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') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 59 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 60 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 61 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 62 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 63 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 64 | value='1|g') |
| 65 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 66 | kind='ms') |
| 67 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 68 | value='1|c') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 70 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 71 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 72 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 73 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 74 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 75 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 76 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 77 | for build in self.builds: |
| 78 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 79 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 80 | def test_initial_pipeline_gauges(self): |
| 81 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 82 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 83 | value='0|g') |
| 84 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 85 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 86 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | def test_job_branch(self): |
| 88 | "Test the correct variant of a job runs on a branch" |
| 89 | self.create_branch('org/project', 'stable') |
| 90 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 91 | A.addApproval('code-review', 2) |
| 92 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 93 | self.waitUntilSettled() |
| 94 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 95 | 'SUCCESS') |
| 96 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 97 | 'SUCCESS') |
| 98 | self.assertEqual(A.data['status'], 'MERGED') |
| 99 | self.assertEqual(A.reported, 2, |
| 100 | "A should report start and success") |
| 101 | self.assertIn('gate', A.messages[1], |
| 102 | "A should transit gate") |
| 103 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 104 | 'image2') |
| 105 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 106 | def test_parallel_changes(self): |
| 107 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 108 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 109 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 110 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 111 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 112 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 113 | A.addApproval('code-review', 2) |
| 114 | B.addApproval('code-review', 2) |
| 115 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 116 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 117 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 118 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 119 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 120 | |
| 121 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 122 | self.assertEqual(len(self.builds), 1) |
| 123 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 124 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 125 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 126 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 127 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 128 | self.assertEqual(len(self.builds), 3) |
| 129 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 130 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 131 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 132 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 133 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 134 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 135 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 137 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 138 | self.assertEqual(len(self.builds), 5) |
| 139 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 140 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 141 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 142 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 144 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 145 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 146 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 147 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 148 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 149 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 150 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 151 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 152 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 154 | self.assertEqual(len(self.builds), 6) |
| 155 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 157 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 158 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 159 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 160 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 161 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 162 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 165 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 166 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 167 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 168 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 169 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.launch_server.hold_jobs_in_build = False |
| 171 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 172 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 173 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 175 | self.assertEqual(len(self.history), 9) |
| 176 | self.assertEqual(A.data['status'], 'MERGED') |
| 177 | self.assertEqual(B.data['status'], 'MERGED') |
| 178 | self.assertEqual(C.data['status'], 'MERGED') |
| 179 | self.assertEqual(A.reported, 2) |
| 180 | self.assertEqual(B.reported, 2) |
| 181 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 182 | |
| 183 | def test_failed_changes(self): |
| 184 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 185 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 186 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 187 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 188 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 189 | A.addApproval('code-review', 2) |
| 190 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 191 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 192 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 193 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 194 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 195 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 196 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 197 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 198 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 199 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 200 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 201 | # A/project-merge is complete |
| 202 | self.assertBuilds([ |
| 203 | dict(name='project-test1', changes='1,1'), |
| 204 | dict(name='project-test2', changes='1,1'), |
| 205 | dict(name='project-merge', changes='1,1 2,1'), |
| 206 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 207 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 208 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 209 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 210 | # A/project-merge is complete |
| 211 | # B/project-merge is complete |
| 212 | self.assertBuilds([ |
| 213 | dict(name='project-test1', changes='1,1'), |
| 214 | dict(name='project-test2', changes='1,1'), |
| 215 | dict(name='project-test1', changes='1,1 2,1'), |
| 216 | dict(name='project-test2', changes='1,1 2,1'), |
| 217 | ]) |
| 218 | |
| 219 | # Release project-test1 for A which will fail. This will |
| 220 | # abort both running B jobs and relaunch project-merge for B. |
| 221 | self.builds[0].release() |
| 222 | self.waitUntilSettled() |
| 223 | |
| 224 | self.orderedRelease() |
| 225 | self.assertHistory([ |
| 226 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 227 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 228 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 229 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 230 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 231 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 232 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 233 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 234 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 235 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 236 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 237 | self.assertEqual(A.data['status'], 'NEW') |
| 238 | self.assertEqual(B.data['status'], 'MERGED') |
| 239 | self.assertEqual(A.reported, 2) |
| 240 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 241 | |
| 242 | def test_independent_queues(self): |
| 243 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 244 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 245 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 246 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 248 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 249 | A.addApproval('code-review', 2) |
| 250 | B.addApproval('code-review', 2) |
| 251 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 252 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 253 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 254 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 255 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 256 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 257 | self.waitUntilSettled() |
| 258 | |
| 259 | # 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] | 260 | self.assertBuilds([ |
| 261 | dict(name='project-merge', changes='1,1'), |
| 262 | dict(name='project-merge', changes='2,1'), |
| 263 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 264 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 265 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 266 | self.builds[0].release() |
| 267 | self.waitUntilSettled() |
| 268 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 269 | self.waitUntilSettled() |
| 270 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 271 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 272 | self.waitUntilSettled() |
| 273 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 274 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 275 | self.assertBuilds([ |
| 276 | dict(name='project-test1', changes='1,1'), |
| 277 | dict(name='project-test2', changes='1,1'), |
| 278 | dict(name='project-test1', changes='2,1'), |
| 279 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 280 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 281 | dict(name='project-test1', changes='2,1 3,1'), |
| 282 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 283 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 284 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 285 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 286 | self.orderedRelease() |
| 287 | self.assertHistory([ |
| 288 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 289 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 290 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 291 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 292 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 293 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 294 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 295 | dict( |
| 296 | name='project1-project2-integration', |
| 297 | result='SUCCESS', |
| 298 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 299 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 300 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 301 | dict(name='project1-project2-integration', |
| 302 | result='SUCCESS', |
| 303 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 304 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 305 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 306 | self.assertEqual(A.data['status'], 'MERGED') |
| 307 | self.assertEqual(B.data['status'], 'MERGED') |
| 308 | self.assertEqual(C.data['status'], 'MERGED') |
| 309 | self.assertEqual(A.reported, 2) |
| 310 | self.assertEqual(B.reported, 2) |
| 311 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 312 | |
| 313 | def test_failed_change_at_head(self): |
| 314 | "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] | 315 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 316 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 317 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 318 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 319 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 320 | A.addApproval('code-review', 2) |
| 321 | B.addApproval('code-review', 2) |
| 322 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 323 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 324 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 325 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 326 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 327 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 328 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 329 | |
| 330 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 331 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 332 | self.assertBuilds([ |
| 333 | dict(name='project-merge', changes='1,1'), |
| 334 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 335 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 336 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 338 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 339 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 340 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 341 | self.waitUntilSettled() |
| 342 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 343 | self.assertBuilds([ |
| 344 | dict(name='project-test1', changes='1,1'), |
| 345 | dict(name='project-test2', changes='1,1'), |
| 346 | dict(name='project-test1', changes='1,1 2,1'), |
| 347 | dict(name='project-test2', changes='1,1 2,1'), |
| 348 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 349 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 350 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 351 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 352 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | self.waitUntilSettled() |
| 354 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 355 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 356 | self.assertBuilds([ |
| 357 | dict(name='project-test2', changes='1,1'), |
| 358 | dict(name='project-merge', changes='2,1'), |
| 359 | ]) |
| 360 | # Unordered history comparison because the aborts can finish |
| 361 | # in any order. |
| 362 | self.assertHistory([ |
| 363 | dict(name='project-merge', result='SUCCESS', |
| 364 | changes='1,1'), |
| 365 | dict(name='project-merge', result='SUCCESS', |
| 366 | changes='1,1 2,1'), |
| 367 | dict(name='project-merge', result='SUCCESS', |
| 368 | changes='1,1 2,1 3,1'), |
| 369 | dict(name='project-test1', result='FAILURE', |
| 370 | changes='1,1'), |
| 371 | dict(name='project-test1', result='ABORTED', |
| 372 | changes='1,1 2,1'), |
| 373 | dict(name='project-test2', result='ABORTED', |
| 374 | changes='1,1 2,1'), |
| 375 | dict(name='project-test1', result='ABORTED', |
| 376 | changes='1,1 2,1 3,1'), |
| 377 | dict(name='project-test2', result='ABORTED', |
| 378 | changes='1,1 2,1 3,1'), |
| 379 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 380 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 381 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 383 | self.launch_server.release('.*-merge') |
| 384 | self.waitUntilSettled() |
| 385 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 387 | self.assertBuilds([]) |
| 388 | self.assertHistory([ |
| 389 | dict(name='project-merge', result='SUCCESS', |
| 390 | changes='1,1'), |
| 391 | dict(name='project-merge', result='SUCCESS', |
| 392 | changes='1,1 2,1'), |
| 393 | dict(name='project-merge', result='SUCCESS', |
| 394 | changes='1,1 2,1 3,1'), |
| 395 | dict(name='project-test1', result='FAILURE', |
| 396 | changes='1,1'), |
| 397 | dict(name='project-test1', result='ABORTED', |
| 398 | changes='1,1 2,1'), |
| 399 | dict(name='project-test2', result='ABORTED', |
| 400 | changes='1,1 2,1'), |
| 401 | dict(name='project-test1', result='ABORTED', |
| 402 | changes='1,1 2,1 3,1'), |
| 403 | dict(name='project-test2', result='ABORTED', |
| 404 | changes='1,1 2,1 3,1'), |
| 405 | dict(name='project-merge', result='SUCCESS', |
| 406 | changes='2,1'), |
| 407 | dict(name='project-merge', result='SUCCESS', |
| 408 | changes='2,1 3,1'), |
| 409 | dict(name='project-test2', result='SUCCESS', |
| 410 | changes='1,1'), |
| 411 | dict(name='project-test1', result='SUCCESS', |
| 412 | changes='2,1'), |
| 413 | dict(name='project-test2', result='SUCCESS', |
| 414 | changes='2,1'), |
| 415 | dict(name='project-test1', result='SUCCESS', |
| 416 | changes='2,1 3,1'), |
| 417 | dict(name='project-test2', result='SUCCESS', |
| 418 | changes='2,1 3,1'), |
| 419 | ], ordered=False) |
| 420 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 421 | self.assertEqual(A.data['status'], 'NEW') |
| 422 | self.assertEqual(B.data['status'], 'MERGED') |
| 423 | self.assertEqual(C.data['status'], 'MERGED') |
| 424 | self.assertEqual(A.reported, 2) |
| 425 | self.assertEqual(B.reported, 2) |
| 426 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 427 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 428 | def test_failed_change_in_middle(self): |
| 429 | "Test a failed change in the middle of the queue" |
| 430 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 431 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 433 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 434 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 435 | A.addApproval('code-review', 2) |
| 436 | B.addApproval('code-review', 2) |
| 437 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 438 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 439 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 440 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 441 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 442 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 443 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 444 | |
| 445 | self.waitUntilSettled() |
| 446 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 447 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 448 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 449 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 451 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 452 | self.waitUntilSettled() |
| 453 | |
| 454 | self.assertEqual(len(self.builds), 6) |
| 455 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 456 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 457 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 458 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 459 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 460 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 461 | |
| 462 | self.release(self.builds[2]) |
| 463 | self.waitUntilSettled() |
| 464 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 465 | # project-test1 and project-test2 for A |
| 466 | # project-test2 for B |
| 467 | # project-merge for C (without B) |
| 468 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 469 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 470 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 471 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 472 | self.waitUntilSettled() |
| 473 | |
| 474 | # project-test1 and project-test2 for A |
| 475 | # project-test2 for B |
| 476 | # project-test1 and project-test2 for C |
| 477 | self.assertEqual(len(self.builds), 5) |
| 478 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 479 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 480 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 481 | builds = items[0].current_build_set.getBuilds() |
| 482 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 483 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 484 | builds = items[1].current_build_set.getBuilds() |
| 485 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 486 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 487 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 488 | builds = items[2].current_build_set.getBuilds() |
| 489 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 490 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 491 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 492 | self.launch_server.hold_jobs_in_build = False |
| 493 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 494 | self.waitUntilSettled() |
| 495 | |
| 496 | self.assertEqual(len(self.builds), 0) |
| 497 | self.assertEqual(len(self.history), 12) |
| 498 | self.assertEqual(A.data['status'], 'MERGED') |
| 499 | self.assertEqual(B.data['status'], 'NEW') |
| 500 | self.assertEqual(C.data['status'], 'MERGED') |
| 501 | self.assertEqual(A.reported, 2) |
| 502 | self.assertEqual(B.reported, 2) |
| 503 | self.assertEqual(C.reported, 2) |
| 504 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 505 | def test_failed_change_at_head_with_queue(self): |
| 506 | "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] | 507 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 508 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 509 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 510 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 511 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 512 | A.addApproval('code-review', 2) |
| 513 | B.addApproval('code-review', 2) |
| 514 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 515 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 516 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 517 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 518 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 519 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 520 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 521 | |
| 522 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 523 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 524 | self.assertEqual(len(self.builds), 0) |
| 525 | self.assertEqual(len(queue), 1) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 526 | self.assertEqual(queue[0].name, 'launcher:launch') |
| 527 | job_args = json.loads(queue[0].arguments) |
| 528 | self.assertEqual(job_args['job'], 'project-merge') |
| 529 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 530 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 531 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 532 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 533 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 534 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 535 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 536 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 537 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 538 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 539 | self.assertEqual(len(self.builds), 0) |
| 540 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 541 | |
| 542 | self.assertEqual( |
| 543 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 544 | self.assertEqual( |
| 545 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 546 | self.assertEqual( |
| 547 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 548 | self.assertEqual( |
| 549 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 550 | self.assertEqual( |
| 551 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 552 | self.assertEqual( |
| 553 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 554 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 555 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 556 | self.waitUntilSettled() |
| 557 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 558 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 559 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 560 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 561 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 562 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 563 | self.gearman_server.hold_jobs_in_queue = False |
| 564 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 565 | self.waitUntilSettled() |
| 566 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 567 | self.assertEqual(len(self.builds), 0) |
| 568 | self.assertEqual(len(self.history), 11) |
| 569 | self.assertEqual(A.data['status'], 'NEW') |
| 570 | self.assertEqual(B.data['status'], 'MERGED') |
| 571 | self.assertEqual(C.data['status'], 'MERGED') |
| 572 | self.assertEqual(A.reported, 2) |
| 573 | self.assertEqual(B.reported, 2) |
| 574 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 575 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 576 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 577 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 578 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 579 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 580 | A.addApproval('code-review', 2) |
| 581 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 582 | self.waitUntilSettled() |
| 583 | time.sleep(2) |
| 584 | |
| 585 | data = json.loads(self.sched.formatStatusJSON()) |
| 586 | found_job = None |
| 587 | for pipeline in data['pipelines']: |
| 588 | if pipeline['name'] != 'gate': |
| 589 | continue |
| 590 | for queue in pipeline['change_queues']: |
| 591 | for head in queue['heads']: |
| 592 | for item in head: |
| 593 | for job in item['jobs']: |
| 594 | if job['name'] == 'project-merge': |
| 595 | found_job = job |
| 596 | break |
| 597 | |
| 598 | self.assertIsNotNone(found_job) |
| 599 | if iteration == 1: |
| 600 | self.assertIsNotNone(found_job['estimated_time']) |
| 601 | self.assertIsNone(found_job['remaining_time']) |
| 602 | else: |
| 603 | self.assertIsNotNone(found_job['estimated_time']) |
| 604 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 605 | self.assertIsNotNone(found_job['remaining_time']) |
| 606 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 607 | self.launch_server.hold_jobs_in_build = False |
| 608 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 609 | self.waitUntilSettled() |
| 610 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 611 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 612 | def test_time_database(self): |
| 613 | "Test the time database" |
| 614 | |
| 615 | self._test_time_database(1) |
| 616 | self._test_time_database(2) |
| 617 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 618 | def test_two_failed_changes_at_head(self): |
| 619 | "Test that changes are reparented correctly if 2 fail at head" |
| 620 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 621 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 622 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 623 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 624 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 625 | A.addApproval('code-review', 2) |
| 626 | B.addApproval('code-review', 2) |
| 627 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 628 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 629 | self.launch_server.failJob('project-test1', A) |
| 630 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 631 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 632 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 633 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 634 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 635 | self.waitUntilSettled() |
| 636 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 637 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 638 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 639 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 640 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 641 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 642 | self.waitUntilSettled() |
| 643 | |
| 644 | self.assertEqual(len(self.builds), 6) |
| 645 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 646 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 647 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 648 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 649 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 650 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 651 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 652 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 653 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 654 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 655 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 656 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 657 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 658 | |
| 659 | # Fail change B first |
| 660 | self.release(self.builds[2]) |
| 661 | self.waitUntilSettled() |
| 662 | |
| 663 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 664 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 665 | self.waitUntilSettled() |
| 666 | |
| 667 | self.assertEqual(len(self.builds), 5) |
| 668 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 669 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 670 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 671 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 672 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 673 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 674 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 675 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 676 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 677 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 678 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 679 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 680 | |
| 681 | # Finish running all passing jobs for change A |
| 682 | self.release(self.builds[1]) |
| 683 | self.waitUntilSettled() |
| 684 | # Fail and report change A |
| 685 | self.release(self.builds[0]) |
| 686 | self.waitUntilSettled() |
| 687 | |
| 688 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 689 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 690 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 691 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 692 | self.waitUntilSettled() |
| 693 | |
| 694 | self.assertEqual(len(self.builds), 4) |
| 695 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 696 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 697 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 698 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 699 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 700 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 701 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 702 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 703 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 704 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | # After A failed and B and C restarted, B should be back in |
| 706 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 707 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 708 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 709 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 710 | self.launch_server.hold_jobs_in_build = False |
| 711 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 712 | self.waitUntilSettled() |
| 713 | |
| 714 | self.assertEqual(len(self.builds), 0) |
| 715 | self.assertEqual(len(self.history), 21) |
| 716 | self.assertEqual(A.data['status'], 'NEW') |
| 717 | self.assertEqual(B.data['status'], 'NEW') |
| 718 | self.assertEqual(C.data['status'], 'MERGED') |
| 719 | self.assertEqual(A.reported, 2) |
| 720 | self.assertEqual(B.reported, 2) |
| 721 | self.assertEqual(C.reported, 2) |
| 722 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 723 | def test_patch_order(self): |
| 724 | "Test that dependent patches are tested in the right order" |
| 725 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 726 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 727 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 728 | A.addApproval('code-review', 2) |
| 729 | B.addApproval('code-review', 2) |
| 730 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 731 | |
| 732 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 733 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 734 | M2.setMerged() |
| 735 | M1.setMerged() |
| 736 | |
| 737 | # C -> B -> A -> M1 -> M2 |
| 738 | # M2 is here to make sure it is never queried. If it is, it |
| 739 | # means zuul is walking down the entire history of merged |
| 740 | # changes. |
| 741 | |
| 742 | C.setDependsOn(B, 1) |
| 743 | B.setDependsOn(A, 1) |
| 744 | A.setDependsOn(M1, 1) |
| 745 | M1.setDependsOn(M2, 1) |
| 746 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 747 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 748 | |
| 749 | self.waitUntilSettled() |
| 750 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 751 | self.assertEqual(A.data['status'], 'NEW') |
| 752 | self.assertEqual(B.data['status'], 'NEW') |
| 753 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 754 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 755 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 756 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 757 | |
| 758 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 759 | self.assertEqual(M2.queried, 0) |
| 760 | self.assertEqual(A.data['status'], 'MERGED') |
| 761 | self.assertEqual(B.data['status'], 'MERGED') |
| 762 | self.assertEqual(C.data['status'], 'MERGED') |
| 763 | self.assertEqual(A.reported, 2) |
| 764 | self.assertEqual(B.reported, 2) |
| 765 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 766 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 767 | def test_needed_changes_enqueue(self): |
| 768 | "Test that a needed change is enqueued ahead" |
| 769 | # A Given a git tree like this, if we enqueue |
| 770 | # / \ change C, we should walk up and down the tree |
| 771 | # B G and enqueue changes in the order ABCDEFG. |
| 772 | # /|\ This is also the order that you would get if |
| 773 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 774 | # / the ordering is stable across re-enqueue events. |
| 775 | # D |
| 776 | |
| 777 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 778 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 779 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 780 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 781 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 782 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 783 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 784 | B.setDependsOn(A, 1) |
| 785 | C.setDependsOn(B, 1) |
| 786 | D.setDependsOn(C, 1) |
| 787 | E.setDependsOn(B, 1) |
| 788 | F.setDependsOn(B, 1) |
| 789 | G.setDependsOn(A, 1) |
| 790 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 791 | A.addApproval('code-review', 2) |
| 792 | B.addApproval('code-review', 2) |
| 793 | C.addApproval('code-review', 2) |
| 794 | D.addApproval('code-review', 2) |
| 795 | E.addApproval('code-review', 2) |
| 796 | F.addApproval('code-review', 2) |
| 797 | G.addApproval('code-review', 2) |
| 798 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 799 | |
| 800 | self.waitUntilSettled() |
| 801 | |
| 802 | self.assertEqual(A.data['status'], 'NEW') |
| 803 | self.assertEqual(B.data['status'], 'NEW') |
| 804 | self.assertEqual(C.data['status'], 'NEW') |
| 805 | self.assertEqual(D.data['status'], 'NEW') |
| 806 | self.assertEqual(E.data['status'], 'NEW') |
| 807 | self.assertEqual(F.data['status'], 'NEW') |
| 808 | self.assertEqual(G.data['status'], 'NEW') |
| 809 | |
| 810 | # We're about to add approvals to changes without adding the |
| 811 | # triggering events to Zuul, so that we can be sure that it is |
| 812 | # enqueing the changes based on dependencies, not because of |
| 813 | # triggering events. Since it will have the changes cached |
| 814 | # already (without approvals), we need to clear the cache |
| 815 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 816 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 817 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 818 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 819 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 820 | A.addApproval('approved', 1) |
| 821 | B.addApproval('approved', 1) |
| 822 | D.addApproval('approved', 1) |
| 823 | E.addApproval('approved', 1) |
| 824 | F.addApproval('approved', 1) |
| 825 | G.addApproval('approved', 1) |
| 826 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 827 | |
| 828 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 829 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 830 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 831 | self.launch_server.hold_jobs_in_build = False |
| 832 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 833 | self.waitUntilSettled() |
| 834 | |
| 835 | self.assertEqual(A.data['status'], 'MERGED') |
| 836 | self.assertEqual(B.data['status'], 'MERGED') |
| 837 | self.assertEqual(C.data['status'], 'MERGED') |
| 838 | self.assertEqual(D.data['status'], 'MERGED') |
| 839 | self.assertEqual(E.data['status'], 'MERGED') |
| 840 | self.assertEqual(F.data['status'], 'MERGED') |
| 841 | self.assertEqual(G.data['status'], 'MERGED') |
| 842 | self.assertEqual(A.reported, 2) |
| 843 | self.assertEqual(B.reported, 2) |
| 844 | self.assertEqual(C.reported, 2) |
| 845 | self.assertEqual(D.reported, 2) |
| 846 | self.assertEqual(E.reported, 2) |
| 847 | self.assertEqual(F.reported, 2) |
| 848 | self.assertEqual(G.reported, 2) |
| 849 | self.assertEqual(self.history[6].changes, |
| 850 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 851 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 852 | def test_source_cache(self): |
| 853 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 854 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 855 | |
| 856 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 857 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 858 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 859 | A.addApproval('code-review', 2) |
| 860 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 861 | |
| 862 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 863 | M1.setMerged() |
| 864 | |
| 865 | B.setDependsOn(A, 1) |
| 866 | A.setDependsOn(M1, 1) |
| 867 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 868 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 869 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 870 | |
| 871 | self.waitUntilSettled() |
| 872 | |
| 873 | for build in self.builds: |
| 874 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 875 | build.release() |
| 876 | self.waitUntilSettled() |
| 877 | for build in self.builds: |
| 878 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 879 | build.release() |
| 880 | self.waitUntilSettled() |
| 881 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 882 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 883 | self.waitUntilSettled() |
| 884 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 885 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 886 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 887 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 888 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 889 | self.launch_server.hold_jobs_in_build = False |
| 890 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 891 | self.waitUntilSettled() |
| 892 | |
| 893 | self.assertEqual(A.data['status'], 'MERGED') |
| 894 | self.assertEqual(B.data['status'], 'MERGED') |
| 895 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 896 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 897 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 898 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 899 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 900 | # TODO: move to test_gerrit (this is a unit test!) |
| 901 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 902 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 903 | source = tenant.layout.pipelines['gate'].source |
| 904 | |
| 905 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 906 | # it easier for users to create events for testing. |
| 907 | event = zuul.model.TriggerEvent() |
| 908 | event.trigger_name = 'gerrit' |
| 909 | event.change_number = '1' |
| 910 | event.patch_number = '2' |
| 911 | |
| 912 | a = source.getChange(event) |
| 913 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 914 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 915 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 916 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 917 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 918 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 919 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 920 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 921 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 922 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 923 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 924 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 925 | def test_build_configuration_conflict(self): |
| 926 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 927 | |
| 928 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 929 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 930 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 931 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 932 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 933 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 934 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 935 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 936 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 937 | A.addApproval('code-review', 2) |
| 938 | B.addApproval('code-review', 2) |
| 939 | C.addApproval('code-review', 2) |
| 940 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 941 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 942 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 943 | self.waitUntilSettled() |
| 944 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 945 | self.assertEqual(A.reported, 1) |
| 946 | self.assertEqual(B.reported, 1) |
| 947 | self.assertEqual(C.reported, 1) |
| 948 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 949 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 950 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 951 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 952 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 953 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 954 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 955 | |
| 956 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 957 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 958 | self.gearman_server.hold_jobs_in_queue = False |
| 959 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 960 | self.waitUntilSettled() |
| 961 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 962 | self.assertEqual(A.data['status'], 'MERGED') |
| 963 | self.assertEqual(B.data['status'], 'NEW') |
| 964 | self.assertEqual(C.data['status'], 'MERGED') |
| 965 | self.assertEqual(A.reported, 2) |
| 966 | self.assertEqual(B.reported, 2) |
| 967 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 968 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 969 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 970 | def test_post(self): |
| 971 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 972 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 973 | e = { |
| 974 | "type": "ref-updated", |
| 975 | "submitter": { |
| 976 | "name": "User Name", |
| 977 | }, |
| 978 | "refUpdate": { |
| 979 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 980 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 981 | "refName": "master", |
| 982 | "project": "org/project", |
| 983 | } |
| 984 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 985 | self.fake_gerrit.addEvent(e) |
| 986 | self.waitUntilSettled() |
| 987 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 988 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 989 | self.assertEqual(len(self.history), 1) |
| 990 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 991 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 992 | def test_post_ignore_deletes(self): |
| 993 | "Test that deleting refs does not trigger post jobs" |
| 994 | |
| 995 | e = { |
| 996 | "type": "ref-updated", |
| 997 | "submitter": { |
| 998 | "name": "User Name", |
| 999 | }, |
| 1000 | "refUpdate": { |
| 1001 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1002 | "newRev": "0000000000000000000000000000000000000000", |
| 1003 | "refName": "master", |
| 1004 | "project": "org/project", |
| 1005 | } |
| 1006 | } |
| 1007 | self.fake_gerrit.addEvent(e) |
| 1008 | self.waitUntilSettled() |
| 1009 | |
| 1010 | job_names = [x.name for x in self.history] |
| 1011 | self.assertEqual(len(self.history), 0) |
| 1012 | self.assertNotIn('project-post', job_names) |
| 1013 | |
| 1014 | def test_post_ignore_deletes_negative(self): |
| 1015 | "Test that deleting refs does trigger post jobs" |
| 1016 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1017 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1018 | self.sched.reconfigure(self.config) |
| 1019 | |
| 1020 | e = { |
| 1021 | "type": "ref-updated", |
| 1022 | "submitter": { |
| 1023 | "name": "User Name", |
| 1024 | }, |
| 1025 | "refUpdate": { |
| 1026 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1027 | "newRev": "0000000000000000000000000000000000000000", |
| 1028 | "refName": "master", |
| 1029 | "project": "org/project", |
| 1030 | } |
| 1031 | } |
| 1032 | self.fake_gerrit.addEvent(e) |
| 1033 | self.waitUntilSettled() |
| 1034 | |
| 1035 | job_names = [x.name for x in self.history] |
| 1036 | self.assertEqual(len(self.history), 1) |
| 1037 | self.assertIn('project-post', job_names) |
| 1038 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1039 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1040 | def test_build_configuration_branch_interaction(self): |
| 1041 | "Test that switching between branches works" |
| 1042 | self.test_build_configuration() |
| 1043 | self.test_build_configuration_branch() |
| 1044 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1045 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1046 | repo = git.Repo(path) |
| 1047 | repo.heads.master.commit = repo.commit('init') |
| 1048 | self.test_build_configuration() |
| 1049 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1050 | def test_dependent_changes_dequeue(self): |
| 1051 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1052 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1053 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1054 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1055 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1056 | A.addApproval('code-review', 2) |
| 1057 | B.addApproval('code-review', 2) |
| 1058 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1059 | |
| 1060 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1061 | M1.setMerged() |
| 1062 | |
| 1063 | # C -> B -> A -> M1 |
| 1064 | |
| 1065 | C.setDependsOn(B, 1) |
| 1066 | B.setDependsOn(A, 1) |
| 1067 | A.setDependsOn(M1, 1) |
| 1068 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1069 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1070 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1071 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1072 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1073 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1074 | |
| 1075 | self.waitUntilSettled() |
| 1076 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1077 | self.assertEqual(A.data['status'], 'NEW') |
| 1078 | self.assertEqual(A.reported, 2) |
| 1079 | self.assertEqual(B.data['status'], 'NEW') |
| 1080 | self.assertEqual(B.reported, 2) |
| 1081 | self.assertEqual(C.data['status'], 'NEW') |
| 1082 | self.assertEqual(C.reported, 2) |
| 1083 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1084 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1085 | def test_failing_dependent_changes(self): |
| 1086 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1087 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1088 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1089 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1090 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1091 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1092 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1093 | A.addApproval('code-review', 2) |
| 1094 | B.addApproval('code-review', 2) |
| 1095 | C.addApproval('code-review', 2) |
| 1096 | D.addApproval('code-review', 2) |
| 1097 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1098 | |
| 1099 | # E, D -> C -> B, A |
| 1100 | |
| 1101 | D.setDependsOn(C, 1) |
| 1102 | C.setDependsOn(B, 1) |
| 1103 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1104 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1105 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1106 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1107 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1108 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1109 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1110 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1111 | |
| 1112 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1113 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1114 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1115 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1116 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1117 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1118 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1119 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1120 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1121 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1122 | self.waitUntilSettled() |
| 1123 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1124 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1125 | for build in self.builds: |
| 1126 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1127 | build.release() |
| 1128 | self.waitUntilSettled() |
| 1129 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1130 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1131 | self.waitUntilSettled() |
| 1132 | |
| 1133 | self.assertEqual(A.data['status'], 'MERGED') |
| 1134 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1135 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1136 | self.assertEqual(B.data['status'], 'NEW') |
| 1137 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1138 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1139 | self.assertEqual(C.data['status'], 'NEW') |
| 1140 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1141 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1142 | self.assertEqual(D.data['status'], 'NEW') |
| 1143 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1144 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1145 | self.assertEqual(E.data['status'], 'MERGED') |
| 1146 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1147 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1148 | self.assertEqual(len(self.history), 18) |
| 1149 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1150 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1151 | "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] | 1152 | # If it's dequeued more than once, we should see extra |
| 1153 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1154 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1155 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1156 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1157 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1158 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1159 | A.addApproval('code-review', 2) |
| 1160 | B.addApproval('code-review', 2) |
| 1161 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1162 | |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1163 | self.launch_server.failJob('project-test1', A) |
| 1164 | self.launch_server.failJob('project-test2', A) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1165 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1166 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1167 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1168 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1169 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1170 | |
| 1171 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1172 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1173 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1174 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1175 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1176 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1177 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1178 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1179 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1180 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1181 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1182 | self.waitUntilSettled() |
| 1183 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1184 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1185 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1186 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1187 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1188 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1189 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1190 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1191 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1192 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1193 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1194 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1195 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1196 | self.waitUntilSettled() |
| 1197 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1198 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1199 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1200 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1201 | self.launch_server.hold_jobs_in_build = False |
| 1202 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1203 | self.waitUntilSettled() |
| 1204 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1205 | self.assertEqual(len(self.builds), 0) |
| 1206 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1207 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1208 | self.assertEqual(A.data['status'], 'NEW') |
| 1209 | self.assertEqual(B.data['status'], 'MERGED') |
| 1210 | self.assertEqual(C.data['status'], 'MERGED') |
| 1211 | self.assertEqual(A.reported, 2) |
| 1212 | self.assertEqual(B.reported, 2) |
| 1213 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1214 | |
| 1215 | def test_nonvoting_job(self): |
| 1216 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1217 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1218 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1219 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1220 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1221 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1222 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1223 | |
| 1224 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1225 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1226 | self.assertEqual(A.data['status'], 'MERGED') |
| 1227 | self.assertEqual(A.reported, 2) |
| 1228 | self.assertEqual( |
| 1229 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1230 | 'SUCCESS') |
| 1231 | self.assertEqual( |
| 1232 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1233 | 'SUCCESS') |
| 1234 | self.assertEqual( |
| 1235 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1236 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1237 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1238 | for build in self.builds: |
| 1239 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1240 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1241 | def test_check_queue_success(self): |
| 1242 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1243 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1244 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1245 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1246 | |
| 1247 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1248 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1249 | self.assertEqual(A.data['status'], 'NEW') |
| 1250 | self.assertEqual(A.reported, 1) |
| 1251 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1252 | 'SUCCESS') |
| 1253 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1254 | 'SUCCESS') |
| 1255 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1256 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1257 | |
| 1258 | def test_check_queue_failure(self): |
| 1259 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1260 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1261 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1262 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1263 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1264 | |
| 1265 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1266 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1267 | self.assertEqual(A.data['status'], 'NEW') |
| 1268 | self.assertEqual(A.reported, 1) |
| 1269 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1270 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1271 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1272 | 'SUCCESS') |
| 1273 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1274 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1275 | |
| 1276 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1277 | # This particular test does a large amount of merges and needs a little |
| 1278 | # more time to complete |
| 1279 | self.wait_timeout = 90 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1280 | "test that dependent changes behind dequeued changes work" |
| 1281 | # This complicated test is a reproduction of a real life bug |
| 1282 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1283 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1284 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1285 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1286 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1287 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1288 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1289 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1290 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1291 | D.setDependsOn(C, 1) |
| 1292 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1293 | A.addApproval('code-review', 2) |
| 1294 | B.addApproval('code-review', 2) |
| 1295 | C.addApproval('code-review', 2) |
| 1296 | D.addApproval('code-review', 2) |
| 1297 | E.addApproval('code-review', 2) |
| 1298 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1299 | |
| 1300 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1301 | |
| 1302 | # Change object re-use in the gerrit trigger is hidden if |
| 1303 | # changes are added in quick succession; waiting makes it more |
| 1304 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1305 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1306 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1307 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1308 | self.waitUntilSettled() |
| 1309 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1310 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1311 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1312 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1313 | self.waitUntilSettled() |
| 1314 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1315 | self.fake_gerrit.addEvent(C.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(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1319 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1320 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1321 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1322 | self.waitUntilSettled() |
| 1323 | |
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() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1328 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1329 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1330 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1331 | self.waitUntilSettled() |
| 1332 | |
| 1333 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1334 | |
| 1335 | # Grab pointers to the jobs we want to release before |
| 1336 | # releasing any, because list indexes may change as |
| 1337 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1338 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1339 | a.release() |
| 1340 | b.release() |
| 1341 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1342 | self.waitUntilSettled() |
| 1343 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1344 | self.launch_server.hold_jobs_in_build = False |
| 1345 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1346 | self.waitUntilSettled() |
| 1347 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1348 | self.assertEqual(A.data['status'], 'NEW') |
| 1349 | self.assertEqual(B.data['status'], 'MERGED') |
| 1350 | self.assertEqual(C.data['status'], 'MERGED') |
| 1351 | self.assertEqual(D.data['status'], 'MERGED') |
| 1352 | self.assertEqual(E.data['status'], 'MERGED') |
| 1353 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1354 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1355 | self.assertEqual(A.reported, 2) |
| 1356 | self.assertEqual(B.reported, 2) |
| 1357 | self.assertEqual(C.reported, 2) |
| 1358 | self.assertEqual(D.reported, 2) |
| 1359 | self.assertEqual(E.reported, 2) |
| 1360 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1361 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1362 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1363 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1364 | |
| 1365 | def test_merger_repack(self): |
| 1366 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1367 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1368 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1369 | A.addApproval('code-review', 2) |
| 1370 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1371 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1372 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1373 | 'SUCCESS') |
| 1374 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1375 | 'SUCCESS') |
| 1376 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1377 | 'SUCCESS') |
| 1378 | self.assertEqual(A.data['status'], 'MERGED') |
| 1379 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1380 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1381 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1382 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1383 | path = os.path.join(self.merger_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1384 | if os.path.exists(path): |
| 1385 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1386 | path = os.path.join(self.launcher_src_root, "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1387 | if os.path.exists(path): |
| 1388 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1389 | |
| 1390 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1391 | A.addApproval('code-review', 2) |
| 1392 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1393 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1394 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1395 | 'SUCCESS') |
| 1396 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1397 | 'SUCCESS') |
| 1398 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1399 | 'SUCCESS') |
| 1400 | self.assertEqual(A.data['status'], 'MERGED') |
| 1401 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1402 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1403 | def test_merger_repack_large_change(self): |
| 1404 | "Test that the merger works with large changes after a repack" |
| 1405 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1406 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1407 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1408 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1409 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1410 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1411 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1412 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1413 | path = os.path.join(self.upstream_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1414 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1415 | path = os.path.join(self.merger_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1416 | if os.path.exists(path): |
| 1417 | repack_repo(path) |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 1418 | path = os.path.join(self.launcher_src_root, "org/project1") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1419 | if os.path.exists(path): |
| 1420 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1421 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1422 | A.addApproval('code-review', 2) |
| 1423 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1424 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1425 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1426 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1427 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1428 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1429 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1430 | 'SUCCESS') |
| 1431 | self.assertEqual(A.data['status'], 'MERGED') |
| 1432 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1433 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1434 | def test_new_patchset_dequeues_old(self): |
| 1435 | "Test that a new patchset causes the old to be dequeued" |
| 1436 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1437 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1438 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1439 | M.setMerged() |
| 1440 | |
| 1441 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1442 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1443 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1444 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1445 | A.addApproval('code-review', 2) |
| 1446 | B.addApproval('code-review', 2) |
| 1447 | C.addApproval('code-review', 2) |
| 1448 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1449 | |
| 1450 | C.setDependsOn(B, 1) |
| 1451 | B.setDependsOn(A, 1) |
| 1452 | A.setDependsOn(M, 1) |
| 1453 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1454 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1455 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1456 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1457 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1458 | self.waitUntilSettled() |
| 1459 | |
| 1460 | B.addPatchset() |
| 1461 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1462 | self.waitUntilSettled() |
| 1463 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1464 | self.launch_server.hold_jobs_in_build = False |
| 1465 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1466 | self.waitUntilSettled() |
| 1467 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1468 | self.assertEqual(A.data['status'], 'MERGED') |
| 1469 | self.assertEqual(A.reported, 2) |
| 1470 | self.assertEqual(B.data['status'], 'NEW') |
| 1471 | self.assertEqual(B.reported, 2) |
| 1472 | self.assertEqual(C.data['status'], 'NEW') |
| 1473 | self.assertEqual(C.reported, 2) |
| 1474 | self.assertEqual(D.data['status'], 'MERGED') |
| 1475 | self.assertEqual(D.reported, 2) |
| 1476 | 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] | 1477 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1478 | def test_new_patchset_check(self): |
| 1479 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1480 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1481 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1482 | |
| 1483 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1484 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1485 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1486 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1487 | |
| 1488 | # Add two git-dependent changes |
| 1489 | B.setDependsOn(A, 1) |
| 1490 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1491 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1492 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1493 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1494 | |
| 1495 | # A live item, and a non-live/live pair |
| 1496 | items = check_pipeline.getAllItems() |
| 1497 | self.assertEqual(len(items), 3) |
| 1498 | |
| 1499 | self.assertEqual(items[0].change.number, '1') |
| 1500 | self.assertEqual(items[0].change.patchset, '1') |
| 1501 | self.assertFalse(items[0].live) |
| 1502 | |
| 1503 | self.assertEqual(items[1].change.number, '2') |
| 1504 | self.assertEqual(items[1].change.patchset, '1') |
| 1505 | self.assertTrue(items[1].live) |
| 1506 | |
| 1507 | self.assertEqual(items[2].change.number, '1') |
| 1508 | self.assertEqual(items[2].change.patchset, '1') |
| 1509 | self.assertTrue(items[2].live) |
| 1510 | |
| 1511 | # Add a new patchset to A |
| 1512 | A.addPatchset() |
| 1513 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1514 | self.waitUntilSettled() |
| 1515 | |
| 1516 | # The live copy of A,1 should be gone, but the non-live and B |
| 1517 | # should continue, and we should have a new A,2 |
| 1518 | items = check_pipeline.getAllItems() |
| 1519 | self.assertEqual(len(items), 3) |
| 1520 | |
| 1521 | self.assertEqual(items[0].change.number, '1') |
| 1522 | self.assertEqual(items[0].change.patchset, '1') |
| 1523 | self.assertFalse(items[0].live) |
| 1524 | |
| 1525 | self.assertEqual(items[1].change.number, '2') |
| 1526 | self.assertEqual(items[1].change.patchset, '1') |
| 1527 | self.assertTrue(items[1].live) |
| 1528 | |
| 1529 | self.assertEqual(items[2].change.number, '1') |
| 1530 | self.assertEqual(items[2].change.patchset, '2') |
| 1531 | self.assertTrue(items[2].live) |
| 1532 | |
| 1533 | # Add a new patchset to B |
| 1534 | B.addPatchset() |
| 1535 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1536 | self.waitUntilSettled() |
| 1537 | |
| 1538 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1539 | # but we should have a new B,2 (still based on A,1) |
| 1540 | items = check_pipeline.getAllItems() |
| 1541 | self.assertEqual(len(items), 3) |
| 1542 | |
| 1543 | self.assertEqual(items[0].change.number, '1') |
| 1544 | self.assertEqual(items[0].change.patchset, '2') |
| 1545 | self.assertTrue(items[0].live) |
| 1546 | |
| 1547 | self.assertEqual(items[1].change.number, '1') |
| 1548 | self.assertEqual(items[1].change.patchset, '1') |
| 1549 | self.assertFalse(items[1].live) |
| 1550 | |
| 1551 | self.assertEqual(items[2].change.number, '2') |
| 1552 | self.assertEqual(items[2].change.patchset, '2') |
| 1553 | self.assertTrue(items[2].live) |
| 1554 | |
| 1555 | self.builds[0].release() |
| 1556 | self.waitUntilSettled() |
| 1557 | self.builds[0].release() |
| 1558 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1559 | self.launch_server.hold_jobs_in_build = False |
| 1560 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1561 | self.waitUntilSettled() |
| 1562 | |
| 1563 | self.assertEqual(A.reported, 1) |
| 1564 | self.assertEqual(B.reported, 1) |
| 1565 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1566 | self.assertEqual(self.history[0].changes, '1,1') |
| 1567 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1568 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1569 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1570 | self.assertEqual(self.history[2].changes, '1,2') |
| 1571 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1572 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1573 | |
| 1574 | def test_abandoned_gate(self): |
| 1575 | "Test that an abandoned change is dequeued from gate" |
| 1576 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1577 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1578 | |
| 1579 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1580 | A.addApproval('code-review', 2) |
| 1581 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1582 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1583 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1584 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1585 | |
| 1586 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1587 | self.waitUntilSettled() |
| 1588 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1589 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1590 | self.waitUntilSettled() |
| 1591 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1592 | self.assertBuilds([]) |
| 1593 | self.assertHistory([ |
| 1594 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1595 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1596 | self.assertEqual(A.reported, 1, |
| 1597 | "Abandoned gate change should report only start") |
| 1598 | |
| 1599 | def test_abandoned_check(self): |
| 1600 | "Test that an abandoned change is dequeued from check" |
| 1601 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1602 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1603 | |
| 1604 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1605 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1606 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1607 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1608 | |
| 1609 | # Add two git-dependent changes |
| 1610 | B.setDependsOn(A, 1) |
| 1611 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1612 | self.waitUntilSettled() |
| 1613 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1614 | self.waitUntilSettled() |
| 1615 | # A live item, and a non-live/live pair |
| 1616 | items = check_pipeline.getAllItems() |
| 1617 | self.assertEqual(len(items), 3) |
| 1618 | |
| 1619 | self.assertEqual(items[0].change.number, '1') |
| 1620 | self.assertFalse(items[0].live) |
| 1621 | |
| 1622 | self.assertEqual(items[1].change.number, '2') |
| 1623 | self.assertTrue(items[1].live) |
| 1624 | |
| 1625 | self.assertEqual(items[2].change.number, '1') |
| 1626 | self.assertTrue(items[2].live) |
| 1627 | |
| 1628 | # Abandon A |
| 1629 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1630 | self.waitUntilSettled() |
| 1631 | |
| 1632 | # The live copy of A should be gone, but the non-live and B |
| 1633 | # should continue |
| 1634 | items = check_pipeline.getAllItems() |
| 1635 | self.assertEqual(len(items), 2) |
| 1636 | |
| 1637 | self.assertEqual(items[0].change.number, '1') |
| 1638 | self.assertFalse(items[0].live) |
| 1639 | |
| 1640 | self.assertEqual(items[1].change.number, '2') |
| 1641 | self.assertTrue(items[1].live) |
| 1642 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1643 | self.launch_server.hold_jobs_in_build = False |
| 1644 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1645 | self.waitUntilSettled() |
| 1646 | |
| 1647 | self.assertEqual(len(self.history), 4) |
| 1648 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1649 | 'Build should have been aborted') |
| 1650 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1651 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1652 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1653 | def test_abandoned_not_timer(self): |
| 1654 | "Test that an abandoned change does not cancel timer jobs" |
| 1655 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1656 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1657 | |
| 1658 | # Start timer trigger - also org/project |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1659 | self.updateConfigLayout('layout-idle') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1660 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1661 | # The pipeline triggers every second, so we should have seen |
| 1662 | # several by now. |
| 1663 | time.sleep(5) |
| 1664 | self.waitUntilSettled() |
| 1665 | # Stop queuing timer triggered jobs so that the assertions |
| 1666 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1667 | # Must be in same repo, so overwrite config with another one |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 1668 | self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1669 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1670 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1671 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1672 | |
| 1673 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1674 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1675 | self.waitUntilSettled() |
| 1676 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1677 | |
| 1678 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1679 | self.waitUntilSettled() |
| 1680 | |
| 1681 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1682 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1683 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1684 | self.waitUntilSettled() |
| 1685 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1686 | def test_zuul_url_return(self): |
| 1687 | "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] | 1688 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1689 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1690 | |
| 1691 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1692 | A.addApproval('code-review', 2) |
| 1693 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1694 | self.waitUntilSettled() |
| 1695 | |
| 1696 | self.assertEqual(len(self.builds), 1) |
| 1697 | for build in self.builds: |
| 1698 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1699 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1700 | self.launch_server.hold_jobs_in_build = False |
| 1701 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1702 | self.waitUntilSettled() |
| 1703 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1704 | def test_new_patchset_dequeues_old_on_head(self): |
| 1705 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1706 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1707 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1708 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1709 | M.setMerged() |
| 1710 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1711 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1712 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1713 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1714 | A.addApproval('code-review', 2) |
| 1715 | B.addApproval('code-review', 2) |
| 1716 | C.addApproval('code-review', 2) |
| 1717 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1718 | |
| 1719 | C.setDependsOn(B, 1) |
| 1720 | B.setDependsOn(A, 1) |
| 1721 | A.setDependsOn(M, 1) |
| 1722 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1723 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1724 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1725 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1726 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1727 | self.waitUntilSettled() |
| 1728 | |
| 1729 | A.addPatchset() |
| 1730 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1731 | self.waitUntilSettled() |
| 1732 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1733 | self.launch_server.hold_jobs_in_build = False |
| 1734 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1735 | self.waitUntilSettled() |
| 1736 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1737 | self.assertEqual(A.data['status'], 'NEW') |
| 1738 | self.assertEqual(A.reported, 2) |
| 1739 | self.assertEqual(B.data['status'], 'NEW') |
| 1740 | self.assertEqual(B.reported, 2) |
| 1741 | self.assertEqual(C.data['status'], 'NEW') |
| 1742 | self.assertEqual(C.reported, 2) |
| 1743 | self.assertEqual(D.data['status'], 'MERGED') |
| 1744 | self.assertEqual(D.reported, 2) |
| 1745 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1746 | |
| 1747 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1748 | "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] | 1749 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1750 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1751 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1752 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1753 | A.addApproval('code-review', 2) |
| 1754 | B.addApproval('code-review', 2) |
| 1755 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1756 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1757 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1758 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1759 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1760 | self.waitUntilSettled() |
| 1761 | |
| 1762 | B.addPatchset() |
| 1763 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1764 | self.waitUntilSettled() |
| 1765 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1766 | self.launch_server.hold_jobs_in_build = False |
| 1767 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1768 | self.waitUntilSettled() |
| 1769 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1770 | self.assertEqual(A.data['status'], 'MERGED') |
| 1771 | self.assertEqual(A.reported, 2) |
| 1772 | self.assertEqual(B.data['status'], 'NEW') |
| 1773 | self.assertEqual(B.reported, 2) |
| 1774 | self.assertEqual(C.data['status'], 'MERGED') |
| 1775 | self.assertEqual(C.reported, 2) |
| 1776 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1777 | |
| 1778 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1779 | "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] | 1780 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1781 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1782 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1783 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1784 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1785 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1786 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1787 | self.waitUntilSettled() |
| 1788 | |
| 1789 | B.addPatchset() |
| 1790 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1791 | self.waitUntilSettled() |
| 1792 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1793 | self.launch_server.hold_jobs_in_build = False |
| 1794 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1795 | self.waitUntilSettled() |
| 1796 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1797 | self.assertEqual(A.data['status'], 'NEW') |
| 1798 | self.assertEqual(A.reported, 1) |
| 1799 | self.assertEqual(B.data['status'], 'NEW') |
| 1800 | self.assertEqual(B.reported, 1) |
| 1801 | self.assertEqual(C.data['status'], 'NEW') |
| 1802 | self.assertEqual(C.reported, 1) |
| 1803 | self.assertEqual(len(self.history), 10) |
| 1804 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1805 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1806 | def test_noop_job(self): |
| 1807 | "Test that the internal noop job works" |
| 1808 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1809 | A.addApproval('code-review', 2) |
| 1810 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1811 | self.waitUntilSettled() |
| 1812 | |
| 1813 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1814 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1815 | self.assertEqual(len(self.history), 0) |
| 1816 | self.assertEqual(A.data['status'], 'MERGED') |
| 1817 | self.assertEqual(A.reported, 2) |
| 1818 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1819 | def test_no_job_project(self): |
| 1820 | "Test that reports with no jobs don't get sent" |
| 1821 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1822 | 'master', 'A') |
| 1823 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1824 | self.waitUntilSettled() |
| 1825 | |
| 1826 | # Change wasn't reported to |
| 1827 | self.assertEqual(A.reported, False) |
| 1828 | |
| 1829 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1830 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1831 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1832 | items = check_pipeline.getAllItems() |
| 1833 | self.assertEqual(len(items), 0) |
| 1834 | |
| 1835 | self.assertEqual(len(self.history), 0) |
| 1836 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1837 | def test_zuul_refs(self): |
| 1838 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1839 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1840 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1841 | M1.setMerged() |
| 1842 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1843 | M2.setMerged() |
| 1844 | |
| 1845 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1846 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1847 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1848 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1849 | A.addApproval('code-review', 2) |
| 1850 | B.addApproval('code-review', 2) |
| 1851 | C.addApproval('code-review', 2) |
| 1852 | D.addApproval('code-review', 2) |
| 1853 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1854 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1855 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1856 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1857 | |
| 1858 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1859 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1860 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1861 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1862 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1863 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1864 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1865 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1866 | self.waitUntilSettled() |
| 1867 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1868 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1869 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1870 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1871 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1872 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1873 | a_build = x |
| 1874 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1875 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1876 | b_build = x |
| 1877 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1878 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1879 | c_build = x |
| 1880 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1881 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1882 | d_build = x |
| 1883 | if a_build and b_build and c_build and d_build: |
| 1884 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1885 | |
| 1886 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1887 | self.assertIsNotNone(a_zref) |
| 1888 | self.assertIsNotNone(b_zref) |
| 1889 | self.assertIsNotNone(c_zref) |
| 1890 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1891 | |
| 1892 | # And they should all be different |
| 1893 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1894 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1895 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1896 | # should have a, not b, and should not be in project2 |
| 1897 | self.assertTrue(a_build.hasChanges(A)) |
| 1898 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1899 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1900 | # should have a and b, and should not be in project2 |
| 1901 | self.assertTrue(b_build.hasChanges(A, B)) |
| 1902 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1903 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1904 | # should have a and b in 1, c in 2 |
| 1905 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 1906 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1907 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1908 | # should have a and b in 1, c and d in 2 |
| 1909 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1910 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1911 | self.launch_server.hold_jobs_in_build = False |
| 1912 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1913 | self.waitUntilSettled() |
| 1914 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1915 | self.assertEqual(A.data['status'], 'MERGED') |
| 1916 | self.assertEqual(A.reported, 2) |
| 1917 | self.assertEqual(B.data['status'], 'MERGED') |
| 1918 | self.assertEqual(B.reported, 2) |
| 1919 | self.assertEqual(C.data['status'], 'MERGED') |
| 1920 | self.assertEqual(C.reported, 2) |
| 1921 | self.assertEqual(D.data['status'], 'MERGED') |
| 1922 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1923 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1924 | def test_rerun_on_error(self): |
| 1925 | "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] | 1926 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1927 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1928 | A.addApproval('code-review', 2) |
| 1929 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1930 | self.waitUntilSettled() |
| 1931 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1932 | self.builds[0].requeue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1933 | self.launch_server.hold_jobs_in_build = False |
| 1934 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1935 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 1936 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1937 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 1938 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1939 | def test_statsd(self): |
| 1940 | "Test each of the statsd methods used in the scheduler" |
| 1941 | import extras |
| 1942 | statsd = extras.try_import('statsd.statsd') |
| 1943 | statsd.incr('test-incr') |
| 1944 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1945 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1946 | self.assertReportedStat('test-incr', '1|c') |
| 1947 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1948 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1949 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1950 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1951 | def test_stuck_job_cleanup(self): |
| 1952 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1953 | # This job won't be registered at startup because it is not in |
| 1954 | # the standard layout, but we need it to already be registerd |
| 1955 | # for when we reconfigure, as that is when Zuul will attempt |
| 1956 | # to run the new job. |
| 1957 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1958 | self.gearman_server.hold_jobs_in_queue = True |
| 1959 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1960 | A.addApproval('code-review', 2) |
| 1961 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1962 | self.waitUntilSettled() |
| 1963 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 1964 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1965 | self.updateConfigLayout( |
| 1966 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1967 | self.sched.reconfigure(self.config) |
| 1968 | self.waitUntilSettled() |
| 1969 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1970 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1971 | self.waitUntilSettled() |
| 1972 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1973 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1974 | |
| 1975 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1976 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1977 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1978 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1979 | def test_file_head(self): |
| 1980 | # This is a regression test for an observed bug. A change |
| 1981 | # with a file named "HEAD" in the root directory of the repo |
| 1982 | # was processed by a merger. It then was unable to reset the |
| 1983 | # repo because of: |
| 1984 | # GitCommandError: 'git reset --hard HEAD' returned |
| 1985 | # with exit code 128 |
| 1986 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 1987 | # and filename |
| 1988 | # Use '--' to separate filenames from revisions' |
| 1989 | |
| 1990 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 1991 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 1992 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1993 | |
| 1994 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1995 | self.waitUntilSettled() |
| 1996 | |
| 1997 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1998 | self.waitUntilSettled() |
| 1999 | |
| 2000 | self.assertIn('Build succeeded', A.messages[0]) |
| 2001 | self.assertIn('Build succeeded', B.messages[0]) |
| 2002 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2003 | def test_file_jobs(self): |
| 2004 | "Test that file jobs run only when appropriate" |
| 2005 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2006 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2007 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2008 | A.addApproval('code-review', 2) |
| 2009 | B.addApproval('code-review', 2) |
| 2010 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2011 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2012 | self.waitUntilSettled() |
| 2013 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2014 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2015 | if x.name == 'project-testfile'] |
| 2016 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2017 | self.assertEqual(len(testfile_jobs), 1) |
| 2018 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2019 | self.assertEqual(A.data['status'], 'MERGED') |
| 2020 | self.assertEqual(A.reported, 2) |
| 2021 | self.assertEqual(B.data['status'], 'MERGED') |
| 2022 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2023 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2024 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2025 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2026 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2027 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2028 | |
| 2029 | if should_skip: |
| 2030 | files = {'ignoreme': 'ignored\n'} |
| 2031 | else: |
| 2032 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2033 | |
| 2034 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2035 | 'master', |
| 2036 | 'test irrelevant-files', |
| 2037 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2038 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2039 | self.waitUntilSettled() |
| 2040 | |
| 2041 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2042 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2043 | |
| 2044 | if should_skip: |
| 2045 | self.assertEqual([], tested_change_ids) |
| 2046 | else: |
| 2047 | self.assertIn(change.data['number'], tested_change_ids) |
| 2048 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2049 | def test_irrelevant_files_match_skips_job(self): |
| 2050 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2051 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2052 | def test_irrelevant_files_no_match_runs_job(self): |
| 2053 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2054 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2055 | def test_inherited_jobs_keep_matchers(self): |
| 2056 | self.updateConfigLayout('layout-inheritance') |
| 2057 | self.sched.reconfigure(self.config) |
| 2058 | |
| 2059 | files = {'ignoreme': 'ignored\n'} |
| 2060 | |
| 2061 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2062 | 'master', |
| 2063 | 'test irrelevant-files', |
| 2064 | files=files) |
| 2065 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2066 | self.waitUntilSettled() |
| 2067 | |
| 2068 | run_jobs = set([build.name for build in self.history]) |
| 2069 | |
| 2070 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2071 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2072 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2073 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2074 | def test_test_config(self): |
| 2075 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2076 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2077 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2078 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2079 | def test_queue_names(self): |
| 2080 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2081 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2082 | source = tenant.layout.pipelines['gate'].source |
| 2083 | project1 = source.getProject('org/project1') |
| 2084 | project2 = source.getProject('org/project2') |
| 2085 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2086 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2087 | self.assertEqual(q1.name, 'integrated') |
| 2088 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2089 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2090 | def test_queue_precedence(self): |
| 2091 | "Test that queue precedence works" |
| 2092 | |
| 2093 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2094 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2095 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2096 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2097 | A.addApproval('code-review', 2) |
| 2098 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2099 | |
| 2100 | self.waitUntilSettled() |
| 2101 | self.gearman_server.hold_jobs_in_queue = False |
| 2102 | self.gearman_server.release() |
| 2103 | self.waitUntilSettled() |
| 2104 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2105 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2106 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2107 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2108 | self.waitUntilSettled() |
| 2109 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2110 | self.log.debug(self.history) |
| 2111 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2112 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2113 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2114 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2115 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2116 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2117 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2118 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2119 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2120 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2121 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2122 | A.addApproval('code-review', 2) |
| 2123 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2124 | self.waitUntilSettled() |
| 2125 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2126 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2127 | self.waitUntilSettled() |
| 2128 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2129 | port = self.webapp.server.socket.getsockname()[1] |
| 2130 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2131 | req = urllib.request.Request( |
| 2132 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2133 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2134 | headers = f.info() |
| 2135 | self.assertIn('Content-Length', headers) |
| 2136 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2137 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2138 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2139 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2140 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2141 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2142 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2143 | data = f.read() |
| 2144 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2145 | self.launch_server.hold_jobs_in_build = False |
| 2146 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2147 | self.waitUntilSettled() |
| 2148 | |
| 2149 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2150 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2151 | for p in data['pipelines']: |
| 2152 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2153 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2154 | self.assertEqual(q['window'], 20) |
| 2155 | else: |
| 2156 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2157 | for head in q['heads']: |
| 2158 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2159 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2160 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2161 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2162 | status_jobs.append(job) |
| 2163 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2164 | self.assertEqual('https://server/job/project-merge/0/', |
| 2165 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2166 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2167 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2168 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2169 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2170 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2171 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2172 | status_jobs[1]['report_url']) |
| 2173 | |
| 2174 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2175 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2176 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2177 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2178 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2179 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2180 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2181 | def test_merging_queues(self): |
| 2182 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2183 | self.updateConfigLayout( |
| 2184 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2185 | self.sched.reconfigure(self.config) |
| 2186 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2187 | |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2188 | def test_mutex(self): |
| 2189 | "Test job mutexes" |
Adam Gandelman | ea9ac9b | 2017-02-03 16:59:58 -0800 | [diff] [blame] | 2190 | self.updateConfigLayout('layout-mutex') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2191 | self.sched.reconfigure(self.config) |
| 2192 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2193 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2194 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2195 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2196 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2197 | |
| 2198 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2199 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2200 | self.waitUntilSettled() |
| 2201 | self.assertEqual(len(self.builds), 3) |
| 2202 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2203 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2204 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2205 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2206 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2207 | self.waitUntilSettled() |
| 2208 | |
| 2209 | self.assertEqual(len(self.builds), 3) |
| 2210 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2211 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2212 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2213 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2214 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2215 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2216 | self.waitUntilSettled() |
| 2217 | |
| 2218 | self.assertEqual(len(self.builds), 3) |
| 2219 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2220 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2221 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2222 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2223 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2224 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2225 | self.waitUntilSettled() |
| 2226 | |
| 2227 | self.assertEqual(len(self.builds), 3) |
| 2228 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2229 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2230 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2231 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2232 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2233 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2234 | self.waitUntilSettled() |
| 2235 | |
| 2236 | self.assertEqual(len(self.builds), 2) |
| 2237 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2238 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2239 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2240 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2241 | self.launch_server.hold_jobs_in_build = False |
| 2242 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2243 | |
| 2244 | self.waitUntilSettled() |
| 2245 | self.assertEqual(len(self.builds), 0) |
| 2246 | |
| 2247 | self.assertEqual(A.reported, 1) |
| 2248 | self.assertEqual(B.reported, 1) |
| 2249 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2250 | |
Tobias Henkel | fb91a49 | 2017-02-15 07:29:43 +0100 | [diff] [blame] | 2251 | def test_mutex_abandon(self): |
| 2252 | "Test abandon with job mutexes" |
| 2253 | self.updateConfigLayout('layout-mutex') |
| 2254 | self.sched.reconfigure(self.config) |
| 2255 | |
| 2256 | self.launch_server.hold_jobs_in_build = True |
| 2257 | |
| 2258 | tenant = self.sched.abide.tenants.get('openstack') |
| 2259 | check_pipeline = tenant.layout.pipelines['check'] |
| 2260 | |
| 2261 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2262 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2263 | |
| 2264 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2265 | self.waitUntilSettled() |
| 2266 | |
| 2267 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2268 | |
| 2269 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 2270 | self.waitUntilSettled() |
| 2271 | |
| 2272 | # The check pipeline should be empty |
| 2273 | items = check_pipeline.getAllItems() |
| 2274 | self.assertEqual(len(items), 0) |
| 2275 | |
| 2276 | # The mutex should be released |
| 2277 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2278 | |
| 2279 | self.launch_server.hold_jobs_in_build = False |
| 2280 | self.launch_server.release() |
| 2281 | self.waitUntilSettled() |
| 2282 | |
| 2283 | def test_mutex_reconfigure(self): |
| 2284 | "Test reconfigure with job mutexes" |
| 2285 | self.updateConfigLayout('layout-mutex') |
| 2286 | self.sched.reconfigure(self.config) |
| 2287 | |
| 2288 | self.launch_server.hold_jobs_in_build = True |
| 2289 | |
| 2290 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2291 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2292 | |
| 2293 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2294 | self.waitUntilSettled() |
| 2295 | |
| 2296 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2297 | |
| 2298 | self.updateConfigLayout('layout-mutex-reconfiguration') |
| 2299 | self.sched.reconfigure(self.config) |
| 2300 | self.waitUntilSettled() |
| 2301 | |
| 2302 | self.launch_server.release('project-test1') |
| 2303 | self.waitUntilSettled() |
| 2304 | |
| 2305 | # There should be no builds anymore |
| 2306 | self.assertEqual(len(self.builds), 0) |
| 2307 | |
| 2308 | # The mutex should be released |
| 2309 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2310 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2311 | def test_live_reconfiguration(self): |
| 2312 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2313 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2314 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2315 | A.addApproval('code-review', 2) |
| 2316 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2317 | self.waitUntilSettled() |
| 2318 | |
| 2319 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2320 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2321 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2322 | self.launch_server.hold_jobs_in_build = False |
| 2323 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2324 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2325 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2326 | 'SUCCESS') |
| 2327 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2328 | 'SUCCESS') |
| 2329 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2330 | 'SUCCESS') |
| 2331 | self.assertEqual(A.data['status'], 'MERGED') |
| 2332 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2333 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2334 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2335 | def test_live_reconfiguration_merge_conflict(self): |
| 2336 | # A real-world bug: a change in a gate queue has a merge |
| 2337 | # conflict and a job is added to its project while it's |
| 2338 | # sitting in the queue. The job gets added to the change and |
| 2339 | # enqueued and the change gets stuck. |
| 2340 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2341 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2342 | |
| 2343 | # This change is fine. It's here to stop the queue long |
| 2344 | # enough for the next change to be subject to the |
| 2345 | # reconfiguration, as well as to provide a conflict for the |
| 2346 | # next change. This change will succeed and merge. |
| 2347 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2348 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2349 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2350 | |
| 2351 | # This change will be in merge conflict. During the |
| 2352 | # reconfiguration, we will add a job. We want to make sure |
| 2353 | # that doesn't cause it to get stuck. |
| 2354 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2355 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2356 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2357 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2358 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2359 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2360 | |
| 2361 | self.waitUntilSettled() |
| 2362 | |
| 2363 | # No jobs have run yet |
| 2364 | self.assertEqual(A.data['status'], 'NEW') |
| 2365 | self.assertEqual(A.reported, 1) |
| 2366 | self.assertEqual(B.data['status'], 'NEW') |
| 2367 | self.assertEqual(B.reported, 1) |
| 2368 | self.assertEqual(len(self.history), 0) |
| 2369 | |
| 2370 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2371 | self.updateConfigLayout( |
| 2372 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2373 | self.sched.reconfigure(self.config) |
| 2374 | self.waitUntilSettled() |
| 2375 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2376 | self.launch_server.hold_jobs_in_build = False |
| 2377 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2378 | self.waitUntilSettled() |
| 2379 | |
| 2380 | self.assertEqual(A.data['status'], 'MERGED') |
| 2381 | self.assertEqual(A.reported, 2) |
| 2382 | self.assertEqual(B.data['status'], 'NEW') |
| 2383 | self.assertEqual(B.reported, 2) |
| 2384 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2385 | 'SUCCESS') |
| 2386 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2387 | 'SUCCESS') |
| 2388 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2389 | 'SUCCESS') |
| 2390 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2391 | 'SUCCESS') |
| 2392 | self.assertEqual(len(self.history), 4) |
| 2393 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2394 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2395 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2396 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2397 | # that tests a job added to a job tree with a failed root does |
| 2398 | # not run. |
| 2399 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2400 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2401 | |
| 2402 | # This change is fine. It's here to stop the queue long |
| 2403 | # enough for the next change to be subject to the |
| 2404 | # reconfiguration. This change will succeed and merge. |
| 2405 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2406 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2407 | A.addApproval('code-review', 2) |
| 2408 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2409 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2410 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2411 | self.waitUntilSettled() |
| 2412 | |
| 2413 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2414 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2415 | B.addApproval('code-review', 2) |
| 2416 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2417 | self.waitUntilSettled() |
| 2418 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2419 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2420 | self.waitUntilSettled() |
| 2421 | |
| 2422 | # Both -merge jobs have run, but no others. |
| 2423 | self.assertEqual(A.data['status'], 'NEW') |
| 2424 | self.assertEqual(A.reported, 1) |
| 2425 | self.assertEqual(B.data['status'], 'NEW') |
| 2426 | self.assertEqual(B.reported, 1) |
| 2427 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2428 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2429 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2430 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2431 | self.assertEqual(len(self.history), 2) |
| 2432 | |
| 2433 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2434 | self.updateConfigLayout( |
| 2435 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2436 | self.sched.reconfigure(self.config) |
| 2437 | self.waitUntilSettled() |
| 2438 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2439 | self.launch_server.hold_jobs_in_build = False |
| 2440 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2441 | self.waitUntilSettled() |
| 2442 | |
| 2443 | self.assertEqual(A.data['status'], 'MERGED') |
| 2444 | self.assertEqual(A.reported, 2) |
| 2445 | self.assertEqual(B.data['status'], 'NEW') |
| 2446 | self.assertEqual(B.reported, 2) |
| 2447 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2448 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2449 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2450 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2451 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2452 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2453 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2454 | self.assertEqual(len(self.history), 5) |
| 2455 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2456 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2457 | def test_live_reconfiguration_failed_job(self): |
| 2458 | # Test that a change with a removed failing job does not |
| 2459 | # disrupt reconfiguration. If a change has a failed job and |
| 2460 | # that job is removed during a reconfiguration, we observed a |
| 2461 | # bug where the code to re-set build statuses would run on |
| 2462 | # that build and raise an exception because the job no longer |
| 2463 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2464 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2465 | |
| 2466 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2467 | |
| 2468 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2469 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2470 | |
| 2471 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2472 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2473 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2474 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2475 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2476 | self.waitUntilSettled() |
| 2477 | |
| 2478 | self.assertEqual(A.data['status'], 'NEW') |
| 2479 | self.assertEqual(A.reported, 0) |
| 2480 | |
| 2481 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2482 | 'SUCCESS') |
| 2483 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2484 | 'FAILURE') |
| 2485 | self.assertEqual(len(self.history), 2) |
| 2486 | |
| 2487 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2488 | self.updateConfigLayout( |
| 2489 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2490 | self.sched.reconfigure(self.config) |
| 2491 | self.waitUntilSettled() |
| 2492 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2493 | self.launch_server.hold_jobs_in_build = False |
| 2494 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2495 | self.waitUntilSettled() |
| 2496 | |
| 2497 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2498 | 'SUCCESS') |
| 2499 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2500 | 'SUCCESS') |
| 2501 | self.assertEqual(len(self.history), 4) |
| 2502 | |
| 2503 | self.assertEqual(A.data['status'], 'NEW') |
| 2504 | self.assertEqual(A.reported, 1) |
| 2505 | self.assertIn('Build succeeded', A.messages[0]) |
| 2506 | # Ensure the removed job was not included in the report. |
| 2507 | self.assertNotIn('project-test1', A.messages[0]) |
| 2508 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2509 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2510 | def test_live_reconfiguration_shared_queue(self): |
| 2511 | # Test that a change with a failing job which was removed from |
| 2512 | # this project but otherwise still exists in the system does |
| 2513 | # not disrupt reconfiguration. |
| 2514 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2515 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2516 | |
| 2517 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2518 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2519 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2520 | |
| 2521 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2522 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2523 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2524 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2525 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2526 | self.waitUntilSettled() |
| 2527 | |
| 2528 | self.assertEqual(A.data['status'], 'NEW') |
| 2529 | self.assertEqual(A.reported, 0) |
| 2530 | |
| 2531 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2532 | 'SUCCESS') |
| 2533 | self.assertEqual(self.getJobFromHistory( |
| 2534 | 'project1-project2-integration').result, 'FAILURE') |
| 2535 | self.assertEqual(len(self.history), 2) |
| 2536 | |
| 2537 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2538 | self.updateConfigLayout( |
| 2539 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2540 | self.sched.reconfigure(self.config) |
| 2541 | self.waitUntilSettled() |
| 2542 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2543 | self.launch_server.hold_jobs_in_build = False |
| 2544 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2545 | self.waitUntilSettled() |
| 2546 | |
| 2547 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2548 | 'SUCCESS') |
| 2549 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2550 | 'SUCCESS') |
| 2551 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2552 | 'SUCCESS') |
| 2553 | self.assertEqual(self.getJobFromHistory( |
| 2554 | 'project1-project2-integration').result, 'FAILURE') |
| 2555 | self.assertEqual(len(self.history), 4) |
| 2556 | |
| 2557 | self.assertEqual(A.data['status'], 'NEW') |
| 2558 | self.assertEqual(A.reported, 1) |
| 2559 | self.assertIn('Build succeeded', A.messages[0]) |
| 2560 | # Ensure the removed job was not included in the report. |
| 2561 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2562 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2563 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2564 | def test_double_live_reconfiguration_shared_queue(self): |
| 2565 | # This was a real-world regression. A change is added to |
| 2566 | # gate; a reconfigure happens, a second change which depends |
| 2567 | # on the first is added, and a second reconfiguration happens. |
| 2568 | # Ensure that both changes merge. |
| 2569 | |
| 2570 | # A failure may indicate incorrect caching or cleaning up of |
| 2571 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2572 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2573 | |
| 2574 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2575 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2576 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2577 | A.addApproval('code-review', 2) |
| 2578 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2579 | |
| 2580 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2581 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2582 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2583 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2584 | self.waitUntilSettled() |
| 2585 | |
| 2586 | # Reconfigure (with only one change in the pipeline). |
| 2587 | self.sched.reconfigure(self.config) |
| 2588 | self.waitUntilSettled() |
| 2589 | |
| 2590 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2591 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2592 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2593 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2594 | self.waitUntilSettled() |
| 2595 | |
| 2596 | # Reconfigure (with both in the pipeline). |
| 2597 | self.sched.reconfigure(self.config) |
| 2598 | self.waitUntilSettled() |
| 2599 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2600 | self.launch_server.hold_jobs_in_build = False |
| 2601 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2602 | self.waitUntilSettled() |
| 2603 | |
| 2604 | self.assertEqual(len(self.history), 8) |
| 2605 | |
| 2606 | self.assertEqual(A.data['status'], 'MERGED') |
| 2607 | self.assertEqual(A.reported, 2) |
| 2608 | self.assertEqual(B.data['status'], 'MERGED') |
| 2609 | self.assertEqual(B.reported, 2) |
| 2610 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2611 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2612 | def test_live_reconfiguration_del_project(self): |
| 2613 | # Test project deletion from layout |
| 2614 | # while changes are enqueued |
| 2615 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2616 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2617 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2618 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2619 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2620 | |
| 2621 | # A Depends-On: B |
| 2622 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2623 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2624 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2625 | |
| 2626 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2627 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2628 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2629 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2630 | self.waitUntilSettled() |
| 2631 | self.assertEqual(len(self.builds), 5) |
| 2632 | |
| 2633 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2634 | self.updateConfigLayout( |
| 2635 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2636 | self.sched.reconfigure(self.config) |
| 2637 | self.waitUntilSettled() |
| 2638 | |
| 2639 | # Builds for C aborted, builds for A succeed, |
| 2640 | # and have change B applied ahead |
| 2641 | job_c = self.getJobFromHistory('project1-test1') |
| 2642 | self.assertEqual(job_c.changes, '3,1') |
| 2643 | self.assertEqual(job_c.result, 'ABORTED') |
| 2644 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2645 | self.launch_server.hold_jobs_in_build = False |
| 2646 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2647 | self.waitUntilSettled() |
| 2648 | |
| 2649 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2650 | '2,1 1,1') |
| 2651 | |
| 2652 | self.assertEqual(A.data['status'], 'NEW') |
| 2653 | self.assertEqual(B.data['status'], 'NEW') |
| 2654 | self.assertEqual(C.data['status'], 'NEW') |
| 2655 | self.assertEqual(A.reported, 1) |
| 2656 | self.assertEqual(B.reported, 0) |
| 2657 | self.assertEqual(C.reported, 0) |
| 2658 | |
| 2659 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2660 | self.assertIn('Build succeeded', A.messages[0]) |
| 2661 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2662 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2663 | def test_live_reconfiguration_functions(self): |
| 2664 | "Test live reconfiguration with a custom function" |
| 2665 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2666 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2667 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2668 | A.addApproval('code-review', 2) |
| 2669 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2670 | self.waitUntilSettled() |
| 2671 | |
| 2672 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2673 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2674 | 'debian') |
| 2675 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2676 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2677 | self.updateConfigLayout( |
| 2678 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2679 | self.sched.reconfigure(self.config) |
| 2680 | self.worker.build_history = [] |
| 2681 | |
| 2682 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2683 | B.addApproval('code-review', 2) |
| 2684 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2685 | self.waitUntilSettled() |
| 2686 | |
| 2687 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2688 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2689 | 'wheezy') |
| 2690 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2691 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2692 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2693 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2694 | self.updateConfigLayout( |
| 2695 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2696 | self.sched.reconfigure(self.config) |
| 2697 | |
| 2698 | self.init_repo("org/new-project") |
| 2699 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2700 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2701 | A.addApproval('code-review', 2) |
| 2702 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2703 | self.waitUntilSettled() |
| 2704 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2705 | 'SUCCESS') |
| 2706 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2707 | 'SUCCESS') |
| 2708 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2709 | 'SUCCESS') |
| 2710 | self.assertEqual(A.data['status'], 'MERGED') |
| 2711 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2712 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2713 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2714 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2715 | self.sched.reconfigure(self.config) |
| 2716 | |
| 2717 | self.init_repo("org/delete-project") |
| 2718 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2719 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2720 | A.addApproval('code-review', 2) |
| 2721 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2722 | self.waitUntilSettled() |
| 2723 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2724 | 'SUCCESS') |
| 2725 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2726 | 'SUCCESS') |
| 2727 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2728 | 'SUCCESS') |
| 2729 | self.assertEqual(A.data['status'], 'MERGED') |
| 2730 | self.assertEqual(A.reported, 2) |
| 2731 | |
| 2732 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2733 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2734 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2735 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
| 2736 | if os.path.exists(os.path.join(self.launcher_src_root, p)): |
| 2737 | shutil.rmtree(os.path.join(self.launcher_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2738 | |
| 2739 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2740 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2741 | B.addApproval('code-review', 2) |
| 2742 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2743 | self.waitUntilSettled() |
| 2744 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2745 | 'SUCCESS') |
| 2746 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2747 | 'SUCCESS') |
| 2748 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2749 | 'SUCCESS') |
| 2750 | self.assertEqual(B.data['status'], 'MERGED') |
| 2751 | self.assertEqual(B.reported, 2) |
| 2752 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2753 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2754 | def test_tags(self): |
| 2755 | "Test job tags" |
| 2756 | self.config.set('zuul', 'layout_config', |
| 2757 | 'tests/fixtures/layout-tags.yaml') |
| 2758 | self.sched.reconfigure(self.config) |
| 2759 | |
| 2760 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2761 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2762 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2763 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2764 | self.waitUntilSettled() |
| 2765 | |
| 2766 | results = {'project1-merge': 'extratag merge project1', |
| 2767 | 'project2-merge': 'merge'} |
| 2768 | |
| 2769 | for build in self.history: |
| 2770 | self.assertEqual(results.get(build.name, ''), |
| 2771 | build.parameters.get('BUILD_TAGS')) |
| 2772 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2773 | def test_timer(self): |
| 2774 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2775 | self.launch_server.hold_jobs_in_build = True |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2776 | self.updateConfigLayout('layout-timer') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2777 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2778 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2779 | # The pipeline triggers every second, so we should have seen |
| 2780 | # several by now. |
| 2781 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2782 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2783 | |
| 2784 | self.assertEqual(len(self.builds), 2) |
| 2785 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2786 | port = self.webapp.server.socket.getsockname()[1] |
| 2787 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2788 | req = urllib.request.Request( |
| 2789 | "http://localhost:%s/openstack/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2790 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2791 | data = f.read() |
| 2792 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2793 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2794 | # Stop queuing timer triggered jobs so that the assertions |
| 2795 | # below don't race against more jobs being queued. |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2796 | self.commitLayoutUpdate('layout-timer', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2797 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2798 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2799 | self.waitUntilSettled() |
| 2800 | |
| 2801 | self.assertEqual(self.getJobFromHistory( |
| 2802 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2803 | self.assertEqual(self.getJobFromHistory( |
| 2804 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2805 | |
| 2806 | data = json.loads(data) |
| 2807 | status_jobs = set() |
| 2808 | for p in data['pipelines']: |
| 2809 | for q in p['change_queues']: |
| 2810 | for head in q['heads']: |
| 2811 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2812 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2813 | for job in change['jobs']: |
| 2814 | status_jobs.add(job['name']) |
| 2815 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2816 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2817 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2818 | def test_idle(self): |
| 2819 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2820 | self.launch_server.hold_jobs_in_build = True |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2821 | self.updateConfigLayout('layout-idle') |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2822 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2823 | for x in range(1, 3): |
| 2824 | # Test that timer triggers periodic jobs even across |
| 2825 | # layout config reloads. |
| 2826 | # Start timer trigger |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2827 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2828 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2829 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2830 | # The pipeline triggers every second, so we should have seen |
| 2831 | # several by now. |
| 2832 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2833 | |
| 2834 | # Stop queuing timer triggered jobs so that the assertions |
| 2835 | # below don't race against more jobs being queued. |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2836 | before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2837 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2838 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2839 | self.assertEqual(len(self.builds), 2, |
| 2840 | 'Timer builds iteration #%d' % x) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2841 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2842 | self.waitUntilSettled() |
| 2843 | self.assertEqual(len(self.builds), 0) |
| 2844 | self.assertEqual(len(self.history), x * 2) |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2845 | # Revert back to layout-idle |
| 2846 | repo = git.Repo(os.path.join(self.test_root, |
| 2847 | 'upstream', |
| 2848 | 'layout-idle')) |
| 2849 | repo.git.reset('--hard', before) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2850 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2851 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2852 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2853 | self.sched.reconfigure(self.config) |
| 2854 | |
| 2855 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2856 | self.waitUntilSettled() |
| 2857 | |
| 2858 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2859 | self.waitUntilSettled() |
| 2860 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2861 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2862 | |
| 2863 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2864 | # work on the knowledge of what the first message should be as |
| 2865 | # it is only configured to go to SMTP. |
| 2866 | |
| 2867 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2868 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2869 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2870 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2871 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2872 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2873 | |
| 2874 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2875 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2876 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2877 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2878 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2879 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2880 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2881 | def test_timer_smtp(self): |
| 2882 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2883 | self.launch_server.hold_jobs_in_build = True |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 2884 | self.updateConfigLayout('layout-timer-smtp') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2885 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2886 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2887 | # The pipeline triggers every second, so we should have seen |
| 2888 | # several by now. |
| 2889 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2890 | self.waitUntilSettled() |
| 2891 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2892 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2893 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2894 | self.waitUntilSettled() |
| 2895 | self.assertEqual(len(self.history), 2) |
| 2896 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2897 | self.assertEqual(self.getJobFromHistory( |
| 2898 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2899 | self.assertEqual(self.getJobFromHistory( |
| 2900 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2901 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2902 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2903 | |
| 2904 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2905 | # work on the knowledge of what the first message should be as |
| 2906 | # it is only configured to go to SMTP. |
| 2907 | |
| 2908 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2909 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2910 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2911 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2912 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2913 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2914 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2915 | # Stop queuing timer triggered jobs and let any that may have |
| 2916 | # queued through so that end of test assertions pass. |
Clint Byrum | 7b71b2f | 2017-02-08 07:00:52 -0800 | [diff] [blame] | 2917 | self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2918 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2919 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2920 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2921 | self.waitUntilSettled() |
| 2922 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2923 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2924 | "Test that the RPC client can enqueue a change" |
| 2925 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2926 | A.addApproval('code-review', 2) |
| 2927 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2928 | |
| 2929 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2930 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2931 | r = client.enqueue(tenant='tenant-one', |
| 2932 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2933 | project='org/project', |
| 2934 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2935 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2936 | self.waitUntilSettled() |
| 2937 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2938 | 'SUCCESS') |
| 2939 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2940 | 'SUCCESS') |
| 2941 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2942 | 'SUCCESS') |
| 2943 | self.assertEqual(A.data['status'], 'MERGED') |
| 2944 | self.assertEqual(A.reported, 2) |
| 2945 | self.assertEqual(r, True) |
| 2946 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2947 | def test_client_enqueue_ref(self): |
| 2948 | "Test that the RPC client can enqueue a ref" |
| 2949 | |
| 2950 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2951 | self.gearman_server.port) |
| 2952 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2953 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2954 | pipeline='post', |
| 2955 | project='org/project', |
| 2956 | trigger='gerrit', |
| 2957 | ref='master', |
| 2958 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2959 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2960 | self.waitUntilSettled() |
| 2961 | job_names = [x.name for x in self.history] |
| 2962 | self.assertEqual(len(self.history), 1) |
| 2963 | self.assertIn('project-post', job_names) |
| 2964 | self.assertEqual(r, True) |
| 2965 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2966 | def test_client_enqueue_negative(self): |
| 2967 | "Test that the RPC client returns errors" |
| 2968 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2969 | self.gearman_server.port) |
| 2970 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2971 | "Invalid tenant"): |
| 2972 | r = client.enqueue(tenant='tenant-foo', |
| 2973 | pipeline='gate', |
| 2974 | project='org/project', |
| 2975 | trigger='gerrit', |
| 2976 | change='1,1') |
| 2977 | client.shutdown() |
| 2978 | self.assertEqual(r, False) |
| 2979 | |
| 2980 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2981 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2982 | r = client.enqueue(tenant='tenant-one', |
| 2983 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2984 | project='project-does-not-exist', |
| 2985 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2986 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2987 | client.shutdown() |
| 2988 | self.assertEqual(r, False) |
| 2989 | |
| 2990 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2991 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2992 | r = client.enqueue(tenant='tenant-one', |
| 2993 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2994 | project='org/project', |
| 2995 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2996 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2997 | client.shutdown() |
| 2998 | self.assertEqual(r, False) |
| 2999 | |
| 3000 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3001 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3002 | r = client.enqueue(tenant='tenant-one', |
| 3003 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3004 | project='org/project', |
| 3005 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3006 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3007 | client.shutdown() |
| 3008 | self.assertEqual(r, False) |
| 3009 | |
| 3010 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3011 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3012 | r = client.enqueue(tenant='tenant-one', |
| 3013 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3014 | project='org/project', |
| 3015 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3016 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3017 | client.shutdown() |
| 3018 | self.assertEqual(r, False) |
| 3019 | |
| 3020 | self.waitUntilSettled() |
| 3021 | self.assertEqual(len(self.history), 0) |
| 3022 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3023 | |
| 3024 | def test_client_promote(self): |
| 3025 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3026 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3027 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3028 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3029 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3030 | A.addApproval('code-review', 2) |
| 3031 | B.addApproval('code-review', 2) |
| 3032 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3033 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3034 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3035 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3036 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3037 | |
| 3038 | self.waitUntilSettled() |
| 3039 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3040 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3041 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3042 | enqueue_times = {} |
| 3043 | for item in items: |
| 3044 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3045 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3046 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3047 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3048 | r = client.promote(tenant='tenant-one', |
| 3049 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3050 | change_ids=['2,1', '3,1']) |
| 3051 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3052 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3053 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3054 | for item in items: |
| 3055 | self.assertEqual( |
| 3056 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3057 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3058 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3059 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3060 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3061 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3062 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3063 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3064 | self.waitUntilSettled() |
| 3065 | |
| 3066 | self.assertEqual(len(self.builds), 6) |
| 3067 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3068 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3069 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3070 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3071 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3072 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3073 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3074 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3075 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3076 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3077 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3078 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3079 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3080 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3081 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3082 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3083 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3084 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3085 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3086 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | self.waitUntilSettled() |
| 3088 | |
| 3089 | self.assertEqual(A.data['status'], 'MERGED') |
| 3090 | self.assertEqual(A.reported, 2) |
| 3091 | self.assertEqual(B.data['status'], 'MERGED') |
| 3092 | self.assertEqual(B.reported, 2) |
| 3093 | self.assertEqual(C.data['status'], 'MERGED') |
| 3094 | self.assertEqual(C.reported, 2) |
| 3095 | |
| 3096 | client.shutdown() |
| 3097 | self.assertEqual(r, True) |
| 3098 | |
| 3099 | def test_client_promote_dependent(self): |
| 3100 | "Test that the RPC client can promote a dependent change" |
| 3101 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3102 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3103 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3104 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3105 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3106 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3107 | |
| 3108 | C.setDependsOn(B, 1) |
| 3109 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3110 | A.addApproval('code-review', 2) |
| 3111 | B.addApproval('code-review', 2) |
| 3112 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3113 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3114 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3115 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3116 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3117 | |
| 3118 | self.waitUntilSettled() |
| 3119 | |
| 3120 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3121 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3122 | r = client.promote(tenant='tenant-one', |
| 3123 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3124 | change_ids=['3,1']) |
| 3125 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3126 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3127 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3128 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3129 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3130 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3131 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3132 | self.waitUntilSettled() |
| 3133 | |
| 3134 | self.assertEqual(len(self.builds), 6) |
| 3135 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3136 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3137 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3138 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3139 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3140 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3141 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3142 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3143 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3144 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3145 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3146 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3147 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3148 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3149 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3150 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3151 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3152 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3153 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3154 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3155 | self.waitUntilSettled() |
| 3156 | |
| 3157 | self.assertEqual(A.data['status'], 'MERGED') |
| 3158 | self.assertEqual(A.reported, 2) |
| 3159 | self.assertEqual(B.data['status'], 'MERGED') |
| 3160 | self.assertEqual(B.reported, 2) |
| 3161 | self.assertEqual(C.data['status'], 'MERGED') |
| 3162 | self.assertEqual(C.reported, 2) |
| 3163 | |
| 3164 | client.shutdown() |
| 3165 | self.assertEqual(r, True) |
| 3166 | |
| 3167 | def test_client_promote_negative(self): |
| 3168 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3169 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3170 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3171 | A.addApproval('code-review', 2) |
| 3172 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3173 | self.waitUntilSettled() |
| 3174 | |
| 3175 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3176 | self.gearman_server.port) |
| 3177 | |
| 3178 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3179 | r = client.promote(tenant='tenant-one', |
| 3180 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3181 | change_ids=['2,1', '3,1']) |
| 3182 | client.shutdown() |
| 3183 | self.assertEqual(r, False) |
| 3184 | |
| 3185 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3186 | r = client.promote(tenant='tenant-one', |
| 3187 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3188 | change_ids=['4,1']) |
| 3189 | client.shutdown() |
| 3190 | self.assertEqual(r, False) |
| 3191 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3192 | self.launch_server.hold_jobs_in_build = False |
| 3193 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3194 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3195 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3196 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3197 | def test_queue_rate_limiting(self): |
| 3198 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3199 | self.updateConfigLayout( |
| 3200 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3201 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3202 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3203 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3204 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3205 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3206 | |
| 3207 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3208 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3209 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3210 | A.addApproval('code-review', 2) |
| 3211 | B.addApproval('code-review', 2) |
| 3212 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3213 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3214 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3215 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3216 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3217 | self.waitUntilSettled() |
| 3218 | |
| 3219 | # Only A and B will have their merge jobs queued because |
| 3220 | # window is 2. |
| 3221 | self.assertEqual(len(self.builds), 2) |
| 3222 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3223 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3224 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3225 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3226 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3227 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3228 | self.waitUntilSettled() |
| 3229 | |
| 3230 | # Only A and B will have their test jobs queued because |
| 3231 | # window is 2. |
| 3232 | self.assertEqual(len(self.builds), 4) |
| 3233 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3234 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3235 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3236 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3237 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3238 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3239 | self.waitUntilSettled() |
| 3240 | |
| 3241 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3242 | # A failed so window is reduced by 1 to 1. |
| 3243 | self.assertEqual(queue.window, 1) |
| 3244 | self.assertEqual(queue.window_floor, 1) |
| 3245 | self.assertEqual(A.data['status'], 'NEW') |
| 3246 | |
| 3247 | # Gate is reset and only B's merge job is queued because |
| 3248 | # window shrunk to 1. |
| 3249 | self.assertEqual(len(self.builds), 1) |
| 3250 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3251 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3252 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3253 | self.waitUntilSettled() |
| 3254 | |
| 3255 | # Only B's test jobs are queued because window is still 1. |
| 3256 | self.assertEqual(len(self.builds), 2) |
| 3257 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3258 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3259 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3260 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3261 | self.waitUntilSettled() |
| 3262 | |
| 3263 | # B was successfully merged so window is increased to 2. |
| 3264 | self.assertEqual(queue.window, 2) |
| 3265 | self.assertEqual(queue.window_floor, 1) |
| 3266 | self.assertEqual(B.data['status'], 'MERGED') |
| 3267 | |
| 3268 | # Only C is left and its merge job is queued. |
| 3269 | self.assertEqual(len(self.builds), 1) |
| 3270 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3271 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3272 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3273 | self.waitUntilSettled() |
| 3274 | |
| 3275 | # After successful merge job the test jobs for C are queued. |
| 3276 | self.assertEqual(len(self.builds), 2) |
| 3277 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3278 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3279 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3280 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3281 | self.waitUntilSettled() |
| 3282 | |
| 3283 | # C successfully merged so window is bumped to 3. |
| 3284 | self.assertEqual(queue.window, 3) |
| 3285 | self.assertEqual(queue.window_floor, 1) |
| 3286 | self.assertEqual(C.data['status'], 'MERGED') |
| 3287 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3288 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3289 | def test_queue_rate_limiting_dependent(self): |
| 3290 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3291 | self.updateConfigLayout( |
| 3292 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3293 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3294 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3295 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3296 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3297 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3298 | |
| 3299 | B.setDependsOn(A, 1) |
| 3300 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3301 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3302 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3303 | A.addApproval('code-review', 2) |
| 3304 | B.addApproval('code-review', 2) |
| 3305 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3306 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3307 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3308 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3309 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3310 | self.waitUntilSettled() |
| 3311 | |
| 3312 | # Only A and B will have their merge jobs queued because |
| 3313 | # window is 2. |
| 3314 | self.assertEqual(len(self.builds), 2) |
| 3315 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3316 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3317 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3318 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3319 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3320 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3321 | self.waitUntilSettled() |
| 3322 | |
| 3323 | # Only A and B will have their test jobs queued because |
| 3324 | # window is 2. |
| 3325 | self.assertEqual(len(self.builds), 4) |
| 3326 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3327 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3328 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3329 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3330 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3331 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3332 | self.waitUntilSettled() |
| 3333 | |
| 3334 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3335 | # A failed so window is reduced by 1 to 1. |
| 3336 | self.assertEqual(queue.window, 1) |
| 3337 | self.assertEqual(queue.window_floor, 1) |
| 3338 | self.assertEqual(A.data['status'], 'NEW') |
| 3339 | self.assertEqual(B.data['status'], 'NEW') |
| 3340 | |
| 3341 | # Gate is reset and only C's merge job is queued because |
| 3342 | # window shrunk to 1 and A and B were dequeued. |
| 3343 | self.assertEqual(len(self.builds), 1) |
| 3344 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3345 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3346 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3347 | self.waitUntilSettled() |
| 3348 | |
| 3349 | # Only C's test jobs are queued because window is still 1. |
| 3350 | self.assertEqual(len(self.builds), 2) |
| 3351 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3352 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3353 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3354 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3355 | self.waitUntilSettled() |
| 3356 | |
| 3357 | # C was successfully merged so window is increased to 2. |
| 3358 | self.assertEqual(queue.window, 2) |
| 3359 | self.assertEqual(queue.window_floor, 1) |
| 3360 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3361 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3362 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3363 | def test_worker_update_metadata(self): |
| 3364 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3365 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3366 | |
| 3367 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3368 | A.addApproval('code-review', 2) |
| 3369 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | self.assertEqual(len(self.launcher.builds), 1) |
| 3373 | |
| 3374 | self.log.debug('Current builds:') |
| 3375 | self.log.debug(self.launcher.builds) |
| 3376 | |
| 3377 | start = time.time() |
| 3378 | while True: |
| 3379 | if time.time() - start > 10: |
| 3380 | raise Exception("Timeout waiting for gearman server to report " |
| 3381 | + "back to the client") |
| 3382 | build = self.launcher.builds.values()[0] |
| 3383 | if build.worker.name == "My Worker": |
| 3384 | break |
| 3385 | else: |
| 3386 | time.sleep(0) |
| 3387 | |
| 3388 | self.log.debug(build) |
| 3389 | self.assertEqual("My Worker", build.worker.name) |
| 3390 | self.assertEqual("localhost", build.worker.hostname) |
| 3391 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3392 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3393 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3394 | self.assertEqual("v1.1", build.worker.version) |
| 3395 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3396 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3397 | self.launch_server.hold_jobs_in_build = False |
| 3398 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3399 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3400 | |
| 3401 | def test_footer_message(self): |
| 3402 | "Test a pipeline's footer message is correctly added to the report." |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3403 | self.updateConfigLayout('layout-footer-message') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3404 | self.sched.reconfigure(self.config) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3405 | |
| 3406 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3407 | A.addApproval('code-review', 2) |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3408 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3409 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3410 | self.waitUntilSettled() |
| 3411 | |
| 3412 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3413 | B.addApproval('code-review', 2) |
| 3414 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3415 | self.waitUntilSettled() |
| 3416 | |
| 3417 | self.assertEqual(2, len(self.smtp_messages)) |
| 3418 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3419 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3420 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3421 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3422 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3423 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3424 | For CI problems and help debugging, contact ci@example.org""" |
| 3425 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3426 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3427 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3428 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3429 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3430 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3431 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3432 | def test_merge_failure_reporters(self): |
| 3433 | """Check that the config is set up correctly""" |
| 3434 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3435 | self.updateConfigLayout( |
| 3436 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3437 | self.sched.reconfigure(self.config) |
| 3438 | self.registerJobs() |
| 3439 | |
| 3440 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3441 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3442 | "dependencies was unable to be automatically merged with the " |
| 3443 | "current state of its repository. Please rebase the change and " |
| 3444 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3445 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3446 | self.assertEqual( |
| 3447 | "The merge failed! For more information...", |
| 3448 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3449 | |
| 3450 | self.assertEqual( |
| 3451 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3452 | self.assertEqual( |
| 3453 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3454 | |
| 3455 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3456 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3457 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3458 | |
| 3459 | self.assertTrue( |
| 3460 | ( |
| 3461 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3462 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3463 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3464 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3465 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3466 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3467 | ) or ( |
| 3468 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3469 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3470 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3471 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3472 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3473 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3474 | ) |
| 3475 | ) |
| 3476 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3477 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3478 | def test_merge_failure_reports(self): |
| 3479 | """Check that when a change fails to merge the correct message is sent |
| 3480 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3481 | self.updateConfigLayout( |
| 3482 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3483 | self.sched.reconfigure(self.config) |
| 3484 | self.registerJobs() |
| 3485 | |
| 3486 | # Check a test failure isn't reported to SMTP |
| 3487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3488 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3489 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3490 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3491 | self.waitUntilSettled() |
| 3492 | |
| 3493 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3494 | self.assertEqual(0, len(self.smtp_messages)) |
| 3495 | |
| 3496 | # Check a merge failure is reported to SMTP |
| 3497 | # B should be merged, but C will conflict with B |
| 3498 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3499 | B.addPatchset(['conflict']) |
| 3500 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3501 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3502 | B.addApproval('code-review', 2) |
| 3503 | C.addApproval('code-review', 2) |
| 3504 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3505 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3506 | self.waitUntilSettled() |
| 3507 | |
| 3508 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3509 | self.assertEqual(1, len(self.smtp_messages)) |
| 3510 | self.assertEqual('The merge failed! For more information...', |
| 3511 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3512 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3513 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3514 | def test_default_merge_failure_reports(self): |
| 3515 | """Check that the default merge failure reports are correct.""" |
| 3516 | |
| 3517 | # A should report success, B should report merge failure. |
| 3518 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3519 | A.addPatchset(['conflict']) |
| 3520 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3521 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3522 | A.addApproval('code-review', 2) |
| 3523 | B.addApproval('code-review', 2) |
| 3524 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3525 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3526 | self.waitUntilSettled() |
| 3527 | |
| 3528 | self.assertEqual(3, len(self.history)) # A jobs |
| 3529 | self.assertEqual(A.reported, 2) |
| 3530 | self.assertEqual(B.reported, 2) |
| 3531 | self.assertEqual(A.data['status'], 'MERGED') |
| 3532 | self.assertEqual(B.data['status'], 'NEW') |
| 3533 | self.assertIn('Build succeeded', A.messages[1]) |
| 3534 | self.assertIn('Merge Failed', B.messages[1]) |
| 3535 | self.assertIn('automatically merged', B.messages[1]) |
| 3536 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3537 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3538 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3539 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3540 | def test_swift_instructions(self): |
| 3541 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3542 | self.updateConfigLayout( |
| 3543 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3544 | self.sched.reconfigure(self.config) |
| 3545 | self.registerJobs() |
| 3546 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3547 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3548 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3549 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3550 | A.addApproval('code-review', 2) |
| 3551 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3552 | self.waitUntilSettled() |
| 3553 | |
| 3554 | self.assertEqual( |
| 3555 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3556 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3557 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3558 | self.assertEqual(5, |
| 3559 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3560 | split('\n'))) |
| 3561 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3562 | |
| 3563 | self.assertEqual( |
| 3564 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3565 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3566 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3567 | self.assertEqual(5, |
| 3568 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3569 | split('\n'))) |
| 3570 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3571 | |
| 3572 | self.assertEqual( |
| 3573 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3574 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3575 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3576 | self.assertEqual(5, |
| 3577 | len(self.builds[1]. |
| 3578 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3579 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3580 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3581 | self.launch_server.hold_jobs_in_build = False |
| 3582 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3583 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3584 | |
| 3585 | def test_client_get_running_jobs(self): |
| 3586 | "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] | 3587 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3588 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3589 | A.addApproval('code-review', 2) |
| 3590 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3591 | self.waitUntilSettled() |
| 3592 | |
| 3593 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3594 | self.gearman_server.port) |
| 3595 | |
| 3596 | # Wait for gearman server to send the initial workData back to zuul |
| 3597 | start = time.time() |
| 3598 | while True: |
| 3599 | if time.time() - start > 10: |
| 3600 | raise Exception("Timeout waiting for gearman server to report " |
| 3601 | + "back to the client") |
Clint Byrum | 78a6977 | 2016-12-05 10:52:07 -0800 | [diff] [blame] | 3602 | build = self.launch_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3603 | if build.worker.name == "My Worker": |
| 3604 | break |
| 3605 | else: |
| 3606 | time.sleep(0) |
| 3607 | |
| 3608 | running_items = client.get_running_jobs() |
| 3609 | |
| 3610 | self.assertEqual(1, len(running_items)) |
| 3611 | running_item = running_items[0] |
| 3612 | self.assertEqual([], running_item['failing_reasons']) |
| 3613 | self.assertEqual([], running_item['items_behind']) |
| 3614 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3615 | self.assertEqual(None, running_item['item_ahead']) |
| 3616 | self.assertEqual('org/project', running_item['project']) |
| 3617 | self.assertEqual(None, running_item['remaining_time']) |
| 3618 | self.assertEqual(True, running_item['active']) |
| 3619 | self.assertEqual('1,1', running_item['id']) |
| 3620 | |
| 3621 | self.assertEqual(3, len(running_item['jobs'])) |
| 3622 | for job in running_item['jobs']: |
| 3623 | if job['name'] == 'project-merge': |
| 3624 | self.assertEqual('project-merge', job['name']) |
| 3625 | self.assertEqual('gate', job['pipeline']) |
| 3626 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3627 | self.assertEqual('https://server/job/project-merge/0/', |
| 3628 | job['url']) |
| 3629 | self.assertEqual(7, len(job['worker'])) |
| 3630 | self.assertEqual(False, job['canceled']) |
| 3631 | self.assertEqual(True, job['voting']) |
| 3632 | self.assertEqual(None, job['result']) |
| 3633 | self.assertEqual('gate', job['pipeline']) |
| 3634 | break |
| 3635 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3636 | self.launch_server.hold_jobs_in_build = False |
| 3637 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3638 | self.waitUntilSettled() |
| 3639 | |
| 3640 | running_items = client.get_running_jobs() |
| 3641 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3642 | |
| 3643 | def test_nonvoting_pipeline(self): |
| 3644 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3645 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3646 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3647 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3648 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3649 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3650 | |
| 3651 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3652 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3653 | self.assertEqual( |
| 3654 | self.getJobFromHistory('experimental-project-test').result, |
| 3655 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3656 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3657 | |
| 3658 | def test_crd_gate(self): |
| 3659 | "Test cross-repo dependencies" |
| 3660 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3661 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3662 | A.addApproval('code-review', 2) |
| 3663 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3664 | |
| 3665 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3666 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3667 | AM2.setMerged() |
| 3668 | AM1.setMerged() |
| 3669 | |
| 3670 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3671 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3672 | BM2.setMerged() |
| 3673 | BM1.setMerged() |
| 3674 | |
| 3675 | # A -> AM1 -> AM2 |
| 3676 | # B -> BM1 -> BM2 |
| 3677 | # A Depends-On: B |
| 3678 | # M2 is here to make sure it is never queried. If it is, it |
| 3679 | # means zuul is walking down the entire history of merged |
| 3680 | # changes. |
| 3681 | |
| 3682 | B.setDependsOn(BM1, 1) |
| 3683 | BM1.setDependsOn(BM2, 1) |
| 3684 | |
| 3685 | A.setDependsOn(AM1, 1) |
| 3686 | AM1.setDependsOn(AM2, 1) |
| 3687 | |
| 3688 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3689 | A.subject, B.data['id']) |
| 3690 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3691 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3692 | self.waitUntilSettled() |
| 3693 | |
| 3694 | self.assertEqual(A.data['status'], 'NEW') |
| 3695 | self.assertEqual(B.data['status'], 'NEW') |
| 3696 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3697 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3698 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3699 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3700 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3701 | B.addApproval('approved', 1) |
| 3702 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3703 | self.waitUntilSettled() |
| 3704 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3705 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3706 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3707 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3708 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3709 | self.launch_server.hold_jobs_in_build = False |
| 3710 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3711 | self.waitUntilSettled() |
| 3712 | |
| 3713 | self.assertEqual(AM2.queried, 0) |
| 3714 | self.assertEqual(BM2.queried, 0) |
| 3715 | self.assertEqual(A.data['status'], 'MERGED') |
| 3716 | self.assertEqual(B.data['status'], 'MERGED') |
| 3717 | self.assertEqual(A.reported, 2) |
| 3718 | self.assertEqual(B.reported, 2) |
| 3719 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3720 | changes = self.getJobFromHistory( |
| 3721 | 'project-merge', 'org/project1').changes |
| 3722 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3723 | |
| 3724 | def test_crd_branch(self): |
| 3725 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3726 | |
| 3727 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3728 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3729 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3730 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3731 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3732 | A.addApproval('code-review', 2) |
| 3733 | B.addApproval('code-review', 2) |
| 3734 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3735 | |
| 3736 | # A Depends-On: B+C |
| 3737 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3738 | A.subject, B.data['id']) |
| 3739 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3740 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3741 | B.addApproval('approved', 1) |
| 3742 | C.addApproval('approved', 1) |
| 3743 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3744 | self.waitUntilSettled() |
| 3745 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3746 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3747 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3748 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3749 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3750 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3751 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3752 | self.launch_server.hold_jobs_in_build = False |
| 3753 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3754 | self.waitUntilSettled() |
| 3755 | |
| 3756 | self.assertEqual(A.data['status'], 'MERGED') |
| 3757 | self.assertEqual(B.data['status'], 'MERGED') |
| 3758 | self.assertEqual(C.data['status'], 'MERGED') |
| 3759 | self.assertEqual(A.reported, 2) |
| 3760 | self.assertEqual(B.reported, 2) |
| 3761 | self.assertEqual(C.reported, 2) |
| 3762 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3763 | changes = self.getJobFromHistory( |
| 3764 | 'project-merge', 'org/project1').changes |
| 3765 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3766 | |
| 3767 | def test_crd_multiline(self): |
| 3768 | "Test multiple depends-on lines in commit" |
| 3769 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3770 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3771 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3772 | A.addApproval('code-review', 2) |
| 3773 | B.addApproval('code-review', 2) |
| 3774 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3775 | |
| 3776 | # A Depends-On: B+C |
| 3777 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3778 | A.subject, B.data['id'], C.data['id']) |
| 3779 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3780 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3781 | B.addApproval('approved', 1) |
| 3782 | C.addApproval('approved', 1) |
| 3783 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3784 | self.waitUntilSettled() |
| 3785 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3786 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3787 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3788 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3789 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3790 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3791 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3792 | self.launch_server.hold_jobs_in_build = False |
| 3793 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3794 | self.waitUntilSettled() |
| 3795 | |
| 3796 | self.assertEqual(A.data['status'], 'MERGED') |
| 3797 | self.assertEqual(B.data['status'], 'MERGED') |
| 3798 | self.assertEqual(C.data['status'], 'MERGED') |
| 3799 | self.assertEqual(A.reported, 2) |
| 3800 | self.assertEqual(B.reported, 2) |
| 3801 | self.assertEqual(C.reported, 2) |
| 3802 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3803 | changes = self.getJobFromHistory( |
| 3804 | 'project-merge', 'org/project1').changes |
| 3805 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3806 | |
| 3807 | def test_crd_unshared_gate(self): |
| 3808 | "Test cross-repo dependencies in unshared gate queues" |
| 3809 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3810 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3811 | A.addApproval('code-review', 2) |
| 3812 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3813 | |
| 3814 | # A Depends-On: B |
| 3815 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3816 | A.subject, B.data['id']) |
| 3817 | |
| 3818 | # A and B do not share a queue, make sure that A is unable to |
| 3819 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3820 | B.addApproval('approved', 1) |
| 3821 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3822 | self.waitUntilSettled() |
| 3823 | |
| 3824 | self.assertEqual(A.data['status'], 'NEW') |
| 3825 | self.assertEqual(B.data['status'], 'NEW') |
| 3826 | self.assertEqual(A.reported, 0) |
| 3827 | self.assertEqual(B.reported, 0) |
| 3828 | self.assertEqual(len(self.history), 0) |
| 3829 | |
| 3830 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3831 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3832 | self.waitUntilSettled() |
| 3833 | |
| 3834 | self.assertEqual(B.data['status'], 'MERGED') |
| 3835 | self.assertEqual(B.reported, 2) |
| 3836 | |
| 3837 | # Now that B is merged, A should be able to be enqueued and |
| 3838 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3839 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3840 | self.waitUntilSettled() |
| 3841 | |
| 3842 | self.assertEqual(A.data['status'], 'MERGED') |
| 3843 | self.assertEqual(A.reported, 2) |
| 3844 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3845 | def test_crd_gate_reverse(self): |
| 3846 | "Test reverse cross-repo dependencies" |
| 3847 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3848 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3849 | A.addApproval('code-review', 2) |
| 3850 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3851 | |
| 3852 | # A Depends-On: B |
| 3853 | |
| 3854 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3855 | A.subject, B.data['id']) |
| 3856 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3857 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3858 | self.waitUntilSettled() |
| 3859 | |
| 3860 | self.assertEqual(A.data['status'], 'NEW') |
| 3861 | self.assertEqual(B.data['status'], 'NEW') |
| 3862 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3863 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3864 | A.addApproval('approved', 1) |
| 3865 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3866 | self.waitUntilSettled() |
| 3867 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3868 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3869 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3870 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3871 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3872 | self.launch_server.hold_jobs_in_build = False |
| 3873 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3874 | self.waitUntilSettled() |
| 3875 | |
| 3876 | self.assertEqual(A.data['status'], 'MERGED') |
| 3877 | self.assertEqual(B.data['status'], 'MERGED') |
| 3878 | self.assertEqual(A.reported, 2) |
| 3879 | self.assertEqual(B.reported, 2) |
| 3880 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3881 | changes = self.getJobFromHistory( |
| 3882 | 'project-merge', 'org/project1').changes |
| 3883 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3884 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3885 | def test_crd_cycle(self): |
| 3886 | "Test cross-repo dependency cycles" |
| 3887 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3888 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3889 | A.addApproval('code-review', 2) |
| 3890 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3891 | |
| 3892 | # A -> B -> A (via commit-depends) |
| 3893 | |
| 3894 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3895 | A.subject, B.data['id']) |
| 3896 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3897 | B.subject, A.data['id']) |
| 3898 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3899 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3900 | self.waitUntilSettled() |
| 3901 | |
| 3902 | self.assertEqual(A.reported, 0) |
| 3903 | self.assertEqual(B.reported, 0) |
| 3904 | self.assertEqual(A.data['status'], 'NEW') |
| 3905 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3906 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3907 | def test_crd_gate_unknown(self): |
| 3908 | "Test unknown projects in dependent pipeline" |
| 3909 | self.init_repo("org/unknown") |
| 3910 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3911 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3912 | A.addApproval('code-review', 2) |
| 3913 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3914 | |
| 3915 | # A Depends-On: B |
| 3916 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3917 | A.subject, B.data['id']) |
| 3918 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3919 | B.addApproval('approved', 1) |
| 3920 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3921 | self.waitUntilSettled() |
| 3922 | |
| 3923 | # Unknown projects cannot share a queue with any other |
| 3924 | # since they don't have common jobs with any other (they have no jobs). |
| 3925 | # Changes which depend on unknown project changes |
| 3926 | # should not be processed in dependent pipeline |
| 3927 | self.assertEqual(A.data['status'], 'NEW') |
| 3928 | self.assertEqual(B.data['status'], 'NEW') |
| 3929 | self.assertEqual(A.reported, 0) |
| 3930 | self.assertEqual(B.reported, 0) |
| 3931 | self.assertEqual(len(self.history), 0) |
| 3932 | |
| 3933 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3934 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3935 | B.setMerged() |
| 3936 | self.waitUntilSettled() |
| 3937 | self.assertEqual(len(self.history), 0) |
| 3938 | |
| 3939 | # Now that B is merged, A should be able to be enqueued and |
| 3940 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3941 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3942 | self.waitUntilSettled() |
| 3943 | |
| 3944 | self.assertEqual(A.data['status'], 'MERGED') |
| 3945 | self.assertEqual(A.reported, 2) |
| 3946 | self.assertEqual(B.data['status'], 'MERGED') |
| 3947 | self.assertEqual(B.reported, 0) |
| 3948 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3949 | def test_crd_check(self): |
| 3950 | "Test cross-repo dependencies in independent pipelines" |
| 3951 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3952 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3953 | self.gearman_server.hold_jobs_in_queue = True |
| 3954 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3955 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3956 | |
| 3957 | # A Depends-On: B |
| 3958 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3959 | A.subject, B.data['id']) |
| 3960 | |
| 3961 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3962 | self.waitUntilSettled() |
| 3963 | |
| 3964 | queue = self.gearman_server.getQueue() |
| 3965 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 3966 | self.gearman_server.hold_jobs_in_queue = False |
| 3967 | self.gearman_server.release() |
| 3968 | self.waitUntilSettled() |
| 3969 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3970 | self.launch_server.release('.*-merge') |
| 3971 | self.waitUntilSettled() |
| 3972 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3973 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3974 | repo = git.Repo(path) |
| 3975 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3976 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3977 | correct_messages = [ |
| 3978 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3979 | self.assertEqual(repo_messages, correct_messages) |
| 3980 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 3981 | path = os.path.join(self.builds[0].jobdir.src_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3982 | repo = git.Repo(path) |
| 3983 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3984 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3985 | correct_messages = [ |
| 3986 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3987 | self.assertEqual(repo_messages, correct_messages) |
| 3988 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3989 | self.launch_server.hold_jobs_in_build = False |
| 3990 | self.launch_server.release() |
| 3991 | self.waitUntilSettled() |
| 3992 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3993 | self.assertEqual(A.data['status'], 'NEW') |
| 3994 | self.assertEqual(B.data['status'], 'NEW') |
| 3995 | self.assertEqual(A.reported, 1) |
| 3996 | self.assertEqual(B.reported, 0) |
| 3997 | |
| 3998 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3999 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4000 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4001 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4002 | def test_crd_check_git_depends(self): |
| 4003 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4004 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4005 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4006 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4007 | |
| 4008 | # Add two git-dependent changes and make sure they both report |
| 4009 | # success. |
| 4010 | B.setDependsOn(A, 1) |
| 4011 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4012 | self.waitUntilSettled() |
| 4013 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4014 | self.waitUntilSettled() |
| 4015 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4016 | self.orderedRelease() |
| 4017 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4018 | self.waitUntilSettled() |
| 4019 | |
| 4020 | self.assertEqual(A.data['status'], 'NEW') |
| 4021 | self.assertEqual(B.data['status'], 'NEW') |
| 4022 | self.assertEqual(A.reported, 1) |
| 4023 | self.assertEqual(B.reported, 1) |
| 4024 | |
| 4025 | self.assertEqual(self.history[0].changes, '1,1') |
| 4026 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4027 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4028 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4029 | |
| 4030 | self.assertIn('Build succeeded', A.messages[0]) |
| 4031 | self.assertIn('Build succeeded', B.messages[0]) |
| 4032 | |
| 4033 | def test_crd_check_duplicate(self): |
| 4034 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4035 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4036 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4037 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4038 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4039 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4040 | |
| 4041 | # Add two git-dependent changes... |
| 4042 | B.setDependsOn(A, 1) |
| 4043 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4044 | self.waitUntilSettled() |
| 4045 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4046 | |
| 4047 | # ...make sure the live one is not duplicated... |
| 4048 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4049 | self.waitUntilSettled() |
| 4050 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4051 | |
| 4052 | # ...but the non-live one is able to be. |
| 4053 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4054 | self.waitUntilSettled() |
| 4055 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4056 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4057 | # Release jobs in order to avoid races with change A jobs |
| 4058 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4059 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4060 | self.launch_server.hold_jobs_in_build = False |
| 4061 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4062 | self.waitUntilSettled() |
| 4063 | |
| 4064 | self.assertEqual(A.data['status'], 'NEW') |
| 4065 | self.assertEqual(B.data['status'], 'NEW') |
| 4066 | self.assertEqual(A.reported, 1) |
| 4067 | self.assertEqual(B.reported, 1) |
| 4068 | |
| 4069 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4070 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4071 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4072 | |
| 4073 | self.assertIn('Build succeeded', A.messages[0]) |
| 4074 | self.assertIn('Build succeeded', B.messages[0]) |
| 4075 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4076 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4077 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4078 | |
| 4079 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4080 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4081 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4082 | |
| 4083 | # A Depends-On: B |
| 4084 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4085 | A.subject, B.data['id']) |
| 4086 | |
| 4087 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4088 | self.waitUntilSettled() |
| 4089 | |
| 4090 | self.sched.reconfigure(self.config) |
| 4091 | |
| 4092 | # Make sure the items still share a change queue, and the |
| 4093 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4094 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4095 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4096 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4097 | first_item = queue.queue[0] |
| 4098 | for item in queue.queue: |
| 4099 | self.assertEqual(item.queue, first_item.queue) |
| 4100 | self.assertFalse(first_item.live) |
| 4101 | self.assertTrue(queue.queue[1].live) |
| 4102 | |
| 4103 | self.gearman_server.hold_jobs_in_queue = False |
| 4104 | self.gearman_server.release() |
| 4105 | self.waitUntilSettled() |
| 4106 | |
| 4107 | self.assertEqual(A.data['status'], 'NEW') |
| 4108 | self.assertEqual(B.data['status'], 'NEW') |
| 4109 | self.assertEqual(A.reported, 1) |
| 4110 | self.assertEqual(B.reported, 0) |
| 4111 | |
| 4112 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4113 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4114 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4115 | def test_crd_check_reconfiguration(self): |
| 4116 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4117 | |
| 4118 | def test_crd_undefined_project(self): |
| 4119 | """Test that undefined projects in dependencies are handled for |
| 4120 | independent pipelines""" |
| 4121 | # It's a hack for fake gerrit, |
| 4122 | # as it implies repo creation upon the creation of any change |
| 4123 | self.init_repo("org/unknown") |
| 4124 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4125 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4126 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4127 | def test_crd_check_ignore_dependencies(self): |
| 4128 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4129 | self.updateConfigLayout( |
| 4130 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4131 | self.sched.reconfigure(self.config) |
| 4132 | self.registerJobs() |
| 4133 | |
| 4134 | self.gearman_server.hold_jobs_in_queue = True |
| 4135 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4136 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4137 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4138 | |
| 4139 | # A Depends-On: B |
| 4140 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4141 | A.subject, B.data['id']) |
| 4142 | # C git-depends on B |
| 4143 | C.setDependsOn(B, 1) |
| 4144 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4145 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4146 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4147 | self.waitUntilSettled() |
| 4148 | |
| 4149 | # Make sure none of the items share a change queue, and all |
| 4150 | # are live. |
| 4151 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4152 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4153 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4154 | for item in check_pipeline.getAllItems(): |
| 4155 | self.assertTrue(item.live) |
| 4156 | |
| 4157 | self.gearman_server.hold_jobs_in_queue = False |
| 4158 | self.gearman_server.release() |
| 4159 | self.waitUntilSettled() |
| 4160 | |
| 4161 | self.assertEqual(A.data['status'], 'NEW') |
| 4162 | self.assertEqual(B.data['status'], 'NEW') |
| 4163 | self.assertEqual(C.data['status'], 'NEW') |
| 4164 | self.assertEqual(A.reported, 1) |
| 4165 | self.assertEqual(B.reported, 1) |
| 4166 | self.assertEqual(C.reported, 1) |
| 4167 | |
| 4168 | # Each job should have tested exactly one change |
| 4169 | for job in self.history: |
| 4170 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4171 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4172 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4173 | def test_crd_check_transitive(self): |
| 4174 | "Test transitive cross-repo dependencies" |
| 4175 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4176 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4177 | # and C,2 (not C,1 which would indicate stale data in the |
| 4178 | # cache for B). |
| 4179 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4180 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4181 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4182 | |
| 4183 | # A Depends-On: B |
| 4184 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4185 | A.subject, B.data['id']) |
| 4186 | |
| 4187 | # B Depends-On: C |
| 4188 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4189 | B.subject, C.data['id']) |
| 4190 | |
| 4191 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4192 | self.waitUntilSettled() |
| 4193 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4194 | |
| 4195 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4196 | self.waitUntilSettled() |
| 4197 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4198 | |
| 4199 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4200 | self.waitUntilSettled() |
| 4201 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4202 | |
| 4203 | C.addPatchset() |
| 4204 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4205 | self.waitUntilSettled() |
| 4206 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4207 | |
| 4208 | A.addPatchset() |
| 4209 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4210 | self.waitUntilSettled() |
| 4211 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4212 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4213 | def test_crd_check_unknown(self): |
| 4214 | "Test unknown projects in independent pipeline" |
| 4215 | self.init_repo("org/unknown") |
| 4216 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4217 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4218 | # A Depends-On: B |
| 4219 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4220 | A.subject, B.data['id']) |
| 4221 | |
| 4222 | # Make sure zuul has seen an event on B. |
| 4223 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4224 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4225 | self.waitUntilSettled() |
| 4226 | |
| 4227 | self.assertEqual(A.data['status'], 'NEW') |
| 4228 | self.assertEqual(A.reported, 1) |
| 4229 | self.assertEqual(B.data['status'], 'NEW') |
| 4230 | self.assertEqual(B.reported, 0) |
| 4231 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4232 | def test_crd_cycle_join(self): |
| 4233 | "Test an updated change creates a cycle" |
| 4234 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4235 | |
| 4236 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4237 | self.waitUntilSettled() |
| 4238 | |
| 4239 | # Create B->A |
| 4240 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4241 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4242 | B.subject, A.data['id']) |
| 4243 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4244 | self.waitUntilSettled() |
| 4245 | |
| 4246 | # Update A to add A->B (a cycle). |
| 4247 | A.addPatchset() |
| 4248 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4249 | A.subject, B.data['id']) |
| 4250 | # Normally we would submit the patchset-created event for |
| 4251 | # processing here, however, we have no way of noting whether |
| 4252 | # the dependency cycle detection correctly raised an |
| 4253 | # exception, so instead, we reach into the source driver and |
| 4254 | # call the method that would ultimately be called by the event |
| 4255 | # processing. |
| 4256 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4257 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4258 | source = tenant.layout.pipelines['gate'].source |
| 4259 | |
| 4260 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4261 | # it easier for users to create events for testing. |
| 4262 | event = zuul.model.TriggerEvent() |
| 4263 | event.trigger_name = 'gerrit' |
| 4264 | event.change_number = '1' |
| 4265 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4266 | with testtools.ExpectedException( |
| 4267 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4268 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4269 | self.log.debug("Got expected dependency cycle exception") |
| 4270 | |
| 4271 | # Now if we update B to remove the depends-on, everything |
| 4272 | # should be okay. B; A->B |
| 4273 | |
| 4274 | B.addPatchset() |
| 4275 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4276 | |
| 4277 | source.getChange(event, True) |
| 4278 | event.change_number = '2' |
| 4279 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4280 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4281 | def test_disable_at(self): |
| 4282 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4283 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4284 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4285 | self.sched.reconfigure(self.config) |
| 4286 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4287 | tenant = self.sched.abide.tenants.get('openstack') |
| 4288 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4289 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4290 | 0, 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 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4294 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4295 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4296 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4297 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4298 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4299 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4300 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4301 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4302 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4303 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4304 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4305 | self.launch_server.failJob('project-test1', A) |
| 4306 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4307 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4308 | self.launch_server.failJob('project-test1', D) |
| 4309 | self.launch_server.failJob('project-test1', E) |
| 4310 | self.launch_server.failJob('project-test1', F) |
| 4311 | self.launch_server.failJob('project-test1', G) |
| 4312 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4313 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4314 | self.launch_server.failJob('project-test1', J) |
| 4315 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4316 | |
| 4317 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4318 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4319 | self.waitUntilSettled() |
| 4320 | |
| 4321 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4322 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4323 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4324 | |
| 4325 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4326 | self.waitUntilSettled() |
| 4327 | |
| 4328 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4329 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4330 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4331 | |
| 4332 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4333 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4334 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4335 | self.waitUntilSettled() |
| 4336 | |
| 4337 | # We should be disabled now |
| 4338 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4339 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4340 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4341 | |
| 4342 | # We need to wait between each of these patches to make sure the |
| 4343 | # smtp messages come back in an expected order |
| 4344 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4345 | self.waitUntilSettled() |
| 4346 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4347 | self.waitUntilSettled() |
| 4348 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4349 | self.waitUntilSettled() |
| 4350 | |
| 4351 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4352 | # leaving a message on each change |
| 4353 | self.assertEqual(1, len(A.messages)) |
| 4354 | self.assertIn('Build failed.', A.messages[0]) |
| 4355 | self.assertEqual(1, len(B.messages)) |
| 4356 | self.assertIn('Build failed.', B.messages[0]) |
| 4357 | self.assertEqual(1, len(C.messages)) |
| 4358 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4359 | self.assertEqual(1, len(D.messages)) |
| 4360 | self.assertIn('Build failed.', D.messages[0]) |
| 4361 | self.assertEqual(1, len(E.messages)) |
| 4362 | self.assertIn('Build failed.', E.messages[0]) |
| 4363 | self.assertEqual(1, len(F.messages)) |
| 4364 | self.assertIn('Build failed.', F.messages[0]) |
| 4365 | |
| 4366 | # The last 3 (GHI) would have only reported via smtp. |
| 4367 | self.assertEqual(3, len(self.smtp_messages)) |
| 4368 | self.assertEqual(0, len(G.messages)) |
| 4369 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4370 | self.assertIn( |
| 4371 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4372 | self.assertEqual(0, len(H.messages)) |
| 4373 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4374 | self.assertIn( |
| 4375 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4376 | self.assertEqual(0, len(I.messages)) |
| 4377 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4378 | self.assertIn( |
| 4379 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4380 | |
| 4381 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4382 | # comes out of disabled |
| 4383 | self.sched.reconfigure(self.config) |
| 4384 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4385 | tenant = self.sched.abide.tenants.get('openstack') |
| 4386 | |
| 4387 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4388 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4389 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4390 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4391 | |
| 4392 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4393 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4394 | self.waitUntilSettled() |
| 4395 | |
| 4396 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4397 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4398 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4399 | |
| 4400 | # J and K went back to gerrit |
| 4401 | self.assertEqual(1, len(J.messages)) |
| 4402 | self.assertIn('Build failed.', J.messages[0]) |
| 4403 | self.assertEqual(1, len(K.messages)) |
| 4404 | self.assertIn('Build failed.', K.messages[0]) |
| 4405 | # No more messages reported via smtp |
| 4406 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4407 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4408 | def test_rerun_on_abort(self): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4409 | "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] | 4410 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4411 | self.launch_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4412 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4413 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4414 | self.waitUntilSettled() |
| 4415 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4416 | self.launch_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4417 | self.waitUntilSettled() |
| 4418 | |
| 4419 | self.assertEqual(len(self.builds), 2) |
| 4420 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4421 | self.launch_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4422 | self.waitUntilSettled() |
| 4423 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4424 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4425 | self.assertEqual(len(self.builds), 1, |
| 4426 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4427 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4428 | self.launch_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4429 | self.waitUntilSettled() |
| 4430 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4431 | self.launch_server.hold_jobs_in_build = False |
| 4432 | self.launch_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4433 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4434 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4435 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4436 | self.assertEqual(A.reported, 1) |
| 4437 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4438 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4439 | def test_zookeeper_disconnect(self): |
| 4440 | "Test that jobs are launched after a zookeeper disconnect" |
| 4441 | |
| 4442 | self.fake_nodepool.paused = True |
| 4443 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4444 | A.addApproval('code-review', 2) |
| 4445 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4446 | self.waitUntilSettled() |
| 4447 | |
| 4448 | self.zk.client.stop() |
| 4449 | self.zk.client.start() |
| 4450 | self.fake_nodepool.paused = False |
| 4451 | self.waitUntilSettled() |
| 4452 | |
| 4453 | self.assertEqual(A.data['status'], 'MERGED') |
| 4454 | self.assertEqual(A.reported, 2) |
| 4455 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4456 | def test_nodepool_failure(self): |
| 4457 | "Test that jobs are reported after a nodepool failure" |
| 4458 | |
| 4459 | self.fake_nodepool.paused = True |
| 4460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4461 | A.addApproval('code-review', 2) |
| 4462 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4463 | self.waitUntilSettled() |
| 4464 | |
| 4465 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4466 | self.fake_nodepool.addFailRequest(req) |
| 4467 | |
| 4468 | self.fake_nodepool.paused = False |
| 4469 | self.waitUntilSettled() |
| 4470 | |
| 4471 | self.assertEqual(A.data['status'], 'NEW') |
| 4472 | self.assertEqual(A.reported, 2) |
| 4473 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4474 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4475 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4476 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4477 | |
| 4478 | class TestDuplicatePipeline(ZuulTestCase): |
| 4479 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4480 | |
| 4481 | def test_duplicate_pipelines(self): |
| 4482 | "Test that a change matching multiple pipelines works" |
| 4483 | |
| 4484 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4485 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4486 | self.waitUntilSettled() |
| 4487 | |
| 4488 | self.assertHistory([ |
| 4489 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4490 | pipeline='dup1'), |
| 4491 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4492 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4493 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4494 | |
| 4495 | self.assertEqual(len(A.messages), 2) |
| 4496 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4497 | if 'dup1' in A.messages[0]: |
| 4498 | self.assertIn('dup1', A.messages[0]) |
| 4499 | self.assertNotIn('dup2', A.messages[0]) |
| 4500 | self.assertIn('project-test1', A.messages[0]) |
| 4501 | self.assertIn('dup2', A.messages[1]) |
| 4502 | self.assertNotIn('dup1', A.messages[1]) |
| 4503 | self.assertIn('project-test1', A.messages[1]) |
| 4504 | else: |
| 4505 | self.assertIn('dup1', A.messages[1]) |
| 4506 | self.assertNotIn('dup2', A.messages[1]) |
| 4507 | self.assertIn('project-test1', A.messages[1]) |
| 4508 | self.assertIn('dup2', A.messages[0]) |
| 4509 | self.assertNotIn('dup1', A.messages[0]) |
| 4510 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4511 | |
| 4512 | |
| 4513 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4514 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4515 | |
| 4516 | def test_one_job_project(self): |
| 4517 | "Test that queueing works with one job" |
| 4518 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4519 | 'master', 'A') |
| 4520 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4521 | 'master', 'B') |
| 4522 | A.addApproval('code-review', 2) |
| 4523 | B.addApproval('code-review', 2) |
| 4524 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4525 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4526 | self.waitUntilSettled() |
| 4527 | |
| 4528 | self.assertEqual(A.data['status'], 'MERGED') |
| 4529 | self.assertEqual(A.reported, 2) |
| 4530 | self.assertEqual(B.data['status'], 'MERGED') |
| 4531 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4532 | |
| 4533 | |
| 4534 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4535 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4536 | |
| 4537 | def test_job_from_templates_launched(self): |
| 4538 | "Test whether a job generated via a template can be launched" |
| 4539 | |
| 4540 | A = self.fake_gerrit.addFakeChange( |
| 4541 | 'org/templated-project', 'master', 'A') |
| 4542 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4543 | self.waitUntilSettled() |
| 4544 | |
| 4545 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4546 | 'SUCCESS') |
| 4547 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4548 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4549 | |
| 4550 | def test_layered_templates(self): |
| 4551 | "Test whether a job generated via a template can be launched" |
| 4552 | |
| 4553 | A = self.fake_gerrit.addFakeChange( |
| 4554 | 'org/layered-project', 'master', 'A') |
| 4555 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4556 | self.waitUntilSettled() |
| 4557 | |
| 4558 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4559 | 'SUCCESS') |
| 4560 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4561 | 'SUCCESS') |
| 4562 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4563 | ).result, 'SUCCESS') |
| 4564 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4565 | ).result, 'SUCCESS') |
| 4566 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4567 | ).result, 'SUCCESS') |
| 4568 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4569 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4570 | |
| 4571 | |
| 4572 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4573 | tenant_config_file = 'config/success-url/main.yaml' |
| 4574 | |
| 4575 | def test_success_url(self): |
| 4576 | "Ensure bad build params are ignored" |
| 4577 | self.sched.reconfigure(self.config) |
| 4578 | self.init_repo('org/docs') |
| 4579 | |
| 4580 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4581 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4582 | self.waitUntilSettled() |
| 4583 | |
| 4584 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4585 | self.assertEqual(len(self.history), 2) |
| 4586 | |
| 4587 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4588 | for build in self.history: |
| 4589 | if build.name == 'docs-draft-test': |
| 4590 | uuid = build.uuid[:7] |
| 4591 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4592 | |
| 4593 | # Two msgs: 'Starting...' + results |
| 4594 | self.assertEqual(len(self.smtp_messages), 2) |
| 4595 | body = self.smtp_messages[1]['body'].splitlines() |
| 4596 | self.assertEqual('Build succeeded.', body[0]) |
| 4597 | |
| 4598 | self.assertIn( |
| 4599 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4600 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4601 | body[2]) |
| 4602 | |
| 4603 | # NOTE: This default URL is currently hard-coded in launcher/server.py |
| 4604 | self.assertIn( |
| 4605 | '- docs-draft-test2 https://server/job', |
| 4606 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4607 | |
| 4608 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4609 | class TestSchedulerMerges(ZuulTestCase): |
| 4610 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4611 | |
| 4612 | def _test_project_merge_mode(self, mode): |
| 4613 | self.launch_server.keep_jobdir = False |
| 4614 | project = 'org/project-%s' % mode |
| 4615 | self.launch_server.hold_jobs_in_build = True |
| 4616 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4617 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4618 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4619 | A.addApproval('code-review', 2) |
| 4620 | B.addApproval('code-review', 2) |
| 4621 | C.addApproval('code-review', 2) |
| 4622 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4623 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4624 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4625 | self.waitUntilSettled() |
| 4626 | |
| 4627 | build = self.builds[-1] |
| 4628 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4629 | |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4630 | path = os.path.join(build.jobdir.src_root, project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4631 | repo = git.Repo(path) |
| 4632 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4633 | repo_messages.reverse() |
| 4634 | |
| 4635 | self.launch_server.hold_jobs_in_build = False |
| 4636 | self.launch_server.release() |
| 4637 | self.waitUntilSettled() |
| 4638 | |
| 4639 | return repo_messages |
| 4640 | |
| 4641 | def _test_merge(self, mode): |
| 4642 | us_path = os.path.join( |
| 4643 | self.upstream_root, 'org/project-%s' % mode) |
| 4644 | expected_messages = [ |
| 4645 | 'initial commit', |
| 4646 | 'add content from fixture', |
| 4647 | # the intermediate commits order is nondeterministic |
| 4648 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4649 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4650 | ] |
| 4651 | result = self._test_project_merge_mode(mode) |
| 4652 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4653 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4654 | |
| 4655 | def test_project_merge_mode_merge(self): |
| 4656 | self._test_merge('merge') |
| 4657 | |
| 4658 | def test_project_merge_mode_merge_resolve(self): |
| 4659 | self._test_merge('merge-resolve') |
| 4660 | |
| 4661 | def test_project_merge_mode_cherrypick(self): |
| 4662 | expected_messages = [ |
| 4663 | 'initial commit', |
| 4664 | 'add content from fixture', |
| 4665 | 'A-1', |
| 4666 | 'B-1', |
| 4667 | 'C-1'] |
| 4668 | result = self._test_project_merge_mode('cherry-pick') |
| 4669 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4670 | |
| 4671 | def test_merge_branch(self): |
| 4672 | "Test that the right commits are on alternate branches" |
| 4673 | self.create_branch('org/project-merge-branches', 'mp') |
| 4674 | |
| 4675 | self.launch_server.hold_jobs_in_build = True |
| 4676 | A = self.fake_gerrit.addFakeChange( |
| 4677 | 'org/project-merge-branches', 'mp', 'A') |
| 4678 | B = self.fake_gerrit.addFakeChange( |
| 4679 | 'org/project-merge-branches', 'mp', 'B') |
| 4680 | C = self.fake_gerrit.addFakeChange( |
| 4681 | 'org/project-merge-branches', 'mp', 'C') |
| 4682 | A.addApproval('code-review', 2) |
| 4683 | B.addApproval('code-review', 2) |
| 4684 | C.addApproval('code-review', 2) |
| 4685 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4686 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4687 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4688 | self.waitUntilSettled() |
| 4689 | |
| 4690 | self.launch_server.release('.*-merge') |
| 4691 | self.waitUntilSettled() |
| 4692 | self.launch_server.release('.*-merge') |
| 4693 | self.waitUntilSettled() |
| 4694 | self.launch_server.release('.*-merge') |
| 4695 | self.waitUntilSettled() |
| 4696 | |
| 4697 | build = self.builds[-1] |
| 4698 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4699 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4700 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4701 | build.jobdir.src_root, 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4702 | repo = git.Repo(path) |
| 4703 | |
| 4704 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4705 | repo_messages.reverse() |
| 4706 | correct_messages = [ |
| 4707 | 'initial commit', |
| 4708 | 'add content from fixture', |
| 4709 | 'mp commit', |
| 4710 | 'A-1', 'B-1', 'C-1'] |
| 4711 | self.assertEqual(repo_messages, correct_messages) |
| 4712 | |
| 4713 | self.launch_server.hold_jobs_in_build = False |
| 4714 | self.launch_server.release() |
| 4715 | self.waitUntilSettled() |
| 4716 | |
| 4717 | def test_merge_multi_branch(self): |
| 4718 | "Test that dependent changes on multiple branches are merged" |
| 4719 | self.create_branch('org/project-merge-branches', 'mp') |
| 4720 | |
| 4721 | self.launch_server.hold_jobs_in_build = True |
| 4722 | A = self.fake_gerrit.addFakeChange( |
| 4723 | 'org/project-merge-branches', 'master', 'A') |
| 4724 | B = self.fake_gerrit.addFakeChange( |
| 4725 | 'org/project-merge-branches', 'mp', 'B') |
| 4726 | C = self.fake_gerrit.addFakeChange( |
| 4727 | 'org/project-merge-branches', 'master', 'C') |
| 4728 | A.addApproval('code-review', 2) |
| 4729 | B.addApproval('code-review', 2) |
| 4730 | C.addApproval('code-review', 2) |
| 4731 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4732 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4733 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4734 | self.waitUntilSettled() |
| 4735 | |
| 4736 | job_A = None |
| 4737 | for job in self.builds: |
| 4738 | if 'project-merge' in job.name: |
| 4739 | job_A = job |
| 4740 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4741 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4742 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4743 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4744 | |
| 4745 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4746 | job_A.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4747 | repo = git.Repo(path) |
| 4748 | repo_messages = [c.message.strip() |
| 4749 | for c in repo.iter_commits(ref_A)] |
| 4750 | repo_messages.reverse() |
| 4751 | correct_messages = [ |
| 4752 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4753 | self.assertEqual(repo_messages, correct_messages) |
| 4754 | |
| 4755 | self.launch_server.release('.*-merge') |
| 4756 | self.waitUntilSettled() |
| 4757 | |
| 4758 | job_B = None |
| 4759 | for job in self.builds: |
| 4760 | if 'project-merge' in job.name: |
| 4761 | job_B = job |
| 4762 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4763 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4764 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4765 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4766 | |
| 4767 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4768 | job_B.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4769 | repo = git.Repo(path) |
| 4770 | repo_messages = [c.message.strip() |
| 4771 | for c in repo.iter_commits(ref_B)] |
| 4772 | repo_messages.reverse() |
| 4773 | correct_messages = [ |
| 4774 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4775 | self.assertEqual(repo_messages, correct_messages) |
| 4776 | |
| 4777 | self.launch_server.release('.*-merge') |
| 4778 | self.waitUntilSettled() |
| 4779 | |
| 4780 | job_C = None |
| 4781 | for job in self.builds: |
| 4782 | if 'project-merge' in job.name: |
| 4783 | job_C = job |
| 4784 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4785 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4786 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4787 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
| 4788 | path = os.path.join( |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 4789 | job_C.jobdir.src_root, "org/project-merge-branches") |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4790 | repo = git.Repo(path) |
| 4791 | repo_messages = [c.message.strip() |
| 4792 | for c in repo.iter_commits(ref_C)] |
| 4793 | |
| 4794 | repo_messages.reverse() |
| 4795 | correct_messages = [ |
| 4796 | 'initial commit', 'add content from fixture', |
| 4797 | 'A-1', 'C-1'] |
| 4798 | # Ensure the right commits are in the history for this ref |
| 4799 | self.assertEqual(repo_messages, correct_messages) |
| 4800 | |
| 4801 | self.launch_server.hold_jobs_in_build = False |
| 4802 | self.launch_server.release() |
| 4803 | self.waitUntilSettled() |