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 logging |
| 19 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 20 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 21 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 22 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 23 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 25 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 26 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 27 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 28 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 29 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 31 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 32 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 34 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 35 | ZuulTestCase, |
| 36 | repack_repo, |
| 37 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 38 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 39 | logging.basicConfig(level=logging.DEBUG, |
| 40 | format='%(asctime)s %(name)-32s ' |
| 41 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 42 | |
| 43 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 44 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 45 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 46 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 47 | def test_jobs_launched(self): |
| 48 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 49 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 50 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 51 | A.addApproval('code-review', 2) |
| 52 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 53 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 54 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(A.data['status'], 'MERGED') |
| 61 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 62 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 63 | 'image1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 64 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 65 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 66 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 67 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 68 | value='1|g') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 70 | kind='ms') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 72 | value='1|c') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 74 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 75 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 76 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 77 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 79 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 80 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 81 | for build in self.builds: |
| 82 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 83 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 84 | def test_initial_pipeline_gauges(self): |
| 85 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 86 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 87 | value='0|g') |
| 88 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 89 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 90 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 91 | def test_job_branch(self): |
| 92 | "Test the correct variant of a job runs on a branch" |
| 93 | self.create_branch('org/project', 'stable') |
| 94 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 95 | A.addApproval('code-review', 2) |
| 96 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 97 | self.waitUntilSettled() |
| 98 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 99 | 'SUCCESS') |
| 100 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 101 | 'SUCCESS') |
| 102 | self.assertEqual(A.data['status'], 'MERGED') |
| 103 | self.assertEqual(A.reported, 2, |
| 104 | "A should report start and success") |
| 105 | self.assertIn('gate', A.messages[1], |
| 106 | "A should transit gate") |
| 107 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 108 | 'image2') |
| 109 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 110 | def test_parallel_changes(self): |
| 111 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 112 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 113 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 114 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 115 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 116 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 117 | A.addApproval('code-review', 2) |
| 118 | B.addApproval('code-review', 2) |
| 119 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 120 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 121 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 122 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 123 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 124 | |
| 125 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 126 | self.assertEqual(len(self.builds), 1) |
| 127 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 128 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 129 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 130 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 131 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 132 | self.assertEqual(len(self.builds), 3) |
| 133 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 134 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 135 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 138 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 139 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 140 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 141 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 142 | self.assertEqual(len(self.builds), 5) |
| 143 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 144 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 145 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 146 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 147 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 148 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 149 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 150 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 152 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 153 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 154 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 158 | self.assertEqual(len(self.builds), 6) |
| 159 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 160 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 163 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 169 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 173 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 174 | self.launch_server.hold_jobs_in_build = False |
| 175 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(len(self.history), 9) |
| 180 | self.assertEqual(A.data['status'], 'MERGED') |
| 181 | self.assertEqual(B.data['status'], 'MERGED') |
| 182 | self.assertEqual(C.data['status'], 'MERGED') |
| 183 | self.assertEqual(A.reported, 2) |
| 184 | self.assertEqual(B.reported, 2) |
| 185 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 186 | |
| 187 | def test_failed_changes(self): |
| 188 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 189 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 190 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 191 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 192 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 193 | A.addApproval('code-review', 2) |
| 194 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 195 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 196 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 197 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 198 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 199 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 200 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 201 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 202 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 203 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 204 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 205 | # A/project-merge is complete |
| 206 | self.assertBuilds([ |
| 207 | dict(name='project-test1', changes='1,1'), |
| 208 | dict(name='project-test2', changes='1,1'), |
| 209 | dict(name='project-merge', changes='1,1 2,1'), |
| 210 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 211 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 212 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 213 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 214 | # A/project-merge is complete |
| 215 | # B/project-merge is complete |
| 216 | self.assertBuilds([ |
| 217 | dict(name='project-test1', changes='1,1'), |
| 218 | dict(name='project-test2', changes='1,1'), |
| 219 | dict(name='project-test1', changes='1,1 2,1'), |
| 220 | dict(name='project-test2', changes='1,1 2,1'), |
| 221 | ]) |
| 222 | |
| 223 | # Release project-test1 for A which will fail. This will |
| 224 | # abort both running B jobs and relaunch project-merge for B. |
| 225 | self.builds[0].release() |
| 226 | self.waitUntilSettled() |
| 227 | |
| 228 | self.orderedRelease() |
| 229 | self.assertHistory([ |
| 230 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 231 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 232 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 233 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 234 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 235 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 236 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 237 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 238 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 239 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 240 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 241 | self.assertEqual(A.data['status'], 'NEW') |
| 242 | self.assertEqual(B.data['status'], 'MERGED') |
| 243 | self.assertEqual(A.reported, 2) |
| 244 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 245 | |
| 246 | def test_independent_queues(self): |
| 247 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 248 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 249 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 251 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 252 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 253 | A.addApproval('code-review', 2) |
| 254 | B.addApproval('code-review', 2) |
| 255 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 256 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 257 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 258 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 259 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 260 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 261 | self.waitUntilSettled() |
| 262 | |
| 263 | # 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] | 264 | self.assertBuilds([ |
| 265 | dict(name='project-merge', changes='1,1'), |
| 266 | dict(name='project-merge', changes='2,1'), |
| 267 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 268 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 269 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 270 | self.builds[0].release() |
| 271 | self.waitUntilSettled() |
| 272 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 273 | self.waitUntilSettled() |
| 274 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 275 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 276 | self.waitUntilSettled() |
| 277 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 278 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 279 | self.assertBuilds([ |
| 280 | dict(name='project-test1', changes='1,1'), |
| 281 | dict(name='project-test2', changes='1,1'), |
| 282 | dict(name='project-test1', changes='2,1'), |
| 283 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 284 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 285 | dict(name='project-test1', changes='2,1 3,1'), |
| 286 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 287 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 288 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 289 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 290 | self.orderedRelease() |
| 291 | self.assertHistory([ |
| 292 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 293 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 294 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 295 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 296 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 298 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 299 | dict( |
| 300 | name='project1-project2-integration', |
| 301 | result='SUCCESS', |
| 302 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 303 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 304 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 305 | dict(name='project1-project2-integration', |
| 306 | result='SUCCESS', |
| 307 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 308 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 309 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 310 | self.assertEqual(A.data['status'], 'MERGED') |
| 311 | self.assertEqual(B.data['status'], 'MERGED') |
| 312 | self.assertEqual(C.data['status'], 'MERGED') |
| 313 | self.assertEqual(A.reported, 2) |
| 314 | self.assertEqual(B.reported, 2) |
| 315 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 316 | |
| 317 | def test_failed_change_at_head(self): |
| 318 | "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] | 319 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 320 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 321 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 322 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 323 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 324 | A.addApproval('code-review', 2) |
| 325 | B.addApproval('code-review', 2) |
| 326 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 327 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 328 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 329 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 330 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 331 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 332 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 333 | |
| 334 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 335 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 336 | self.assertBuilds([ |
| 337 | dict(name='project-merge', changes='1,1'), |
| 338 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 339 | |
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() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 342 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 344 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 345 | self.waitUntilSettled() |
| 346 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 347 | self.assertBuilds([ |
| 348 | dict(name='project-test1', changes='1,1'), |
| 349 | dict(name='project-test2', changes='1,1'), |
| 350 | dict(name='project-test1', changes='1,1 2,1'), |
| 351 | dict(name='project-test2', changes='1,1 2,1'), |
| 352 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 353 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 354 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 355 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 356 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 357 | self.waitUntilSettled() |
| 358 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 359 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 360 | self.assertBuilds([ |
| 361 | dict(name='project-test2', changes='1,1'), |
| 362 | dict(name='project-merge', changes='2,1'), |
| 363 | ]) |
| 364 | # Unordered history comparison because the aborts can finish |
| 365 | # in any order. |
| 366 | self.assertHistory([ |
| 367 | dict(name='project-merge', result='SUCCESS', |
| 368 | changes='1,1'), |
| 369 | dict(name='project-merge', result='SUCCESS', |
| 370 | changes='1,1 2,1'), |
| 371 | dict(name='project-merge', result='SUCCESS', |
| 372 | changes='1,1 2,1 3,1'), |
| 373 | dict(name='project-test1', result='FAILURE', |
| 374 | changes='1,1'), |
| 375 | dict(name='project-test1', result='ABORTED', |
| 376 | changes='1,1 2,1'), |
| 377 | dict(name='project-test2', result='ABORTED', |
| 378 | changes='1,1 2,1'), |
| 379 | dict(name='project-test1', result='ABORTED', |
| 380 | changes='1,1 2,1 3,1'), |
| 381 | dict(name='project-test2', result='ABORTED', |
| 382 | changes='1,1 2,1 3,1'), |
| 383 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 384 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 385 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 387 | self.launch_server.release('.*-merge') |
| 388 | self.waitUntilSettled() |
| 389 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 390 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 391 | self.assertBuilds([]) |
| 392 | self.assertHistory([ |
| 393 | dict(name='project-merge', result='SUCCESS', |
| 394 | changes='1,1'), |
| 395 | dict(name='project-merge', result='SUCCESS', |
| 396 | changes='1,1 2,1'), |
| 397 | dict(name='project-merge', result='SUCCESS', |
| 398 | changes='1,1 2,1 3,1'), |
| 399 | dict(name='project-test1', result='FAILURE', |
| 400 | changes='1,1'), |
| 401 | dict(name='project-test1', result='ABORTED', |
| 402 | changes='1,1 2,1'), |
| 403 | dict(name='project-test2', result='ABORTED', |
| 404 | changes='1,1 2,1'), |
| 405 | dict(name='project-test1', result='ABORTED', |
| 406 | changes='1,1 2,1 3,1'), |
| 407 | dict(name='project-test2', result='ABORTED', |
| 408 | changes='1,1 2,1 3,1'), |
| 409 | dict(name='project-merge', result='SUCCESS', |
| 410 | changes='2,1'), |
| 411 | dict(name='project-merge', result='SUCCESS', |
| 412 | changes='2,1 3,1'), |
| 413 | dict(name='project-test2', result='SUCCESS', |
| 414 | changes='1,1'), |
| 415 | dict(name='project-test1', result='SUCCESS', |
| 416 | changes='2,1'), |
| 417 | dict(name='project-test2', result='SUCCESS', |
| 418 | changes='2,1'), |
| 419 | dict(name='project-test1', result='SUCCESS', |
| 420 | changes='2,1 3,1'), |
| 421 | dict(name='project-test2', result='SUCCESS', |
| 422 | changes='2,1 3,1'), |
| 423 | ], ordered=False) |
| 424 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 425 | self.assertEqual(A.data['status'], 'NEW') |
| 426 | self.assertEqual(B.data['status'], 'MERGED') |
| 427 | self.assertEqual(C.data['status'], 'MERGED') |
| 428 | self.assertEqual(A.reported, 2) |
| 429 | self.assertEqual(B.reported, 2) |
| 430 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 431 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 432 | def test_failed_change_in_middle(self): |
| 433 | "Test a failed change in the middle of the queue" |
| 434 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 435 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 436 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 437 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 438 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 439 | A.addApproval('code-review', 2) |
| 440 | B.addApproval('code-review', 2) |
| 441 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 442 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 443 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 444 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 445 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 446 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 447 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 448 | |
| 449 | self.waitUntilSettled() |
| 450 | |
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() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 453 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 454 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 455 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 456 | self.waitUntilSettled() |
| 457 | |
| 458 | self.assertEqual(len(self.builds), 6) |
| 459 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 460 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 461 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 462 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 463 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 464 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 465 | |
| 466 | self.release(self.builds[2]) |
| 467 | self.waitUntilSettled() |
| 468 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 469 | # project-test1 and project-test2 for A |
| 470 | # project-test2 for B |
| 471 | # project-merge for C (without B) |
| 472 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 473 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 474 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 475 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 476 | self.waitUntilSettled() |
| 477 | |
| 478 | # project-test1 and project-test2 for A |
| 479 | # project-test2 for B |
| 480 | # project-test1 and project-test2 for C |
| 481 | self.assertEqual(len(self.builds), 5) |
| 482 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 483 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 484 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 485 | builds = items[0].current_build_set.getBuilds() |
| 486 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 487 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 488 | builds = items[1].current_build_set.getBuilds() |
| 489 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 490 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 491 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 492 | builds = items[2].current_build_set.getBuilds() |
| 493 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 494 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 495 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 496 | self.launch_server.hold_jobs_in_build = False |
| 497 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 498 | self.waitUntilSettled() |
| 499 | |
| 500 | self.assertEqual(len(self.builds), 0) |
| 501 | self.assertEqual(len(self.history), 12) |
| 502 | self.assertEqual(A.data['status'], 'MERGED') |
| 503 | self.assertEqual(B.data['status'], 'NEW') |
| 504 | self.assertEqual(C.data['status'], 'MERGED') |
| 505 | self.assertEqual(A.reported, 2) |
| 506 | self.assertEqual(B.reported, 2) |
| 507 | self.assertEqual(C.reported, 2) |
| 508 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 509 | def test_failed_change_at_head_with_queue(self): |
| 510 | "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] | 511 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 512 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 513 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 514 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 515 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 516 | A.addApproval('code-review', 2) |
| 517 | B.addApproval('code-review', 2) |
| 518 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 519 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 520 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 521 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 522 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 523 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 524 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 525 | |
| 526 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 527 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 528 | self.assertEqual(len(self.builds), 0) |
| 529 | self.assertEqual(len(queue), 1) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 530 | self.assertEqual(queue[0].name, 'launcher:launch') |
| 531 | job_args = json.loads(queue[0].arguments) |
| 532 | self.assertEqual(job_args['job'], 'project-merge') |
| 533 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 534 | |
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 | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 537 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 538 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 539 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 540 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 541 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 542 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 543 | self.assertEqual(len(self.builds), 0) |
| 544 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 545 | |
| 546 | self.assertEqual( |
| 547 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 548 | self.assertEqual( |
| 549 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 550 | self.assertEqual( |
| 551 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 552 | self.assertEqual( |
| 553 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 554 | self.assertEqual( |
| 555 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 556 | self.assertEqual( |
| 557 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 558 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 559 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 560 | self.waitUntilSettled() |
| 561 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 562 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 563 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 564 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 565 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 567 | self.gearman_server.hold_jobs_in_queue = False |
| 568 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 569 | self.waitUntilSettled() |
| 570 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 571 | self.assertEqual(len(self.builds), 0) |
| 572 | self.assertEqual(len(self.history), 11) |
| 573 | self.assertEqual(A.data['status'], 'NEW') |
| 574 | self.assertEqual(B.data['status'], 'MERGED') |
| 575 | self.assertEqual(C.data['status'], 'MERGED') |
| 576 | self.assertEqual(A.reported, 2) |
| 577 | self.assertEqual(B.reported, 2) |
| 578 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 579 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 580 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 581 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 582 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 583 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 584 | A.addApproval('code-review', 2) |
| 585 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 586 | self.waitUntilSettled() |
| 587 | time.sleep(2) |
| 588 | |
| 589 | data = json.loads(self.sched.formatStatusJSON()) |
| 590 | found_job = None |
| 591 | for pipeline in data['pipelines']: |
| 592 | if pipeline['name'] != 'gate': |
| 593 | continue |
| 594 | for queue in pipeline['change_queues']: |
| 595 | for head in queue['heads']: |
| 596 | for item in head: |
| 597 | for job in item['jobs']: |
| 598 | if job['name'] == 'project-merge': |
| 599 | found_job = job |
| 600 | break |
| 601 | |
| 602 | self.assertIsNotNone(found_job) |
| 603 | if iteration == 1: |
| 604 | self.assertIsNotNone(found_job['estimated_time']) |
| 605 | self.assertIsNone(found_job['remaining_time']) |
| 606 | else: |
| 607 | self.assertIsNotNone(found_job['estimated_time']) |
| 608 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 609 | self.assertIsNotNone(found_job['remaining_time']) |
| 610 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 611 | self.launch_server.hold_jobs_in_build = False |
| 612 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 613 | self.waitUntilSettled() |
| 614 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 615 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 616 | def test_time_database(self): |
| 617 | "Test the time database" |
| 618 | |
| 619 | self._test_time_database(1) |
| 620 | self._test_time_database(2) |
| 621 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 622 | def test_two_failed_changes_at_head(self): |
| 623 | "Test that changes are reparented correctly if 2 fail at head" |
| 624 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 625 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 626 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 627 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 628 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 629 | A.addApproval('code-review', 2) |
| 630 | B.addApproval('code-review', 2) |
| 631 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 632 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 633 | self.launch_server.failJob('project-test1', A) |
| 634 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 635 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 636 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 637 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 638 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 639 | self.waitUntilSettled() |
| 640 | |
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() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 643 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 645 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 646 | self.waitUntilSettled() |
| 647 | |
| 648 | self.assertEqual(len(self.builds), 6) |
| 649 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 650 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 651 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 652 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 653 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 654 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 655 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 656 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 657 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 658 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 659 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 660 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 661 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 662 | |
| 663 | # Fail change B first |
| 664 | self.release(self.builds[2]) |
| 665 | self.waitUntilSettled() |
| 666 | |
| 667 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 668 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 669 | self.waitUntilSettled() |
| 670 | |
| 671 | self.assertEqual(len(self.builds), 5) |
| 672 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 673 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 674 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 675 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 676 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 677 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 678 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 679 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 680 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 681 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 682 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 683 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 684 | |
| 685 | # Finish running all passing jobs for change A |
| 686 | self.release(self.builds[1]) |
| 687 | self.waitUntilSettled() |
| 688 | # Fail and report change A |
| 689 | self.release(self.builds[0]) |
| 690 | self.waitUntilSettled() |
| 691 | |
| 692 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 693 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 694 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 695 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 696 | self.waitUntilSettled() |
| 697 | |
| 698 | self.assertEqual(len(self.builds), 4) |
| 699 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 700 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 701 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 702 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 703 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 704 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 705 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 706 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 708 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 709 | # After A failed and B and C restarted, B should be back in |
| 710 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 711 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 712 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 713 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 714 | self.launch_server.hold_jobs_in_build = False |
| 715 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 716 | self.waitUntilSettled() |
| 717 | |
| 718 | self.assertEqual(len(self.builds), 0) |
| 719 | self.assertEqual(len(self.history), 21) |
| 720 | self.assertEqual(A.data['status'], 'NEW') |
| 721 | self.assertEqual(B.data['status'], 'NEW') |
| 722 | self.assertEqual(C.data['status'], 'MERGED') |
| 723 | self.assertEqual(A.reported, 2) |
| 724 | self.assertEqual(B.reported, 2) |
| 725 | self.assertEqual(C.reported, 2) |
| 726 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 727 | def test_patch_order(self): |
| 728 | "Test that dependent patches are tested in the right order" |
| 729 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 730 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 731 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 732 | A.addApproval('code-review', 2) |
| 733 | B.addApproval('code-review', 2) |
| 734 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 735 | |
| 736 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 737 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 738 | M2.setMerged() |
| 739 | M1.setMerged() |
| 740 | |
| 741 | # C -> B -> A -> M1 -> M2 |
| 742 | # M2 is here to make sure it is never queried. If it is, it |
| 743 | # means zuul is walking down the entire history of merged |
| 744 | # changes. |
| 745 | |
| 746 | C.setDependsOn(B, 1) |
| 747 | B.setDependsOn(A, 1) |
| 748 | A.setDependsOn(M1, 1) |
| 749 | M1.setDependsOn(M2, 1) |
| 750 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 751 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 752 | |
| 753 | self.waitUntilSettled() |
| 754 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 755 | self.assertEqual(A.data['status'], 'NEW') |
| 756 | self.assertEqual(B.data['status'], 'NEW') |
| 757 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 758 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 759 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 760 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 761 | |
| 762 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 763 | self.assertEqual(M2.queried, 0) |
| 764 | self.assertEqual(A.data['status'], 'MERGED') |
| 765 | self.assertEqual(B.data['status'], 'MERGED') |
| 766 | self.assertEqual(C.data['status'], 'MERGED') |
| 767 | self.assertEqual(A.reported, 2) |
| 768 | self.assertEqual(B.reported, 2) |
| 769 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 770 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 771 | def test_needed_changes_enqueue(self): |
| 772 | "Test that a needed change is enqueued ahead" |
| 773 | # A Given a git tree like this, if we enqueue |
| 774 | # / \ change C, we should walk up and down the tree |
| 775 | # B G and enqueue changes in the order ABCDEFG. |
| 776 | # /|\ This is also the order that you would get if |
| 777 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 778 | # / the ordering is stable across re-enqueue events. |
| 779 | # D |
| 780 | |
| 781 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 782 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 783 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 784 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 785 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 786 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 787 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 788 | B.setDependsOn(A, 1) |
| 789 | C.setDependsOn(B, 1) |
| 790 | D.setDependsOn(C, 1) |
| 791 | E.setDependsOn(B, 1) |
| 792 | F.setDependsOn(B, 1) |
| 793 | G.setDependsOn(A, 1) |
| 794 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 795 | A.addApproval('code-review', 2) |
| 796 | B.addApproval('code-review', 2) |
| 797 | C.addApproval('code-review', 2) |
| 798 | D.addApproval('code-review', 2) |
| 799 | E.addApproval('code-review', 2) |
| 800 | F.addApproval('code-review', 2) |
| 801 | G.addApproval('code-review', 2) |
| 802 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 803 | |
| 804 | self.waitUntilSettled() |
| 805 | |
| 806 | self.assertEqual(A.data['status'], 'NEW') |
| 807 | self.assertEqual(B.data['status'], 'NEW') |
| 808 | self.assertEqual(C.data['status'], 'NEW') |
| 809 | self.assertEqual(D.data['status'], 'NEW') |
| 810 | self.assertEqual(E.data['status'], 'NEW') |
| 811 | self.assertEqual(F.data['status'], 'NEW') |
| 812 | self.assertEqual(G.data['status'], 'NEW') |
| 813 | |
| 814 | # We're about to add approvals to changes without adding the |
| 815 | # triggering events to Zuul, so that we can be sure that it is |
| 816 | # enqueing the changes based on dependencies, not because of |
| 817 | # triggering events. Since it will have the changes cached |
| 818 | # already (without approvals), we need to clear the cache |
| 819 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 820 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 821 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 822 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 823 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 824 | A.addApproval('approved', 1) |
| 825 | B.addApproval('approved', 1) |
| 826 | D.addApproval('approved', 1) |
| 827 | E.addApproval('approved', 1) |
| 828 | F.addApproval('approved', 1) |
| 829 | G.addApproval('approved', 1) |
| 830 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 831 | |
| 832 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 833 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 834 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 835 | self.launch_server.hold_jobs_in_build = False |
| 836 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 837 | self.waitUntilSettled() |
| 838 | |
| 839 | self.assertEqual(A.data['status'], 'MERGED') |
| 840 | self.assertEqual(B.data['status'], 'MERGED') |
| 841 | self.assertEqual(C.data['status'], 'MERGED') |
| 842 | self.assertEqual(D.data['status'], 'MERGED') |
| 843 | self.assertEqual(E.data['status'], 'MERGED') |
| 844 | self.assertEqual(F.data['status'], 'MERGED') |
| 845 | self.assertEqual(G.data['status'], 'MERGED') |
| 846 | self.assertEqual(A.reported, 2) |
| 847 | self.assertEqual(B.reported, 2) |
| 848 | self.assertEqual(C.reported, 2) |
| 849 | self.assertEqual(D.reported, 2) |
| 850 | self.assertEqual(E.reported, 2) |
| 851 | self.assertEqual(F.reported, 2) |
| 852 | self.assertEqual(G.reported, 2) |
| 853 | self.assertEqual(self.history[6].changes, |
| 854 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 855 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 856 | def test_source_cache(self): |
| 857 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 858 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 859 | |
| 860 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 861 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 862 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 863 | A.addApproval('code-review', 2) |
| 864 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 865 | |
| 866 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 867 | M1.setMerged() |
| 868 | |
| 869 | B.setDependsOn(A, 1) |
| 870 | A.setDependsOn(M1, 1) |
| 871 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 872 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 873 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 874 | |
| 875 | self.waitUntilSettled() |
| 876 | |
| 877 | for build in self.builds: |
| 878 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 879 | build.release() |
| 880 | self.waitUntilSettled() |
| 881 | for build in self.builds: |
| 882 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 883 | build.release() |
| 884 | self.waitUntilSettled() |
| 885 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 886 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 887 | self.waitUntilSettled() |
| 888 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 889 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 890 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 891 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 892 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 893 | self.launch_server.hold_jobs_in_build = False |
| 894 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 895 | self.waitUntilSettled() |
| 896 | |
| 897 | self.assertEqual(A.data['status'], 'MERGED') |
| 898 | self.assertEqual(B.data['status'], 'MERGED') |
| 899 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 900 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 901 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 902 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 903 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 904 | # TODO: move to test_gerrit (this is a unit test!) |
| 905 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 906 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 907 | source = tenant.layout.pipelines['gate'].source |
| 908 | |
| 909 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 910 | # it easier for users to create events for testing. |
| 911 | event = zuul.model.TriggerEvent() |
| 912 | event.trigger_name = 'gerrit' |
| 913 | event.change_number = '1' |
| 914 | event.patch_number = '2' |
| 915 | |
| 916 | a = source.getChange(event) |
| 917 | mgr = tenant.layout.pipelines['gate'].manager |
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('code-review', 2) |
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.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 923 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 924 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 925 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 926 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 927 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 928 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 929 | def test_build_configuration_conflict(self): |
| 930 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 931 | |
| 932 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 933 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 934 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 935 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 936 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 937 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 938 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 939 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 940 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 941 | A.addApproval('code-review', 2) |
| 942 | B.addApproval('code-review', 2) |
| 943 | C.addApproval('code-review', 2) |
| 944 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 945 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 946 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 947 | self.waitUntilSettled() |
| 948 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 949 | self.assertEqual(A.reported, 1) |
| 950 | self.assertEqual(B.reported, 1) |
| 951 | self.assertEqual(C.reported, 1) |
| 952 | |
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 | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 955 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 957 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 958 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 959 | |
| 960 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 961 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 962 | self.gearman_server.hold_jobs_in_queue = False |
| 963 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 964 | self.waitUntilSettled() |
| 965 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 966 | self.assertEqual(A.data['status'], 'MERGED') |
| 967 | self.assertEqual(B.data['status'], 'NEW') |
| 968 | self.assertEqual(C.data['status'], 'MERGED') |
| 969 | self.assertEqual(A.reported, 2) |
| 970 | self.assertEqual(B.reported, 2) |
| 971 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 972 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 973 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 974 | def test_post(self): |
| 975 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 976 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 977 | e = { |
| 978 | "type": "ref-updated", |
| 979 | "submitter": { |
| 980 | "name": "User Name", |
| 981 | }, |
| 982 | "refUpdate": { |
| 983 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 984 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 985 | "refName": "master", |
| 986 | "project": "org/project", |
| 987 | } |
| 988 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 989 | self.fake_gerrit.addEvent(e) |
| 990 | self.waitUntilSettled() |
| 991 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 992 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 993 | self.assertEqual(len(self.history), 1) |
| 994 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 995 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 996 | def test_post_ignore_deletes(self): |
| 997 | "Test that deleting refs does not trigger post jobs" |
| 998 | |
| 999 | e = { |
| 1000 | "type": "ref-updated", |
| 1001 | "submitter": { |
| 1002 | "name": "User Name", |
| 1003 | }, |
| 1004 | "refUpdate": { |
| 1005 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1006 | "newRev": "0000000000000000000000000000000000000000", |
| 1007 | "refName": "master", |
| 1008 | "project": "org/project", |
| 1009 | } |
| 1010 | } |
| 1011 | self.fake_gerrit.addEvent(e) |
| 1012 | self.waitUntilSettled() |
| 1013 | |
| 1014 | job_names = [x.name for x in self.history] |
| 1015 | self.assertEqual(len(self.history), 0) |
| 1016 | self.assertNotIn('project-post', job_names) |
| 1017 | |
| 1018 | def test_post_ignore_deletes_negative(self): |
| 1019 | "Test that deleting refs does trigger post jobs" |
| 1020 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1021 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1022 | self.sched.reconfigure(self.config) |
| 1023 | |
| 1024 | e = { |
| 1025 | "type": "ref-updated", |
| 1026 | "submitter": { |
| 1027 | "name": "User Name", |
| 1028 | }, |
| 1029 | "refUpdate": { |
| 1030 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1031 | "newRev": "0000000000000000000000000000000000000000", |
| 1032 | "refName": "master", |
| 1033 | "project": "org/project", |
| 1034 | } |
| 1035 | } |
| 1036 | self.fake_gerrit.addEvent(e) |
| 1037 | self.waitUntilSettled() |
| 1038 | |
| 1039 | job_names = [x.name for x in self.history] |
| 1040 | self.assertEqual(len(self.history), 1) |
| 1041 | self.assertIn('project-post', job_names) |
| 1042 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1043 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1044 | def test_build_configuration_branch(self): |
| 1045 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1046 | |
| 1047 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1048 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1049 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1050 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1051 | A.addApproval('code-review', 2) |
| 1052 | B.addApproval('code-review', 2) |
| 1053 | C.addApproval('code-review', 2) |
| 1054 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1055 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1056 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1057 | self.waitUntilSettled() |
| 1058 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1059 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1060 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1061 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1062 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1063 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1064 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1065 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1066 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1067 | self.gearman_server.hold_jobs_in_queue = False |
| 1068 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1069 | self.waitUntilSettled() |
| 1070 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1071 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1072 | repo = git.Repo(path) |
| 1073 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1074 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1075 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1076 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1077 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1078 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1079 | def test_build_configuration_branch_interaction(self): |
| 1080 | "Test that switching between branches works" |
| 1081 | self.test_build_configuration() |
| 1082 | self.test_build_configuration_branch() |
| 1083 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1084 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1085 | repo = git.Repo(path) |
| 1086 | repo.heads.master.commit = repo.commit('init') |
| 1087 | self.test_build_configuration() |
| 1088 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1089 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1090 | def test_build_configuration_multi_branch(self): |
| 1091 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1092 | |
| 1093 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1094 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1095 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1096 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1097 | A.addApproval('code-review', 2) |
| 1098 | B.addApproval('code-review', 2) |
| 1099 | C.addApproval('code-review', 2) |
| 1100 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1101 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1102 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1103 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1104 | queue = self.gearman_server.getQueue() |
| 1105 | job_A = None |
| 1106 | for job in queue: |
| 1107 | if 'project-merge' in job.name: |
| 1108 | job_A = job |
| 1109 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1110 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1111 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1112 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1113 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1114 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1115 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1116 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1117 | job_B = None |
| 1118 | for job in queue: |
| 1119 | if 'project-merge' in job.name: |
| 1120 | job_B = job |
| 1121 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1122 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1123 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1124 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1125 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1126 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1127 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1128 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1129 | for job in queue: |
| 1130 | if 'project-merge' in job.name: |
| 1131 | job_C = job |
| 1132 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1133 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1134 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1135 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1136 | self.gearman_server.hold_jobs_in_queue = False |
| 1137 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1138 | self.waitUntilSettled() |
| 1139 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1140 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1141 | repo = git.Repo(path) |
| 1142 | |
| 1143 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1144 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1145 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1146 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1147 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1148 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1149 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1150 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 1151 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1152 | |
| 1153 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1154 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1155 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1156 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1157 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1158 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1159 | self.assertEqual(repo_shas[0], commit_B) |
| 1160 | |
| 1161 | repo_messages = [c.message.strip() |
| 1162 | for c in repo.iter_commits(ref_A)] |
| 1163 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1164 | repo_messages.reverse() |
| 1165 | correct_messages = ['initial commit', 'A-1'] |
| 1166 | self.assertEqual(repo_messages, correct_messages) |
| 1167 | self.assertEqual(repo_shas[0], commit_A) |
| 1168 | |
| 1169 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1170 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1171 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1172 | def test_dependent_changes_dequeue(self): |
| 1173 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1174 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1175 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1176 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1177 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1178 | A.addApproval('code-review', 2) |
| 1179 | B.addApproval('code-review', 2) |
| 1180 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1181 | |
| 1182 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1183 | M1.setMerged() |
| 1184 | |
| 1185 | # C -> B -> A -> M1 |
| 1186 | |
| 1187 | C.setDependsOn(B, 1) |
| 1188 | B.setDependsOn(A, 1) |
| 1189 | A.setDependsOn(M1, 1) |
| 1190 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1191 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1192 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1193 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1194 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1195 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1196 | |
| 1197 | self.waitUntilSettled() |
| 1198 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1199 | self.assertEqual(A.data['status'], 'NEW') |
| 1200 | self.assertEqual(A.reported, 2) |
| 1201 | self.assertEqual(B.data['status'], 'NEW') |
| 1202 | self.assertEqual(B.reported, 2) |
| 1203 | self.assertEqual(C.data['status'], 'NEW') |
| 1204 | self.assertEqual(C.reported, 2) |
| 1205 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1206 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1207 | def test_failing_dependent_changes(self): |
| 1208 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1209 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1211 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1212 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1213 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1214 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1215 | A.addApproval('code-review', 2) |
| 1216 | B.addApproval('code-review', 2) |
| 1217 | C.addApproval('code-review', 2) |
| 1218 | D.addApproval('code-review', 2) |
| 1219 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1220 | |
| 1221 | # E, D -> C -> B, A |
| 1222 | |
| 1223 | D.setDependsOn(C, 1) |
| 1224 | C.setDependsOn(B, 1) |
| 1225 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1226 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1227 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1228 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1229 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1230 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1231 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1232 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1233 | |
| 1234 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1235 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1236 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1237 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1238 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1239 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1240 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1241 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1242 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1243 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1244 | self.waitUntilSettled() |
| 1245 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1246 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1247 | for build in self.builds: |
| 1248 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1249 | build.release() |
| 1250 | self.waitUntilSettled() |
| 1251 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1252 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1253 | self.waitUntilSettled() |
| 1254 | |
| 1255 | self.assertEqual(A.data['status'], 'MERGED') |
| 1256 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1257 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1258 | self.assertEqual(B.data['status'], 'NEW') |
| 1259 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1260 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1261 | self.assertEqual(C.data['status'], 'NEW') |
| 1262 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1263 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1264 | self.assertEqual(D.data['status'], 'NEW') |
| 1265 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1266 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1267 | self.assertEqual(E.data['status'], 'MERGED') |
| 1268 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1269 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1270 | self.assertEqual(len(self.history), 18) |
| 1271 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1272 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1273 | "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] | 1274 | # If it's dequeued more than once, we should see extra |
| 1275 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1276 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1277 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1278 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1279 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1280 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1281 | A.addApproval('code-review', 2) |
| 1282 | B.addApproval('code-review', 2) |
| 1283 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1284 | |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1285 | self.launch_server.failJob('project-test1', A) |
| 1286 | self.launch_server.failJob('project-test2', A) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1287 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1288 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1289 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1290 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1291 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1292 | |
| 1293 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1294 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1295 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1296 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1297 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1298 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1299 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1300 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1301 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1302 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1303 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1304 | self.waitUntilSettled() |
| 1305 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1306 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1307 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1308 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1309 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1310 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1311 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1312 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1313 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1314 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1315 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1316 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1317 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1318 | self.waitUntilSettled() |
| 1319 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1320 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1321 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1322 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1323 | self.launch_server.hold_jobs_in_build = False |
| 1324 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1325 | self.waitUntilSettled() |
| 1326 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1327 | self.assertEqual(len(self.builds), 0) |
| 1328 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1329 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1330 | self.assertEqual(A.data['status'], 'NEW') |
| 1331 | self.assertEqual(B.data['status'], 'MERGED') |
| 1332 | self.assertEqual(C.data['status'], 'MERGED') |
| 1333 | self.assertEqual(A.reported, 2) |
| 1334 | self.assertEqual(B.reported, 2) |
| 1335 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1336 | |
| 1337 | def test_nonvoting_job(self): |
| 1338 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1339 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1340 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1341 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1342 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1343 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1344 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1345 | |
| 1346 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1347 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1348 | self.assertEqual(A.data['status'], 'MERGED') |
| 1349 | self.assertEqual(A.reported, 2) |
| 1350 | self.assertEqual( |
| 1351 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1352 | 'SUCCESS') |
| 1353 | self.assertEqual( |
| 1354 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1355 | 'SUCCESS') |
| 1356 | self.assertEqual( |
| 1357 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1358 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1359 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1360 | for build in self.builds: |
| 1361 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1362 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1363 | def test_check_queue_success(self): |
| 1364 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1365 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1367 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1368 | |
| 1369 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1370 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1371 | self.assertEqual(A.data['status'], 'NEW') |
| 1372 | self.assertEqual(A.reported, 1) |
| 1373 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1374 | 'SUCCESS') |
| 1375 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1376 | 'SUCCESS') |
| 1377 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1378 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1379 | |
| 1380 | def test_check_queue_failure(self): |
| 1381 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1382 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1383 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1384 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1385 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1386 | |
| 1387 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1388 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1389 | self.assertEqual(A.data['status'], 'NEW') |
| 1390 | self.assertEqual(A.reported, 1) |
| 1391 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1392 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1393 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1394 | 'SUCCESS') |
| 1395 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1396 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1397 | |
| 1398 | def test_dependent_behind_dequeue(self): |
| 1399 | "test that dependent changes behind dequeued changes work" |
| 1400 | # This complicated test is a reproduction of a real life bug |
| 1401 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1402 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1403 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1404 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1405 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1406 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1407 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1408 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1409 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1410 | D.setDependsOn(C, 1) |
| 1411 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1412 | A.addApproval('code-review', 2) |
| 1413 | B.addApproval('code-review', 2) |
| 1414 | C.addApproval('code-review', 2) |
| 1415 | D.addApproval('code-review', 2) |
| 1416 | E.addApproval('code-review', 2) |
| 1417 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1418 | |
| 1419 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1420 | |
| 1421 | # Change object re-use in the gerrit trigger is hidden if |
| 1422 | # changes are added in quick succession; waiting makes it more |
| 1423 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1424 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1425 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1426 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1427 | self.waitUntilSettled() |
| 1428 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1429 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1430 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1431 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1432 | self.waitUntilSettled() |
| 1433 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1434 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1435 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1436 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1437 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1438 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1439 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1440 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1441 | self.waitUntilSettled() |
| 1442 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1443 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1444 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1445 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1446 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1447 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1448 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1449 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1450 | self.waitUntilSettled() |
| 1451 | |
| 1452 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1453 | |
| 1454 | # Grab pointers to the jobs we want to release before |
| 1455 | # releasing any, because list indexes may change as |
| 1456 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1457 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1458 | a.release() |
| 1459 | b.release() |
| 1460 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1461 | self.waitUntilSettled() |
| 1462 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1463 | self.launch_server.hold_jobs_in_build = False |
| 1464 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1465 | self.waitUntilSettled() |
| 1466 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1467 | self.assertEqual(A.data['status'], 'NEW') |
| 1468 | self.assertEqual(B.data['status'], 'MERGED') |
| 1469 | self.assertEqual(C.data['status'], 'MERGED') |
| 1470 | self.assertEqual(D.data['status'], 'MERGED') |
| 1471 | self.assertEqual(E.data['status'], 'MERGED') |
| 1472 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1473 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1474 | self.assertEqual(A.reported, 2) |
| 1475 | self.assertEqual(B.reported, 2) |
| 1476 | self.assertEqual(C.reported, 2) |
| 1477 | self.assertEqual(D.reported, 2) |
| 1478 | self.assertEqual(E.reported, 2) |
| 1479 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1480 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1481 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1482 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1483 | |
| 1484 | def test_merger_repack(self): |
| 1485 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1486 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1487 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1488 | A.addApproval('code-review', 2) |
| 1489 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1490 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1491 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1492 | 'SUCCESS') |
| 1493 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1494 | 'SUCCESS') |
| 1495 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1496 | 'SUCCESS') |
| 1497 | self.assertEqual(A.data['status'], 'MERGED') |
| 1498 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1499 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1500 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1501 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1502 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1503 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1504 | |
| 1505 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1506 | A.addApproval('code-review', 2) |
| 1507 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1508 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1509 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1510 | 'SUCCESS') |
| 1511 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1512 | 'SUCCESS') |
| 1513 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1514 | 'SUCCESS') |
| 1515 | self.assertEqual(A.data['status'], 'MERGED') |
| 1516 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1517 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1518 | def test_merger_repack_large_change(self): |
| 1519 | "Test that the merger works with large changes after a repack" |
| 1520 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1521 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1522 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1523 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1524 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1525 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1526 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1527 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1528 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1529 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1530 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1531 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1532 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1533 | A.addApproval('code-review', 2) |
| 1534 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1535 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1536 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1537 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1538 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1539 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1540 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1541 | 'SUCCESS') |
| 1542 | self.assertEqual(A.data['status'], 'MERGED') |
| 1543 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1544 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1545 | def test_new_patchset_dequeues_old(self): |
| 1546 | "Test that a new patchset causes the old to be dequeued" |
| 1547 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1548 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1549 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1550 | M.setMerged() |
| 1551 | |
| 1552 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1553 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1554 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1555 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1556 | A.addApproval('code-review', 2) |
| 1557 | B.addApproval('code-review', 2) |
| 1558 | C.addApproval('code-review', 2) |
| 1559 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1560 | |
| 1561 | C.setDependsOn(B, 1) |
| 1562 | B.setDependsOn(A, 1) |
| 1563 | A.setDependsOn(M, 1) |
| 1564 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1565 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1566 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1567 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1568 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1569 | self.waitUntilSettled() |
| 1570 | |
| 1571 | B.addPatchset() |
| 1572 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1573 | self.waitUntilSettled() |
| 1574 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1575 | self.launch_server.hold_jobs_in_build = False |
| 1576 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1577 | self.waitUntilSettled() |
| 1578 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1579 | self.assertEqual(A.data['status'], 'MERGED') |
| 1580 | self.assertEqual(A.reported, 2) |
| 1581 | self.assertEqual(B.data['status'], 'NEW') |
| 1582 | self.assertEqual(B.reported, 2) |
| 1583 | self.assertEqual(C.data['status'], 'NEW') |
| 1584 | self.assertEqual(C.reported, 2) |
| 1585 | self.assertEqual(D.data['status'], 'MERGED') |
| 1586 | self.assertEqual(D.reported, 2) |
| 1587 | 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] | 1588 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1589 | def test_new_patchset_check(self): |
| 1590 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1591 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1592 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1593 | |
| 1594 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1595 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1596 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1597 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1598 | |
| 1599 | # Add two git-dependent changes |
| 1600 | B.setDependsOn(A, 1) |
| 1601 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1602 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1603 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1604 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1605 | |
| 1606 | # A live item, and a non-live/live pair |
| 1607 | items = check_pipeline.getAllItems() |
| 1608 | self.assertEqual(len(items), 3) |
| 1609 | |
| 1610 | self.assertEqual(items[0].change.number, '1') |
| 1611 | self.assertEqual(items[0].change.patchset, '1') |
| 1612 | self.assertFalse(items[0].live) |
| 1613 | |
| 1614 | self.assertEqual(items[1].change.number, '2') |
| 1615 | self.assertEqual(items[1].change.patchset, '1') |
| 1616 | self.assertTrue(items[1].live) |
| 1617 | |
| 1618 | self.assertEqual(items[2].change.number, '1') |
| 1619 | self.assertEqual(items[2].change.patchset, '1') |
| 1620 | self.assertTrue(items[2].live) |
| 1621 | |
| 1622 | # Add a new patchset to A |
| 1623 | A.addPatchset() |
| 1624 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1625 | self.waitUntilSettled() |
| 1626 | |
| 1627 | # The live copy of A,1 should be gone, but the non-live and B |
| 1628 | # should continue, and we should have a new A,2 |
| 1629 | items = check_pipeline.getAllItems() |
| 1630 | self.assertEqual(len(items), 3) |
| 1631 | |
| 1632 | self.assertEqual(items[0].change.number, '1') |
| 1633 | self.assertEqual(items[0].change.patchset, '1') |
| 1634 | self.assertFalse(items[0].live) |
| 1635 | |
| 1636 | self.assertEqual(items[1].change.number, '2') |
| 1637 | self.assertEqual(items[1].change.patchset, '1') |
| 1638 | self.assertTrue(items[1].live) |
| 1639 | |
| 1640 | self.assertEqual(items[2].change.number, '1') |
| 1641 | self.assertEqual(items[2].change.patchset, '2') |
| 1642 | self.assertTrue(items[2].live) |
| 1643 | |
| 1644 | # Add a new patchset to B |
| 1645 | B.addPatchset() |
| 1646 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1647 | self.waitUntilSettled() |
| 1648 | |
| 1649 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1650 | # but we should have a new B,2 (still based on A,1) |
| 1651 | items = check_pipeline.getAllItems() |
| 1652 | self.assertEqual(len(items), 3) |
| 1653 | |
| 1654 | self.assertEqual(items[0].change.number, '1') |
| 1655 | self.assertEqual(items[0].change.patchset, '2') |
| 1656 | self.assertTrue(items[0].live) |
| 1657 | |
| 1658 | self.assertEqual(items[1].change.number, '1') |
| 1659 | self.assertEqual(items[1].change.patchset, '1') |
| 1660 | self.assertFalse(items[1].live) |
| 1661 | |
| 1662 | self.assertEqual(items[2].change.number, '2') |
| 1663 | self.assertEqual(items[2].change.patchset, '2') |
| 1664 | self.assertTrue(items[2].live) |
| 1665 | |
| 1666 | self.builds[0].release() |
| 1667 | self.waitUntilSettled() |
| 1668 | self.builds[0].release() |
| 1669 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1670 | self.launch_server.hold_jobs_in_build = False |
| 1671 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1672 | self.waitUntilSettled() |
| 1673 | |
| 1674 | self.assertEqual(A.reported, 1) |
| 1675 | self.assertEqual(B.reported, 1) |
| 1676 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1677 | self.assertEqual(self.history[0].changes, '1,1') |
| 1678 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1679 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1680 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1681 | self.assertEqual(self.history[2].changes, '1,2') |
| 1682 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1683 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1684 | |
| 1685 | def test_abandoned_gate(self): |
| 1686 | "Test that an abandoned change is dequeued from gate" |
| 1687 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1688 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1689 | |
| 1690 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1691 | A.addApproval('code-review', 2) |
| 1692 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1693 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1694 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1695 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1696 | |
| 1697 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1698 | self.waitUntilSettled() |
| 1699 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1700 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1701 | self.waitUntilSettled() |
| 1702 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1703 | self.assertBuilds([]) |
| 1704 | self.assertHistory([ |
| 1705 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1706 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1707 | self.assertEqual(A.reported, 1, |
| 1708 | "Abandoned gate change should report only start") |
| 1709 | |
| 1710 | def test_abandoned_check(self): |
| 1711 | "Test that an abandoned change is dequeued from check" |
| 1712 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1713 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1714 | |
| 1715 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1716 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1717 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1718 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1719 | |
| 1720 | # Add two git-dependent changes |
| 1721 | B.setDependsOn(A, 1) |
| 1722 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1723 | self.waitUntilSettled() |
| 1724 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1725 | self.waitUntilSettled() |
| 1726 | # A live item, and a non-live/live pair |
| 1727 | items = check_pipeline.getAllItems() |
| 1728 | self.assertEqual(len(items), 3) |
| 1729 | |
| 1730 | self.assertEqual(items[0].change.number, '1') |
| 1731 | self.assertFalse(items[0].live) |
| 1732 | |
| 1733 | self.assertEqual(items[1].change.number, '2') |
| 1734 | self.assertTrue(items[1].live) |
| 1735 | |
| 1736 | self.assertEqual(items[2].change.number, '1') |
| 1737 | self.assertTrue(items[2].live) |
| 1738 | |
| 1739 | # Abandon A |
| 1740 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1741 | self.waitUntilSettled() |
| 1742 | |
| 1743 | # The live copy of A should be gone, but the non-live and B |
| 1744 | # should continue |
| 1745 | items = check_pipeline.getAllItems() |
| 1746 | self.assertEqual(len(items), 2) |
| 1747 | |
| 1748 | self.assertEqual(items[0].change.number, '1') |
| 1749 | self.assertFalse(items[0].live) |
| 1750 | |
| 1751 | self.assertEqual(items[1].change.number, '2') |
| 1752 | self.assertTrue(items[1].live) |
| 1753 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1754 | self.launch_server.hold_jobs_in_build = False |
| 1755 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1756 | self.waitUntilSettled() |
| 1757 | |
| 1758 | self.assertEqual(len(self.history), 4) |
| 1759 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1760 | 'Build should have been aborted') |
| 1761 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1762 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1763 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1764 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1765 | def test_abandoned_not_timer(self): |
| 1766 | "Test that an abandoned change does not cancel timer jobs" |
| 1767 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1768 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1769 | |
| 1770 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1771 | self.updateConfigLayout( |
| 1772 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1773 | self.sched.reconfigure(self.config) |
| 1774 | self.registerJobs() |
| 1775 | # The pipeline triggers every second, so we should have seen |
| 1776 | # several by now. |
| 1777 | time.sleep(5) |
| 1778 | self.waitUntilSettled() |
| 1779 | # Stop queuing timer triggered jobs so that the assertions |
| 1780 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1781 | self.updateConfigLayout( |
| 1782 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1783 | self.sched.reconfigure(self.config) |
| 1784 | self.registerJobs() |
| 1785 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1786 | |
| 1787 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1788 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1789 | self.waitUntilSettled() |
| 1790 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1791 | |
| 1792 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1793 | self.waitUntilSettled() |
| 1794 | |
| 1795 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1796 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1797 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1798 | self.waitUntilSettled() |
| 1799 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1800 | def test_zuul_url_return(self): |
| 1801 | "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] | 1802 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1803 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1804 | |
| 1805 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1806 | A.addApproval('code-review', 2) |
| 1807 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1808 | self.waitUntilSettled() |
| 1809 | |
| 1810 | self.assertEqual(len(self.builds), 1) |
| 1811 | for build in self.builds: |
| 1812 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1813 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1814 | self.launch_server.hold_jobs_in_build = False |
| 1815 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1816 | self.waitUntilSettled() |
| 1817 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1818 | def test_new_patchset_dequeues_old_on_head(self): |
| 1819 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1820 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1821 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1822 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1823 | M.setMerged() |
| 1824 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1825 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1826 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1827 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1828 | A.addApproval('code-review', 2) |
| 1829 | B.addApproval('code-review', 2) |
| 1830 | C.addApproval('code-review', 2) |
| 1831 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1832 | |
| 1833 | C.setDependsOn(B, 1) |
| 1834 | B.setDependsOn(A, 1) |
| 1835 | A.setDependsOn(M, 1) |
| 1836 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1837 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1838 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1839 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1840 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1841 | self.waitUntilSettled() |
| 1842 | |
| 1843 | A.addPatchset() |
| 1844 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1845 | self.waitUntilSettled() |
| 1846 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1847 | self.launch_server.hold_jobs_in_build = False |
| 1848 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1849 | self.waitUntilSettled() |
| 1850 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1851 | self.assertEqual(A.data['status'], 'NEW') |
| 1852 | self.assertEqual(A.reported, 2) |
| 1853 | self.assertEqual(B.data['status'], 'NEW') |
| 1854 | self.assertEqual(B.reported, 2) |
| 1855 | self.assertEqual(C.data['status'], 'NEW') |
| 1856 | self.assertEqual(C.reported, 2) |
| 1857 | self.assertEqual(D.data['status'], 'MERGED') |
| 1858 | self.assertEqual(D.reported, 2) |
| 1859 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1860 | |
| 1861 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1862 | "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] | 1863 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1864 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1865 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1866 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1867 | A.addApproval('code-review', 2) |
| 1868 | B.addApproval('code-review', 2) |
| 1869 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1870 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1871 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1872 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1873 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1874 | self.waitUntilSettled() |
| 1875 | |
| 1876 | B.addPatchset() |
| 1877 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1878 | self.waitUntilSettled() |
| 1879 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1880 | self.launch_server.hold_jobs_in_build = False |
| 1881 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1882 | self.waitUntilSettled() |
| 1883 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1884 | self.assertEqual(A.data['status'], 'MERGED') |
| 1885 | self.assertEqual(A.reported, 2) |
| 1886 | self.assertEqual(B.data['status'], 'NEW') |
| 1887 | self.assertEqual(B.reported, 2) |
| 1888 | self.assertEqual(C.data['status'], 'MERGED') |
| 1889 | self.assertEqual(C.reported, 2) |
| 1890 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1891 | |
| 1892 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1893 | "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] | 1894 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1895 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1896 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1897 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1898 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1899 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1900 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1901 | self.waitUntilSettled() |
| 1902 | |
| 1903 | B.addPatchset() |
| 1904 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1905 | self.waitUntilSettled() |
| 1906 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1907 | self.launch_server.hold_jobs_in_build = False |
| 1908 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1909 | self.waitUntilSettled() |
| 1910 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1911 | self.assertEqual(A.data['status'], 'NEW') |
| 1912 | self.assertEqual(A.reported, 1) |
| 1913 | self.assertEqual(B.data['status'], 'NEW') |
| 1914 | self.assertEqual(B.reported, 1) |
| 1915 | self.assertEqual(C.data['status'], 'NEW') |
| 1916 | self.assertEqual(C.reported, 1) |
| 1917 | self.assertEqual(len(self.history), 10) |
| 1918 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1919 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1920 | def test_noop_job(self): |
| 1921 | "Test that the internal noop job works" |
| 1922 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1923 | A.addApproval('code-review', 2) |
| 1924 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1925 | self.waitUntilSettled() |
| 1926 | |
| 1927 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1928 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1929 | self.assertEqual(len(self.history), 0) |
| 1930 | self.assertEqual(A.data['status'], 'MERGED') |
| 1931 | self.assertEqual(A.reported, 2) |
| 1932 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1933 | def test_no_job_project(self): |
| 1934 | "Test that reports with no jobs don't get sent" |
| 1935 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1936 | 'master', 'A') |
| 1937 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1938 | self.waitUntilSettled() |
| 1939 | |
| 1940 | # Change wasn't reported to |
| 1941 | self.assertEqual(A.reported, False) |
| 1942 | |
| 1943 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1944 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1945 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1946 | items = check_pipeline.getAllItems() |
| 1947 | self.assertEqual(len(items), 0) |
| 1948 | |
| 1949 | self.assertEqual(len(self.history), 0) |
| 1950 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1951 | def test_zuul_refs(self): |
| 1952 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1953 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1954 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1955 | M1.setMerged() |
| 1956 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1957 | M2.setMerged() |
| 1958 | |
| 1959 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1960 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1961 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1962 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1963 | A.addApproval('code-review', 2) |
| 1964 | B.addApproval('code-review', 2) |
| 1965 | C.addApproval('code-review', 2) |
| 1966 | D.addApproval('code-review', 2) |
| 1967 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1968 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1969 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1970 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1971 | |
| 1972 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1973 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1974 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1975 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1976 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1977 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1978 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1979 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1980 | self.waitUntilSettled() |
| 1981 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1982 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1983 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1984 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1985 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1986 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1987 | a_build = x |
| 1988 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1989 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1990 | b_build = x |
| 1991 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1992 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1993 | c_build = x |
| 1994 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1995 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1996 | d_build = x |
| 1997 | if a_build and b_build and c_build and d_build: |
| 1998 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1999 | |
| 2000 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2001 | self.assertIsNotNone(a_zref) |
| 2002 | self.assertIsNotNone(b_zref) |
| 2003 | self.assertIsNotNone(c_zref) |
| 2004 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2005 | |
| 2006 | # And they should all be different |
| 2007 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2008 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2009 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2010 | # should have a, not b, and should not be in project2 |
| 2011 | self.assertTrue(a_build.hasChanges(A)) |
| 2012 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2013 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2014 | # should have a and b, and should not be in project2 |
| 2015 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2016 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2017 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2018 | # should have a and b in 1, c in 2 |
| 2019 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2020 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2021 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2022 | # should have a and b in 1, c and d in 2 |
| 2023 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2024 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2025 | self.launch_server.hold_jobs_in_build = False |
| 2026 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2027 | self.waitUntilSettled() |
| 2028 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2029 | self.assertEqual(A.data['status'], 'MERGED') |
| 2030 | self.assertEqual(A.reported, 2) |
| 2031 | self.assertEqual(B.data['status'], 'MERGED') |
| 2032 | self.assertEqual(B.reported, 2) |
| 2033 | self.assertEqual(C.data['status'], 'MERGED') |
| 2034 | self.assertEqual(C.reported, 2) |
| 2035 | self.assertEqual(D.data['status'], 'MERGED') |
| 2036 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2037 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2038 | def test_rerun_on_error(self): |
| 2039 | "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] | 2040 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2041 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2042 | A.addApproval('code-review', 2) |
| 2043 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2044 | self.waitUntilSettled() |
| 2045 | |
| 2046 | self.builds[0].run_error = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2047 | self.launch_server.hold_jobs_in_build = False |
| 2048 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2049 | self.waitUntilSettled() |
| 2050 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2051 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2052 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2053 | def test_statsd(self): |
| 2054 | "Test each of the statsd methods used in the scheduler" |
| 2055 | import extras |
| 2056 | statsd = extras.try_import('statsd.statsd') |
| 2057 | statsd.incr('test-incr') |
| 2058 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2059 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2060 | self.assertReportedStat('test-incr', '1|c') |
| 2061 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2062 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2063 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2064 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2065 | def test_stuck_job_cleanup(self): |
| 2066 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2067 | # This job won't be registered at startup because it is not in |
| 2068 | # the standard layout, but we need it to already be registerd |
| 2069 | # for when we reconfigure, as that is when Zuul will attempt |
| 2070 | # to run the new job. |
| 2071 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2072 | self.gearman_server.hold_jobs_in_queue = True |
| 2073 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2074 | A.addApproval('code-review', 2) |
| 2075 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2076 | self.waitUntilSettled() |
| 2077 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2078 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2079 | self.updateConfigLayout( |
| 2080 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2081 | self.sched.reconfigure(self.config) |
| 2082 | self.waitUntilSettled() |
| 2083 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2084 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2085 | self.waitUntilSettled() |
| 2086 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2087 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2088 | |
| 2089 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2090 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2091 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2092 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2093 | def test_file_head(self): |
| 2094 | # This is a regression test for an observed bug. A change |
| 2095 | # with a file named "HEAD" in the root directory of the repo |
| 2096 | # was processed by a merger. It then was unable to reset the |
| 2097 | # repo because of: |
| 2098 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2099 | # with exit code 128 |
| 2100 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2101 | # and filename |
| 2102 | # Use '--' to separate filenames from revisions' |
| 2103 | |
| 2104 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2105 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2106 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2107 | |
| 2108 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2109 | self.waitUntilSettled() |
| 2110 | |
| 2111 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2112 | self.waitUntilSettled() |
| 2113 | |
| 2114 | self.assertIn('Build succeeded', A.messages[0]) |
| 2115 | self.assertIn('Build succeeded', B.messages[0]) |
| 2116 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2117 | @skip("Disabled for early v3 development") |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2118 | def test_file_jobs(self): |
| 2119 | "Test that file jobs run only when appropriate" |
| 2120 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2121 | A.addPatchset(['pip-requires']) |
| 2122 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2123 | A.addApproval('code-review', 2) |
| 2124 | B.addApproval('code-review', 2) |
| 2125 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2126 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2127 | self.waitUntilSettled() |
| 2128 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2129 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2130 | if x.name == 'project-testfile'] |
| 2131 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2132 | self.assertEqual(len(testfile_jobs), 1) |
| 2133 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2134 | self.assertEqual(A.data['status'], 'MERGED') |
| 2135 | self.assertEqual(A.reported, 2) |
| 2136 | self.assertEqual(B.data['status'], 'MERGED') |
| 2137 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2138 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2139 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2140 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2141 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2142 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2143 | |
| 2144 | if should_skip: |
| 2145 | files = {'ignoreme': 'ignored\n'} |
| 2146 | else: |
| 2147 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2148 | |
| 2149 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2150 | 'master', |
| 2151 | 'test irrelevant-files', |
| 2152 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2153 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2154 | self.waitUntilSettled() |
| 2155 | |
| 2156 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2157 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2158 | |
| 2159 | if should_skip: |
| 2160 | self.assertEqual([], tested_change_ids) |
| 2161 | else: |
| 2162 | self.assertIn(change.data['number'], tested_change_ids) |
| 2163 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2164 | def test_irrelevant_files_match_skips_job(self): |
| 2165 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2166 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2167 | def test_irrelevant_files_no_match_runs_job(self): |
| 2168 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2169 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2170 | def test_inherited_jobs_keep_matchers(self): |
| 2171 | self.updateConfigLayout('layout-inheritance') |
| 2172 | self.sched.reconfigure(self.config) |
| 2173 | |
| 2174 | files = {'ignoreme': 'ignored\n'} |
| 2175 | |
| 2176 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2177 | 'master', |
| 2178 | 'test irrelevant-files', |
| 2179 | files=files) |
| 2180 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2181 | self.waitUntilSettled() |
| 2182 | |
| 2183 | run_jobs = set([build.name for build in self.history]) |
| 2184 | |
| 2185 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2186 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2187 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2188 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2189 | def test_test_config(self): |
| 2190 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2191 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2192 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2193 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2194 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2195 | def test_queue_names(self): |
| 2196 | "Test shared change queue names" |
| 2197 | project1 = self.sched.layout.projects['org/project1'] |
| 2198 | project2 = self.sched.layout.projects['org/project2'] |
| 2199 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2200 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2201 | self.assertEqual(q1.name, 'integration') |
| 2202 | self.assertEqual(q2.name, 'integration') |
| 2203 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2204 | self.updateConfigLayout( |
| 2205 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2206 | with testtools.ExpectedException( |
| 2207 | Exception, "More than one name assigned to change queue"): |
| 2208 | self.sched.reconfigure(self.config) |
| 2209 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2210 | def test_queue_precedence(self): |
| 2211 | "Test that queue precedence works" |
| 2212 | |
| 2213 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2214 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2215 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2216 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2217 | A.addApproval('code-review', 2) |
| 2218 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2219 | |
| 2220 | self.waitUntilSettled() |
| 2221 | self.gearman_server.hold_jobs_in_queue = False |
| 2222 | self.gearman_server.release() |
| 2223 | self.waitUntilSettled() |
| 2224 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2225 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2226 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2227 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2228 | self.waitUntilSettled() |
| 2229 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2230 | self.log.debug(self.history) |
| 2231 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2232 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2233 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2234 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2235 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2236 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2237 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2238 | @skip("Disabled for early v3 development") |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2239 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2240 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2241 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2242 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2243 | A.addApproval('code-review', 2) |
| 2244 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2245 | self.waitUntilSettled() |
| 2246 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2247 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2248 | self.waitUntilSettled() |
| 2249 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2250 | port = self.webapp.server.socket.getsockname()[1] |
| 2251 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2252 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2253 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2254 | headers = f.info() |
| 2255 | self.assertIn('Content-Length', headers) |
| 2256 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2257 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2258 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2259 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2260 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2261 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2262 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2263 | data = f.read() |
| 2264 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2265 | self.launch_server.hold_jobs_in_build = False |
| 2266 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2267 | self.waitUntilSettled() |
| 2268 | |
| 2269 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2270 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2271 | for p in data['pipelines']: |
| 2272 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2273 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2274 | self.assertEqual(q['window'], 20) |
| 2275 | else: |
| 2276 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2277 | for head in q['heads']: |
| 2278 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2279 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2280 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2281 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2282 | status_jobs.append(job) |
| 2283 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2284 | self.assertEqual('https://server/job/project-merge/0/', |
| 2285 | status_jobs[0]['url']) |
| 2286 | self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0', |
| 2287 | status_jobs[0]['report_url']) |
| 2288 | |
| 2289 | self.assertEqual('project-test1', status_jobs[1]['name']) |
| 2290 | self.assertEqual('https://server/job/project-test1/1/', |
| 2291 | status_jobs[1]['url']) |
| 2292 | self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1', |
| 2293 | status_jobs[1]['report_url']) |
| 2294 | |
| 2295 | self.assertEqual('project-test2', status_jobs[2]['name']) |
| 2296 | self.assertEqual('https://server/job/project-test2/2/', |
| 2297 | status_jobs[2]['url']) |
| 2298 | self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2', |
| 2299 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2300 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2301 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2302 | def test_merging_queues(self): |
| 2303 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2304 | self.updateConfigLayout( |
| 2305 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2306 | self.sched.reconfigure(self.config) |
| 2307 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2308 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2309 | @skip("Disabled for early v3 development") |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2310 | def test_mutex(self): |
| 2311 | "Test job mutexes" |
| 2312 | self.config.set('zuul', 'layout_config', |
| 2313 | 'tests/fixtures/layout-mutex.yaml') |
| 2314 | self.sched.reconfigure(self.config) |
| 2315 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2316 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2317 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2318 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2319 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2320 | |
| 2321 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2322 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2323 | self.waitUntilSettled() |
| 2324 | self.assertEqual(len(self.builds), 3) |
| 2325 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2326 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2327 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2328 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2329 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2330 | self.waitUntilSettled() |
| 2331 | |
| 2332 | self.assertEqual(len(self.builds), 3) |
| 2333 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2334 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2335 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2336 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2337 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2338 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2339 | self.waitUntilSettled() |
| 2340 | |
| 2341 | self.assertEqual(len(self.builds), 3) |
| 2342 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2343 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2344 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2345 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2346 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2347 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2348 | self.waitUntilSettled() |
| 2349 | |
| 2350 | self.assertEqual(len(self.builds), 3) |
| 2351 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2352 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2353 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2354 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2355 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2356 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2357 | self.waitUntilSettled() |
| 2358 | |
| 2359 | self.assertEqual(len(self.builds), 2) |
| 2360 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2361 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2362 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2363 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2364 | self.launch_server.hold_jobs_in_build = False |
| 2365 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2366 | |
| 2367 | self.waitUntilSettled() |
| 2368 | self.assertEqual(len(self.builds), 0) |
| 2369 | |
| 2370 | self.assertEqual(A.reported, 1) |
| 2371 | self.assertEqual(B.reported, 1) |
| 2372 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2373 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2374 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2375 | def test_node_label(self): |
| 2376 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2377 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2378 | |
| 2379 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2380 | A.addApproval('code-review', 2) |
| 2381 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2382 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2383 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2384 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2385 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2386 | 'debian') |
| 2387 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2388 | |
| 2389 | def test_live_reconfiguration(self): |
| 2390 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2391 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2392 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2393 | A.addApproval('code-review', 2) |
| 2394 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2395 | self.waitUntilSettled() |
| 2396 | |
| 2397 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame^] | 2398 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2399 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2400 | self.launch_server.hold_jobs_in_build = False |
| 2401 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2402 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2403 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2404 | 'SUCCESS') |
| 2405 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2406 | 'SUCCESS') |
| 2407 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2408 | 'SUCCESS') |
| 2409 | self.assertEqual(A.data['status'], 'MERGED') |
| 2410 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2411 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2412 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2413 | def test_live_reconfiguration_merge_conflict(self): |
| 2414 | # A real-world bug: a change in a gate queue has a merge |
| 2415 | # conflict and a job is added to its project while it's |
| 2416 | # sitting in the queue. The job gets added to the change and |
| 2417 | # enqueued and the change gets stuck. |
| 2418 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2419 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2420 | |
| 2421 | # This change is fine. It's here to stop the queue long |
| 2422 | # enough for the next change to be subject to the |
| 2423 | # reconfiguration, as well as to provide a conflict for the |
| 2424 | # next change. This change will succeed and merge. |
| 2425 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2426 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2427 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2428 | |
| 2429 | # This change will be in merge conflict. During the |
| 2430 | # reconfiguration, we will add a job. We want to make sure |
| 2431 | # that doesn't cause it to get stuck. |
| 2432 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2433 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2434 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2435 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2436 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2437 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2438 | |
| 2439 | self.waitUntilSettled() |
| 2440 | |
| 2441 | # No jobs have run yet |
| 2442 | self.assertEqual(A.data['status'], 'NEW') |
| 2443 | self.assertEqual(A.reported, 1) |
| 2444 | self.assertEqual(B.data['status'], 'NEW') |
| 2445 | self.assertEqual(B.reported, 1) |
| 2446 | self.assertEqual(len(self.history), 0) |
| 2447 | |
| 2448 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2449 | self.updateConfigLayout( |
| 2450 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2451 | self.sched.reconfigure(self.config) |
| 2452 | self.waitUntilSettled() |
| 2453 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2454 | self.launch_server.hold_jobs_in_build = False |
| 2455 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2456 | self.waitUntilSettled() |
| 2457 | |
| 2458 | self.assertEqual(A.data['status'], 'MERGED') |
| 2459 | self.assertEqual(A.reported, 2) |
| 2460 | self.assertEqual(B.data['status'], 'NEW') |
| 2461 | self.assertEqual(B.reported, 2) |
| 2462 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2463 | 'SUCCESS') |
| 2464 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2465 | 'SUCCESS') |
| 2466 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2467 | 'SUCCESS') |
| 2468 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2469 | 'SUCCESS') |
| 2470 | self.assertEqual(len(self.history), 4) |
| 2471 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2472 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2473 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2474 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2475 | # that tests a job added to a job tree with a failed root does |
| 2476 | # not run. |
| 2477 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2478 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2479 | |
| 2480 | # This change is fine. It's here to stop the queue long |
| 2481 | # enough for the next change to be subject to the |
| 2482 | # reconfiguration. This change will succeed and merge. |
| 2483 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2484 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2485 | A.addApproval('code-review', 2) |
| 2486 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2487 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2488 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2489 | self.waitUntilSettled() |
| 2490 | |
| 2491 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2492 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2493 | B.addApproval('code-review', 2) |
| 2494 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2495 | self.waitUntilSettled() |
| 2496 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2497 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2498 | self.waitUntilSettled() |
| 2499 | |
| 2500 | # Both -merge jobs have run, but no others. |
| 2501 | self.assertEqual(A.data['status'], 'NEW') |
| 2502 | self.assertEqual(A.reported, 1) |
| 2503 | self.assertEqual(B.data['status'], 'NEW') |
| 2504 | self.assertEqual(B.reported, 1) |
| 2505 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2506 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2507 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2508 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2509 | self.assertEqual(len(self.history), 2) |
| 2510 | |
| 2511 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2512 | self.updateConfigLayout( |
| 2513 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2514 | self.sched.reconfigure(self.config) |
| 2515 | self.waitUntilSettled() |
| 2516 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2517 | self.launch_server.hold_jobs_in_build = False |
| 2518 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2519 | self.waitUntilSettled() |
| 2520 | |
| 2521 | self.assertEqual(A.data['status'], 'MERGED') |
| 2522 | self.assertEqual(A.reported, 2) |
| 2523 | self.assertEqual(B.data['status'], 'NEW') |
| 2524 | self.assertEqual(B.reported, 2) |
| 2525 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2526 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2527 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2528 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2529 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2530 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2531 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2532 | self.assertEqual(len(self.history), 5) |
| 2533 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2534 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2535 | def test_live_reconfiguration_failed_job(self): |
| 2536 | # Test that a change with a removed failing job does not |
| 2537 | # disrupt reconfiguration. If a change has a failed job and |
| 2538 | # that job is removed during a reconfiguration, we observed a |
| 2539 | # bug where the code to re-set build statuses would run on |
| 2540 | # that build and raise an exception because the job no longer |
| 2541 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2542 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2543 | |
| 2544 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2545 | |
| 2546 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2547 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2548 | |
| 2549 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2550 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2551 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2552 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2553 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2554 | self.waitUntilSettled() |
| 2555 | |
| 2556 | self.assertEqual(A.data['status'], 'NEW') |
| 2557 | self.assertEqual(A.reported, 0) |
| 2558 | |
| 2559 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2560 | 'SUCCESS') |
| 2561 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2562 | 'FAILURE') |
| 2563 | self.assertEqual(len(self.history), 2) |
| 2564 | |
| 2565 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2566 | self.updateConfigLayout( |
| 2567 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2568 | self.sched.reconfigure(self.config) |
| 2569 | self.waitUntilSettled() |
| 2570 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2571 | self.launch_server.hold_jobs_in_build = False |
| 2572 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2573 | self.waitUntilSettled() |
| 2574 | |
| 2575 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2576 | 'SUCCESS') |
| 2577 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2578 | 'SUCCESS') |
| 2579 | self.assertEqual(len(self.history), 4) |
| 2580 | |
| 2581 | self.assertEqual(A.data['status'], 'NEW') |
| 2582 | self.assertEqual(A.reported, 1) |
| 2583 | self.assertIn('Build succeeded', A.messages[0]) |
| 2584 | # Ensure the removed job was not included in the report. |
| 2585 | self.assertNotIn('project-test1', A.messages[0]) |
| 2586 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2587 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2588 | def test_live_reconfiguration_shared_queue(self): |
| 2589 | # Test that a change with a failing job which was removed from |
| 2590 | # this project but otherwise still exists in the system does |
| 2591 | # not disrupt reconfiguration. |
| 2592 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2593 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2594 | |
| 2595 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2596 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2597 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2598 | |
| 2599 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2600 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2601 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2602 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2603 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2604 | self.waitUntilSettled() |
| 2605 | |
| 2606 | self.assertEqual(A.data['status'], 'NEW') |
| 2607 | self.assertEqual(A.reported, 0) |
| 2608 | |
| 2609 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2610 | 'SUCCESS') |
| 2611 | self.assertEqual(self.getJobFromHistory( |
| 2612 | 'project1-project2-integration').result, 'FAILURE') |
| 2613 | self.assertEqual(len(self.history), 2) |
| 2614 | |
| 2615 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2616 | self.updateConfigLayout( |
| 2617 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2618 | self.sched.reconfigure(self.config) |
| 2619 | self.waitUntilSettled() |
| 2620 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2621 | self.launch_server.hold_jobs_in_build = False |
| 2622 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2623 | self.waitUntilSettled() |
| 2624 | |
| 2625 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2626 | 'SUCCESS') |
| 2627 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2628 | 'SUCCESS') |
| 2629 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2630 | 'SUCCESS') |
| 2631 | self.assertEqual(self.getJobFromHistory( |
| 2632 | 'project1-project2-integration').result, 'FAILURE') |
| 2633 | self.assertEqual(len(self.history), 4) |
| 2634 | |
| 2635 | self.assertEqual(A.data['status'], 'NEW') |
| 2636 | self.assertEqual(A.reported, 1) |
| 2637 | self.assertIn('Build succeeded', A.messages[0]) |
| 2638 | # Ensure the removed job was not included in the report. |
| 2639 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2640 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2641 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2642 | def test_double_live_reconfiguration_shared_queue(self): |
| 2643 | # This was a real-world regression. A change is added to |
| 2644 | # gate; a reconfigure happens, a second change which depends |
| 2645 | # on the first is added, and a second reconfiguration happens. |
| 2646 | # Ensure that both changes merge. |
| 2647 | |
| 2648 | # A failure may indicate incorrect caching or cleaning up of |
| 2649 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2650 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2651 | |
| 2652 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2653 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2654 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2655 | A.addApproval('code-review', 2) |
| 2656 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2657 | |
| 2658 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2659 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2660 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2661 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2662 | self.waitUntilSettled() |
| 2663 | |
| 2664 | # Reconfigure (with only one change in the pipeline). |
| 2665 | self.sched.reconfigure(self.config) |
| 2666 | self.waitUntilSettled() |
| 2667 | |
| 2668 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2669 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2670 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2671 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2672 | self.waitUntilSettled() |
| 2673 | |
| 2674 | # Reconfigure (with both in the pipeline). |
| 2675 | self.sched.reconfigure(self.config) |
| 2676 | self.waitUntilSettled() |
| 2677 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2678 | self.launch_server.hold_jobs_in_build = False |
| 2679 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2680 | self.waitUntilSettled() |
| 2681 | |
| 2682 | self.assertEqual(len(self.history), 8) |
| 2683 | |
| 2684 | self.assertEqual(A.data['status'], 'MERGED') |
| 2685 | self.assertEqual(A.reported, 2) |
| 2686 | self.assertEqual(B.data['status'], 'MERGED') |
| 2687 | self.assertEqual(B.reported, 2) |
| 2688 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2689 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2690 | def test_live_reconfiguration_del_project(self): |
| 2691 | # Test project deletion from layout |
| 2692 | # while changes are enqueued |
| 2693 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2694 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2695 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2696 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2697 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2698 | |
| 2699 | # A Depends-On: B |
| 2700 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2701 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2702 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2703 | |
| 2704 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2705 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2706 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2707 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2708 | self.waitUntilSettled() |
| 2709 | self.assertEqual(len(self.builds), 5) |
| 2710 | |
| 2711 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2712 | self.updateConfigLayout( |
| 2713 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2714 | self.sched.reconfigure(self.config) |
| 2715 | self.waitUntilSettled() |
| 2716 | |
| 2717 | # Builds for C aborted, builds for A succeed, |
| 2718 | # and have change B applied ahead |
| 2719 | job_c = self.getJobFromHistory('project1-test1') |
| 2720 | self.assertEqual(job_c.changes, '3,1') |
| 2721 | self.assertEqual(job_c.result, 'ABORTED') |
| 2722 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2723 | self.launch_server.hold_jobs_in_build = False |
| 2724 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2725 | self.waitUntilSettled() |
| 2726 | |
| 2727 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2728 | '2,1 1,1') |
| 2729 | |
| 2730 | self.assertEqual(A.data['status'], 'NEW') |
| 2731 | self.assertEqual(B.data['status'], 'NEW') |
| 2732 | self.assertEqual(C.data['status'], 'NEW') |
| 2733 | self.assertEqual(A.reported, 1) |
| 2734 | self.assertEqual(B.reported, 0) |
| 2735 | self.assertEqual(C.reported, 0) |
| 2736 | |
| 2737 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2738 | self.assertIn('Build succeeded', A.messages[0]) |
| 2739 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2740 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2741 | def test_live_reconfiguration_functions(self): |
| 2742 | "Test live reconfiguration with a custom function" |
| 2743 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2744 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2745 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2746 | A.addApproval('code-review', 2) |
| 2747 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2748 | self.waitUntilSettled() |
| 2749 | |
| 2750 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2751 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2752 | 'debian') |
| 2753 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2754 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2755 | self.updateConfigLayout( |
| 2756 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2757 | self.sched.reconfigure(self.config) |
| 2758 | self.worker.build_history = [] |
| 2759 | |
| 2760 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2761 | B.addApproval('code-review', 2) |
| 2762 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2763 | self.waitUntilSettled() |
| 2764 | |
| 2765 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2766 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2767 | 'wheezy') |
| 2768 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2769 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2770 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2771 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2772 | self.updateConfigLayout( |
| 2773 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2774 | self.sched.reconfigure(self.config) |
| 2775 | |
| 2776 | self.init_repo("org/new-project") |
| 2777 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2778 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2779 | A.addApproval('code-review', 2) |
| 2780 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2781 | self.waitUntilSettled() |
| 2782 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2783 | 'SUCCESS') |
| 2784 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2785 | 'SUCCESS') |
| 2786 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2787 | 'SUCCESS') |
| 2788 | self.assertEqual(A.data['status'], 'MERGED') |
| 2789 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2790 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2791 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2792 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2793 | self.sched.reconfigure(self.config) |
| 2794 | |
| 2795 | self.init_repo("org/delete-project") |
| 2796 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2797 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2798 | A.addApproval('code-review', 2) |
| 2799 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2800 | self.waitUntilSettled() |
| 2801 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2802 | 'SUCCESS') |
| 2803 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2804 | 'SUCCESS') |
| 2805 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2806 | 'SUCCESS') |
| 2807 | self.assertEqual(A.data['status'], 'MERGED') |
| 2808 | self.assertEqual(A.reported, 2) |
| 2809 | |
| 2810 | # Delete org/new-project zuul repo. Should be recloned. |
| 2811 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2812 | |
| 2813 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2814 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2815 | B.addApproval('code-review', 2) |
| 2816 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2817 | self.waitUntilSettled() |
| 2818 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2819 | 'SUCCESS') |
| 2820 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2821 | 'SUCCESS') |
| 2822 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2823 | 'SUCCESS') |
| 2824 | self.assertEqual(B.data['status'], 'MERGED') |
| 2825 | self.assertEqual(B.reported, 2) |
| 2826 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2827 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2828 | def test_tags(self): |
| 2829 | "Test job tags" |
| 2830 | self.config.set('zuul', 'layout_config', |
| 2831 | 'tests/fixtures/layout-tags.yaml') |
| 2832 | self.sched.reconfigure(self.config) |
| 2833 | |
| 2834 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2835 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2836 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2837 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2838 | self.waitUntilSettled() |
| 2839 | |
| 2840 | results = {'project1-merge': 'extratag merge project1', |
| 2841 | 'project2-merge': 'merge'} |
| 2842 | |
| 2843 | for build in self.history: |
| 2844 | self.assertEqual(results.get(build.name, ''), |
| 2845 | build.parameters.get('BUILD_TAGS')) |
| 2846 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2847 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2848 | def test_timer(self): |
| 2849 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2850 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2851 | self.updateConfigLayout( |
| 2852 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2853 | self.sched.reconfigure(self.config) |
| 2854 | self.registerJobs() |
| 2855 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2856 | # The pipeline triggers every second, so we should have seen |
| 2857 | # several by now. |
| 2858 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2859 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2860 | |
| 2861 | self.assertEqual(len(self.builds), 2) |
| 2862 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2863 | port = self.webapp.server.socket.getsockname()[1] |
| 2864 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2865 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2866 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2867 | data = f.read() |
| 2868 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2869 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2870 | # Stop queuing timer triggered jobs so that the assertions |
| 2871 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2872 | self.updateConfigLayout( |
| 2873 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2874 | self.sched.reconfigure(self.config) |
| 2875 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2876 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2877 | self.waitUntilSettled() |
| 2878 | |
| 2879 | self.assertEqual(self.getJobFromHistory( |
| 2880 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2881 | self.assertEqual(self.getJobFromHistory( |
| 2882 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2883 | |
| 2884 | data = json.loads(data) |
| 2885 | status_jobs = set() |
| 2886 | for p in data['pipelines']: |
| 2887 | for q in p['change_queues']: |
| 2888 | for head in q['heads']: |
| 2889 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2890 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2891 | for job in change['jobs']: |
| 2892 | status_jobs.add(job['name']) |
| 2893 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2894 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2895 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2896 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2897 | def test_idle(self): |
| 2898 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2899 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2900 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2901 | for x in range(1, 3): |
| 2902 | # Test that timer triggers periodic jobs even across |
| 2903 | # layout config reloads. |
| 2904 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2905 | self.updateConfigLayout( |
| 2906 | 'tests/fixtures/layout-idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2907 | self.sched.reconfigure(self.config) |
| 2908 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2909 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2910 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2911 | # The pipeline triggers every second, so we should have seen |
| 2912 | # several by now. |
| 2913 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2914 | |
| 2915 | # Stop queuing timer triggered jobs so that the assertions |
| 2916 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2917 | self.updateConfigLayout( |
| 2918 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2919 | self.sched.reconfigure(self.config) |
| 2920 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2921 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2922 | |
| 2923 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2924 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2925 | self.waitUntilSettled() |
| 2926 | self.assertEqual(len(self.builds), 0) |
| 2927 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2928 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2929 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2930 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2931 | self.sched.reconfigure(self.config) |
| 2932 | |
| 2933 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2934 | self.waitUntilSettled() |
| 2935 | |
| 2936 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2937 | self.waitUntilSettled() |
| 2938 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2939 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2940 | |
| 2941 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2942 | # work on the knowledge of what the first message should be as |
| 2943 | # it is only configured to go to SMTP. |
| 2944 | |
| 2945 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2946 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2947 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2948 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2949 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2950 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2951 | |
| 2952 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2953 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2954 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2955 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2956 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2957 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2958 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2959 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2960 | def test_timer_smtp(self): |
| 2961 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2962 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2963 | self.updateConfigLayout( |
| 2964 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2965 | self.sched.reconfigure(self.config) |
| 2966 | self.registerJobs() |
| 2967 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2968 | # The pipeline triggers every second, so we should have seen |
| 2969 | # several by now. |
| 2970 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2971 | self.waitUntilSettled() |
| 2972 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2973 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2974 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2975 | self.waitUntilSettled() |
| 2976 | self.assertEqual(len(self.history), 2) |
| 2977 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2978 | self.assertEqual(self.getJobFromHistory( |
| 2979 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2980 | self.assertEqual(self.getJobFromHistory( |
| 2981 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2982 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2983 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2984 | |
| 2985 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2986 | # work on the knowledge of what the first message should be as |
| 2987 | # it is only configured to go to SMTP. |
| 2988 | |
| 2989 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2990 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2991 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2992 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2993 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2994 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2995 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2996 | # Stop queuing timer triggered jobs and let any that may have |
| 2997 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2998 | self.updateConfigLayout( |
| 2999 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3000 | self.sched.reconfigure(self.config) |
| 3001 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3002 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3003 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3004 | self.waitUntilSettled() |
| 3005 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3006 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3007 | "Test that the RPC client can enqueue a change" |
| 3008 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3009 | A.addApproval('code-review', 2) |
| 3010 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3011 | |
| 3012 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3013 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3014 | r = client.enqueue(tenant='tenant-one', |
| 3015 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3016 | project='org/project', |
| 3017 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3018 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3019 | self.waitUntilSettled() |
| 3020 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3021 | 'SUCCESS') |
| 3022 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3023 | 'SUCCESS') |
| 3024 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3025 | 'SUCCESS') |
| 3026 | self.assertEqual(A.data['status'], 'MERGED') |
| 3027 | self.assertEqual(A.reported, 2) |
| 3028 | self.assertEqual(r, True) |
| 3029 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3030 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3031 | def test_client_enqueue_ref(self): |
| 3032 | "Test that the RPC client can enqueue a ref" |
| 3033 | |
| 3034 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3035 | self.gearman_server.port) |
| 3036 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3037 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3038 | pipeline='post', |
| 3039 | project='org/project', |
| 3040 | trigger='gerrit', |
| 3041 | ref='master', |
| 3042 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3043 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3044 | self.waitUntilSettled() |
| 3045 | job_names = [x.name for x in self.history] |
| 3046 | self.assertEqual(len(self.history), 1) |
| 3047 | self.assertIn('project-post', job_names) |
| 3048 | self.assertEqual(r, True) |
| 3049 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3050 | def test_client_enqueue_negative(self): |
| 3051 | "Test that the RPC client returns errors" |
| 3052 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3053 | self.gearman_server.port) |
| 3054 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3055 | "Invalid tenant"): |
| 3056 | r = client.enqueue(tenant='tenant-foo', |
| 3057 | pipeline='gate', |
| 3058 | project='org/project', |
| 3059 | trigger='gerrit', |
| 3060 | change='1,1') |
| 3061 | client.shutdown() |
| 3062 | self.assertEqual(r, False) |
| 3063 | |
| 3064 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3065 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3066 | r = client.enqueue(tenant='tenant-one', |
| 3067 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3068 | project='project-does-not-exist', |
| 3069 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3070 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3071 | client.shutdown() |
| 3072 | self.assertEqual(r, False) |
| 3073 | |
| 3074 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3075 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3076 | r = client.enqueue(tenant='tenant-one', |
| 3077 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3078 | project='org/project', |
| 3079 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3080 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3081 | client.shutdown() |
| 3082 | self.assertEqual(r, False) |
| 3083 | |
| 3084 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3085 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3086 | r = client.enqueue(tenant='tenant-one', |
| 3087 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3088 | project='org/project', |
| 3089 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3090 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3091 | client.shutdown() |
| 3092 | self.assertEqual(r, False) |
| 3093 | |
| 3094 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3095 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3096 | r = client.enqueue(tenant='tenant-one', |
| 3097 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3098 | project='org/project', |
| 3099 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3100 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3101 | client.shutdown() |
| 3102 | self.assertEqual(r, False) |
| 3103 | |
| 3104 | self.waitUntilSettled() |
| 3105 | self.assertEqual(len(self.history), 0) |
| 3106 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3107 | |
| 3108 | def test_client_promote(self): |
| 3109 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3110 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3111 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3112 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3113 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3114 | A.addApproval('code-review', 2) |
| 3115 | B.addApproval('code-review', 2) |
| 3116 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3117 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3118 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3119 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3120 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3121 | |
| 3122 | self.waitUntilSettled() |
| 3123 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3124 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3125 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3126 | enqueue_times = {} |
| 3127 | for item in items: |
| 3128 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3129 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3130 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3131 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3132 | r = client.promote(tenant='tenant-one', |
| 3133 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3134 | change_ids=['2,1', '3,1']) |
| 3135 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3136 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3137 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3138 | for item in items: |
| 3139 | self.assertEqual( |
| 3140 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3141 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3142 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3143 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3144 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3145 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3146 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3147 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3148 | self.waitUntilSettled() |
| 3149 | |
| 3150 | self.assertEqual(len(self.builds), 6) |
| 3151 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3152 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3153 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3154 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3155 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3156 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3157 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3158 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3159 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3160 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3161 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3162 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3163 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3164 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3166 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3167 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3168 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3169 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3170 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3171 | self.waitUntilSettled() |
| 3172 | |
| 3173 | self.assertEqual(A.data['status'], 'MERGED') |
| 3174 | self.assertEqual(A.reported, 2) |
| 3175 | self.assertEqual(B.data['status'], 'MERGED') |
| 3176 | self.assertEqual(B.reported, 2) |
| 3177 | self.assertEqual(C.data['status'], 'MERGED') |
| 3178 | self.assertEqual(C.reported, 2) |
| 3179 | |
| 3180 | client.shutdown() |
| 3181 | self.assertEqual(r, True) |
| 3182 | |
| 3183 | def test_client_promote_dependent(self): |
| 3184 | "Test that the RPC client can promote a dependent change" |
| 3185 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3186 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3187 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3188 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3189 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3190 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3191 | |
| 3192 | C.setDependsOn(B, 1) |
| 3193 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3194 | A.addApproval('code-review', 2) |
| 3195 | B.addApproval('code-review', 2) |
| 3196 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3197 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3198 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3199 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3200 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3201 | |
| 3202 | self.waitUntilSettled() |
| 3203 | |
| 3204 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3205 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | r = client.promote(tenant='tenant-one', |
| 3207 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3208 | change_ids=['3,1']) |
| 3209 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3211 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3212 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3213 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3214 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3215 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3216 | self.waitUntilSettled() |
| 3217 | |
| 3218 | self.assertEqual(len(self.builds), 6) |
| 3219 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3220 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3221 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3222 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3223 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3224 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3225 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3226 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3227 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3228 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3229 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3230 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3231 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3232 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3233 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3234 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3235 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3236 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3237 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3238 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3239 | self.waitUntilSettled() |
| 3240 | |
| 3241 | self.assertEqual(A.data['status'], 'MERGED') |
| 3242 | self.assertEqual(A.reported, 2) |
| 3243 | self.assertEqual(B.data['status'], 'MERGED') |
| 3244 | self.assertEqual(B.reported, 2) |
| 3245 | self.assertEqual(C.data['status'], 'MERGED') |
| 3246 | self.assertEqual(C.reported, 2) |
| 3247 | |
| 3248 | client.shutdown() |
| 3249 | self.assertEqual(r, True) |
| 3250 | |
| 3251 | def test_client_promote_negative(self): |
| 3252 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3253 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3254 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3255 | A.addApproval('code-review', 2) |
| 3256 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | self.waitUntilSettled() |
| 3258 | |
| 3259 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3260 | self.gearman_server.port) |
| 3261 | |
| 3262 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3263 | r = client.promote(tenant='tenant-one', |
| 3264 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3265 | change_ids=['2,1', '3,1']) |
| 3266 | client.shutdown() |
| 3267 | self.assertEqual(r, False) |
| 3268 | |
| 3269 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3270 | r = client.promote(tenant='tenant-one', |
| 3271 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3272 | change_ids=['4,1']) |
| 3273 | client.shutdown() |
| 3274 | self.assertEqual(r, False) |
| 3275 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3276 | self.launch_server.hold_jobs_in_build = False |
| 3277 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3278 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3279 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3280 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3281 | def test_queue_rate_limiting(self): |
| 3282 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3283 | self.updateConfigLayout( |
| 3284 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3285 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3286 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3287 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3288 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3289 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3290 | |
| 3291 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3292 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3293 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3294 | A.addApproval('code-review', 2) |
| 3295 | B.addApproval('code-review', 2) |
| 3296 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3297 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3298 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3299 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3300 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3301 | self.waitUntilSettled() |
| 3302 | |
| 3303 | # Only A and B will have their merge jobs queued because |
| 3304 | # window is 2. |
| 3305 | self.assertEqual(len(self.builds), 2) |
| 3306 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3307 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3308 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3309 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3310 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3311 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3312 | self.waitUntilSettled() |
| 3313 | |
| 3314 | # Only A and B will have their test jobs queued because |
| 3315 | # window is 2. |
| 3316 | self.assertEqual(len(self.builds), 4) |
| 3317 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3318 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3319 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3320 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3321 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3322 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3323 | self.waitUntilSettled() |
| 3324 | |
| 3325 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3326 | # A failed so window is reduced by 1 to 1. |
| 3327 | self.assertEqual(queue.window, 1) |
| 3328 | self.assertEqual(queue.window_floor, 1) |
| 3329 | self.assertEqual(A.data['status'], 'NEW') |
| 3330 | |
| 3331 | # Gate is reset and only B's merge job is queued because |
| 3332 | # window shrunk to 1. |
| 3333 | self.assertEqual(len(self.builds), 1) |
| 3334 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3335 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3336 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3337 | self.waitUntilSettled() |
| 3338 | |
| 3339 | # Only B's test jobs are queued because window is still 1. |
| 3340 | self.assertEqual(len(self.builds), 2) |
| 3341 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3342 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3343 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3344 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3345 | self.waitUntilSettled() |
| 3346 | |
| 3347 | # B was successfully merged so window is increased to 2. |
| 3348 | self.assertEqual(queue.window, 2) |
| 3349 | self.assertEqual(queue.window_floor, 1) |
| 3350 | self.assertEqual(B.data['status'], 'MERGED') |
| 3351 | |
| 3352 | # Only C is left and its merge job is queued. |
| 3353 | self.assertEqual(len(self.builds), 1) |
| 3354 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3355 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3356 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3357 | self.waitUntilSettled() |
| 3358 | |
| 3359 | # After successful merge job the test jobs for C are queued. |
| 3360 | self.assertEqual(len(self.builds), 2) |
| 3361 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3362 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3363 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3364 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3365 | self.waitUntilSettled() |
| 3366 | |
| 3367 | # C successfully merged so window is bumped to 3. |
| 3368 | self.assertEqual(queue.window, 3) |
| 3369 | self.assertEqual(queue.window_floor, 1) |
| 3370 | self.assertEqual(C.data['status'], 'MERGED') |
| 3371 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3372 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3373 | def test_queue_rate_limiting_dependent(self): |
| 3374 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3375 | self.updateConfigLayout( |
| 3376 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3377 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3378 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3379 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3380 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3381 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3382 | |
| 3383 | B.setDependsOn(A, 1) |
| 3384 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3385 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3386 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3387 | A.addApproval('code-review', 2) |
| 3388 | B.addApproval('code-review', 2) |
| 3389 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3390 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3391 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3392 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3393 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3394 | self.waitUntilSettled() |
| 3395 | |
| 3396 | # Only A and B will have their merge jobs queued because |
| 3397 | # window is 2. |
| 3398 | self.assertEqual(len(self.builds), 2) |
| 3399 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3400 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3401 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3402 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3403 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3404 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3405 | self.waitUntilSettled() |
| 3406 | |
| 3407 | # Only A and B will have their test jobs queued because |
| 3408 | # window is 2. |
| 3409 | self.assertEqual(len(self.builds), 4) |
| 3410 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3411 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3412 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3413 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3414 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3415 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3416 | self.waitUntilSettled() |
| 3417 | |
| 3418 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3419 | # A failed so window is reduced by 1 to 1. |
| 3420 | self.assertEqual(queue.window, 1) |
| 3421 | self.assertEqual(queue.window_floor, 1) |
| 3422 | self.assertEqual(A.data['status'], 'NEW') |
| 3423 | self.assertEqual(B.data['status'], 'NEW') |
| 3424 | |
| 3425 | # Gate is reset and only C's merge job is queued because |
| 3426 | # window shrunk to 1 and A and B were dequeued. |
| 3427 | self.assertEqual(len(self.builds), 1) |
| 3428 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3429 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3430 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3431 | self.waitUntilSettled() |
| 3432 | |
| 3433 | # Only C's test jobs are queued because window is still 1. |
| 3434 | self.assertEqual(len(self.builds), 2) |
| 3435 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3436 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3437 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3438 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3439 | self.waitUntilSettled() |
| 3440 | |
| 3441 | # C was successfully merged so window is increased to 2. |
| 3442 | self.assertEqual(queue.window, 2) |
| 3443 | self.assertEqual(queue.window_floor, 1) |
| 3444 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3445 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3446 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3447 | def test_worker_update_metadata(self): |
| 3448 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3449 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3450 | |
| 3451 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3452 | A.addApproval('code-review', 2) |
| 3453 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3454 | self.waitUntilSettled() |
| 3455 | |
| 3456 | self.assertEqual(len(self.launcher.builds), 1) |
| 3457 | |
| 3458 | self.log.debug('Current builds:') |
| 3459 | self.log.debug(self.launcher.builds) |
| 3460 | |
| 3461 | start = time.time() |
| 3462 | while True: |
| 3463 | if time.time() - start > 10: |
| 3464 | raise Exception("Timeout waiting for gearman server to report " |
| 3465 | + "back to the client") |
| 3466 | build = self.launcher.builds.values()[0] |
| 3467 | if build.worker.name == "My Worker": |
| 3468 | break |
| 3469 | else: |
| 3470 | time.sleep(0) |
| 3471 | |
| 3472 | self.log.debug(build) |
| 3473 | self.assertEqual("My Worker", build.worker.name) |
| 3474 | self.assertEqual("localhost", build.worker.hostname) |
| 3475 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3476 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3477 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3478 | self.assertEqual("v1.1", build.worker.version) |
| 3479 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3480 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3481 | self.launch_server.hold_jobs_in_build = False |
| 3482 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3483 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3484 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3485 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3486 | def test_footer_message(self): |
| 3487 | "Test a pipeline's footer message is correctly added to the report." |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3488 | self.updateConfigLayout( |
| 3489 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3490 | self.sched.reconfigure(self.config) |
| 3491 | self.registerJobs() |
| 3492 | |
| 3493 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3494 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3495 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3496 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3497 | self.waitUntilSettled() |
| 3498 | |
| 3499 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3500 | B.addApproval('code-review', 2) |
| 3501 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3502 | self.waitUntilSettled() |
| 3503 | |
| 3504 | self.assertEqual(2, len(self.smtp_messages)) |
| 3505 | |
| 3506 | failure_body = """\ |
| 3507 | Build failed. For information on how to proceed, see \ |
| 3508 | http://wiki.example.org/Test_Failures |
| 3509 | |
| 3510 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3511 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3512 | |
| 3513 | For CI problems and help debugging, contact ci@example.org""" |
| 3514 | |
| 3515 | success_body = """\ |
| 3516 | Build succeeded. |
| 3517 | |
| 3518 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3519 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3520 | |
| 3521 | For CI problems and help debugging, contact ci@example.org""" |
| 3522 | |
| 3523 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3524 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3525 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3526 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3527 | def test_merge_failure_reporters(self): |
| 3528 | """Check that the config is set up correctly""" |
| 3529 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3530 | self.updateConfigLayout( |
| 3531 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3532 | self.sched.reconfigure(self.config) |
| 3533 | self.registerJobs() |
| 3534 | |
| 3535 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3536 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3537 | "dependencies was unable to be automatically merged with the " |
| 3538 | "current state of its repository. Please rebase the change and " |
| 3539 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3540 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3541 | self.assertEqual( |
| 3542 | "The merge failed! For more information...", |
| 3543 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3544 | |
| 3545 | self.assertEqual( |
| 3546 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3547 | self.assertEqual( |
| 3548 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3549 | |
| 3550 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3551 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3552 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3553 | |
| 3554 | self.assertTrue( |
| 3555 | ( |
| 3556 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3557 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3558 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3559 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3560 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3561 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3562 | ) or ( |
| 3563 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3564 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3565 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3566 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3567 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3568 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3569 | ) |
| 3570 | ) |
| 3571 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3572 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3573 | def test_merge_failure_reports(self): |
| 3574 | """Check that when a change fails to merge the correct message is sent |
| 3575 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3576 | self.updateConfigLayout( |
| 3577 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3578 | self.sched.reconfigure(self.config) |
| 3579 | self.registerJobs() |
| 3580 | |
| 3581 | # Check a test failure isn't reported to SMTP |
| 3582 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3583 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3584 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3585 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3586 | self.waitUntilSettled() |
| 3587 | |
| 3588 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3589 | self.assertEqual(0, len(self.smtp_messages)) |
| 3590 | |
| 3591 | # Check a merge failure is reported to SMTP |
| 3592 | # B should be merged, but C will conflict with B |
| 3593 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3594 | B.addPatchset(['conflict']) |
| 3595 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3596 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3597 | B.addApproval('code-review', 2) |
| 3598 | C.addApproval('code-review', 2) |
| 3599 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3600 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3601 | self.waitUntilSettled() |
| 3602 | |
| 3603 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3604 | self.assertEqual(1, len(self.smtp_messages)) |
| 3605 | self.assertEqual('The merge failed! For more information...', |
| 3606 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3607 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3608 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3609 | def test_default_merge_failure_reports(self): |
| 3610 | """Check that the default merge failure reports are correct.""" |
| 3611 | |
| 3612 | # A should report success, B should report merge failure. |
| 3613 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3614 | A.addPatchset(['conflict']) |
| 3615 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3616 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3617 | A.addApproval('code-review', 2) |
| 3618 | B.addApproval('code-review', 2) |
| 3619 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3620 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3621 | self.waitUntilSettled() |
| 3622 | |
| 3623 | self.assertEqual(3, len(self.history)) # A jobs |
| 3624 | self.assertEqual(A.reported, 2) |
| 3625 | self.assertEqual(B.reported, 2) |
| 3626 | self.assertEqual(A.data['status'], 'MERGED') |
| 3627 | self.assertEqual(B.data['status'], 'NEW') |
| 3628 | self.assertIn('Build succeeded', A.messages[1]) |
| 3629 | self.assertIn('Merge Failed', B.messages[1]) |
| 3630 | self.assertIn('automatically merged', B.messages[1]) |
| 3631 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3632 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3633 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3634 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3635 | def test_swift_instructions(self): |
| 3636 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3637 | self.updateConfigLayout( |
| 3638 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3639 | self.sched.reconfigure(self.config) |
| 3640 | self.registerJobs() |
| 3641 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3642 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3643 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3644 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3645 | A.addApproval('code-review', 2) |
| 3646 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3647 | self.waitUntilSettled() |
| 3648 | |
| 3649 | self.assertEqual( |
| 3650 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3651 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3652 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3653 | self.assertEqual(5, |
| 3654 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3655 | split('\n'))) |
| 3656 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3657 | |
| 3658 | self.assertEqual( |
| 3659 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3660 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3661 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3662 | self.assertEqual(5, |
| 3663 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3664 | split('\n'))) |
| 3665 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3666 | |
| 3667 | self.assertEqual( |
| 3668 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3669 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3670 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3671 | self.assertEqual(5, |
| 3672 | len(self.builds[1]. |
| 3673 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3674 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3675 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3676 | self.launch_server.hold_jobs_in_build = False |
| 3677 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3678 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3679 | |
| 3680 | def test_client_get_running_jobs(self): |
| 3681 | "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] | 3682 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3683 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3684 | A.addApproval('code-review', 2) |
| 3685 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3686 | self.waitUntilSettled() |
| 3687 | |
| 3688 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3689 | self.gearman_server.port) |
| 3690 | |
| 3691 | # Wait for gearman server to send the initial workData back to zuul |
| 3692 | start = time.time() |
| 3693 | while True: |
| 3694 | if time.time() - start > 10: |
| 3695 | raise Exception("Timeout waiting for gearman server to report " |
| 3696 | + "back to the client") |
Clint Byrum | 78a6977 | 2016-12-05 10:52:07 -0800 | [diff] [blame] | 3697 | build = self.launch_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3698 | if build.worker.name == "My Worker": |
| 3699 | break |
| 3700 | else: |
| 3701 | time.sleep(0) |
| 3702 | |
| 3703 | running_items = client.get_running_jobs() |
| 3704 | |
| 3705 | self.assertEqual(1, len(running_items)) |
| 3706 | running_item = running_items[0] |
| 3707 | self.assertEqual([], running_item['failing_reasons']) |
| 3708 | self.assertEqual([], running_item['items_behind']) |
| 3709 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3710 | self.assertEqual(None, running_item['item_ahead']) |
| 3711 | self.assertEqual('org/project', running_item['project']) |
| 3712 | self.assertEqual(None, running_item['remaining_time']) |
| 3713 | self.assertEqual(True, running_item['active']) |
| 3714 | self.assertEqual('1,1', running_item['id']) |
| 3715 | |
| 3716 | self.assertEqual(3, len(running_item['jobs'])) |
| 3717 | for job in running_item['jobs']: |
| 3718 | if job['name'] == 'project-merge': |
| 3719 | self.assertEqual('project-merge', job['name']) |
| 3720 | self.assertEqual('gate', job['pipeline']) |
| 3721 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3722 | self.assertEqual('https://server/job/project-merge/0/', |
| 3723 | job['url']) |
| 3724 | self.assertEqual(7, len(job['worker'])) |
| 3725 | self.assertEqual(False, job['canceled']) |
| 3726 | self.assertEqual(True, job['voting']) |
| 3727 | self.assertEqual(None, job['result']) |
| 3728 | self.assertEqual('gate', job['pipeline']) |
| 3729 | break |
| 3730 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3731 | self.launch_server.hold_jobs_in_build = False |
| 3732 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3733 | self.waitUntilSettled() |
| 3734 | |
| 3735 | running_items = client.get_running_jobs() |
| 3736 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3737 | |
| 3738 | def test_nonvoting_pipeline(self): |
| 3739 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3740 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3741 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3742 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3743 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3744 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3745 | |
| 3746 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3747 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3748 | self.assertEqual( |
| 3749 | self.getJobFromHistory('experimental-project-test').result, |
| 3750 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3751 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3752 | |
| 3753 | def test_crd_gate(self): |
| 3754 | "Test cross-repo dependencies" |
| 3755 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3756 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3757 | A.addApproval('code-review', 2) |
| 3758 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3759 | |
| 3760 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3761 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3762 | AM2.setMerged() |
| 3763 | AM1.setMerged() |
| 3764 | |
| 3765 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3766 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3767 | BM2.setMerged() |
| 3768 | BM1.setMerged() |
| 3769 | |
| 3770 | # A -> AM1 -> AM2 |
| 3771 | # B -> BM1 -> BM2 |
| 3772 | # A Depends-On: B |
| 3773 | # M2 is here to make sure it is never queried. If it is, it |
| 3774 | # means zuul is walking down the entire history of merged |
| 3775 | # changes. |
| 3776 | |
| 3777 | B.setDependsOn(BM1, 1) |
| 3778 | BM1.setDependsOn(BM2, 1) |
| 3779 | |
| 3780 | A.setDependsOn(AM1, 1) |
| 3781 | AM1.setDependsOn(AM2, 1) |
| 3782 | |
| 3783 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3784 | A.subject, B.data['id']) |
| 3785 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3786 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3787 | self.waitUntilSettled() |
| 3788 | |
| 3789 | self.assertEqual(A.data['status'], 'NEW') |
| 3790 | self.assertEqual(B.data['status'], 'NEW') |
| 3791 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3792 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3793 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3794 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3795 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3796 | B.addApproval('approved', 1) |
| 3797 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3798 | self.waitUntilSettled() |
| 3799 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3800 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3801 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3802 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3803 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3804 | self.launch_server.hold_jobs_in_build = False |
| 3805 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3806 | self.waitUntilSettled() |
| 3807 | |
| 3808 | self.assertEqual(AM2.queried, 0) |
| 3809 | self.assertEqual(BM2.queried, 0) |
| 3810 | self.assertEqual(A.data['status'], 'MERGED') |
| 3811 | self.assertEqual(B.data['status'], 'MERGED') |
| 3812 | self.assertEqual(A.reported, 2) |
| 3813 | self.assertEqual(B.reported, 2) |
| 3814 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3815 | changes = self.getJobFromHistory( |
| 3816 | 'project-merge', 'org/project1').changes |
| 3817 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3818 | |
| 3819 | def test_crd_branch(self): |
| 3820 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3821 | |
| 3822 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3823 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3824 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3825 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3826 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3827 | A.addApproval('code-review', 2) |
| 3828 | B.addApproval('code-review', 2) |
| 3829 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3830 | |
| 3831 | # A Depends-On: B+C |
| 3832 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3833 | A.subject, B.data['id']) |
| 3834 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3835 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3836 | B.addApproval('approved', 1) |
| 3837 | C.addApproval('approved', 1) |
| 3838 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3839 | self.waitUntilSettled() |
| 3840 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3841 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3842 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3843 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3844 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3845 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3846 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3847 | self.launch_server.hold_jobs_in_build = False |
| 3848 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3849 | self.waitUntilSettled() |
| 3850 | |
| 3851 | self.assertEqual(A.data['status'], 'MERGED') |
| 3852 | self.assertEqual(B.data['status'], 'MERGED') |
| 3853 | self.assertEqual(C.data['status'], 'MERGED') |
| 3854 | self.assertEqual(A.reported, 2) |
| 3855 | self.assertEqual(B.reported, 2) |
| 3856 | self.assertEqual(C.reported, 2) |
| 3857 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3858 | changes = self.getJobFromHistory( |
| 3859 | 'project-merge', 'org/project1').changes |
| 3860 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3861 | |
| 3862 | def test_crd_multiline(self): |
| 3863 | "Test multiple depends-on lines in commit" |
| 3864 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3865 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3866 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3867 | A.addApproval('code-review', 2) |
| 3868 | B.addApproval('code-review', 2) |
| 3869 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3870 | |
| 3871 | # A Depends-On: B+C |
| 3872 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3873 | A.subject, B.data['id'], C.data['id']) |
| 3874 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3875 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3876 | B.addApproval('approved', 1) |
| 3877 | C.addApproval('approved', 1) |
| 3878 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3879 | self.waitUntilSettled() |
| 3880 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3881 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3882 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3883 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3884 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3885 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3886 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3887 | self.launch_server.hold_jobs_in_build = False |
| 3888 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3889 | self.waitUntilSettled() |
| 3890 | |
| 3891 | self.assertEqual(A.data['status'], 'MERGED') |
| 3892 | self.assertEqual(B.data['status'], 'MERGED') |
| 3893 | self.assertEqual(C.data['status'], 'MERGED') |
| 3894 | self.assertEqual(A.reported, 2) |
| 3895 | self.assertEqual(B.reported, 2) |
| 3896 | self.assertEqual(C.reported, 2) |
| 3897 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3898 | changes = self.getJobFromHistory( |
| 3899 | 'project-merge', 'org/project1').changes |
| 3900 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3901 | |
| 3902 | def test_crd_unshared_gate(self): |
| 3903 | "Test cross-repo dependencies in unshared gate queues" |
| 3904 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3905 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3906 | A.addApproval('code-review', 2) |
| 3907 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3908 | |
| 3909 | # A Depends-On: B |
| 3910 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3911 | A.subject, B.data['id']) |
| 3912 | |
| 3913 | # A and B do not share a queue, make sure that A is unable to |
| 3914 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3915 | B.addApproval('approved', 1) |
| 3916 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3917 | self.waitUntilSettled() |
| 3918 | |
| 3919 | self.assertEqual(A.data['status'], 'NEW') |
| 3920 | self.assertEqual(B.data['status'], 'NEW') |
| 3921 | self.assertEqual(A.reported, 0) |
| 3922 | self.assertEqual(B.reported, 0) |
| 3923 | self.assertEqual(len(self.history), 0) |
| 3924 | |
| 3925 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3926 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3927 | self.waitUntilSettled() |
| 3928 | |
| 3929 | self.assertEqual(B.data['status'], 'MERGED') |
| 3930 | self.assertEqual(B.reported, 2) |
| 3931 | |
| 3932 | # Now that B is merged, A should be able to be enqueued and |
| 3933 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3934 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3935 | self.waitUntilSettled() |
| 3936 | |
| 3937 | self.assertEqual(A.data['status'], 'MERGED') |
| 3938 | self.assertEqual(A.reported, 2) |
| 3939 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3940 | def test_crd_gate_reverse(self): |
| 3941 | "Test reverse cross-repo dependencies" |
| 3942 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3943 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3944 | A.addApproval('code-review', 2) |
| 3945 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3946 | |
| 3947 | # A Depends-On: B |
| 3948 | |
| 3949 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3950 | A.subject, B.data['id']) |
| 3951 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3952 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3953 | self.waitUntilSettled() |
| 3954 | |
| 3955 | self.assertEqual(A.data['status'], 'NEW') |
| 3956 | self.assertEqual(B.data['status'], 'NEW') |
| 3957 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3958 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3959 | A.addApproval('approved', 1) |
| 3960 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3961 | self.waitUntilSettled() |
| 3962 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3963 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3964 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3965 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3966 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3967 | self.launch_server.hold_jobs_in_build = False |
| 3968 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3969 | self.waitUntilSettled() |
| 3970 | |
| 3971 | self.assertEqual(A.data['status'], 'MERGED') |
| 3972 | self.assertEqual(B.data['status'], 'MERGED') |
| 3973 | self.assertEqual(A.reported, 2) |
| 3974 | self.assertEqual(B.reported, 2) |
| 3975 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3976 | changes = self.getJobFromHistory( |
| 3977 | 'project-merge', 'org/project1').changes |
| 3978 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3979 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3980 | def test_crd_cycle(self): |
| 3981 | "Test cross-repo dependency cycles" |
| 3982 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3983 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3984 | A.addApproval('code-review', 2) |
| 3985 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3986 | |
| 3987 | # A -> B -> A (via commit-depends) |
| 3988 | |
| 3989 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3990 | A.subject, B.data['id']) |
| 3991 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3992 | B.subject, A.data['id']) |
| 3993 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3994 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3995 | self.waitUntilSettled() |
| 3996 | |
| 3997 | self.assertEqual(A.reported, 0) |
| 3998 | self.assertEqual(B.reported, 0) |
| 3999 | self.assertEqual(A.data['status'], 'NEW') |
| 4000 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4001 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4002 | def test_crd_gate_unknown(self): |
| 4003 | "Test unknown projects in dependent pipeline" |
| 4004 | self.init_repo("org/unknown") |
| 4005 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4006 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4007 | A.addApproval('code-review', 2) |
| 4008 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4009 | |
| 4010 | # A Depends-On: B |
| 4011 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4012 | A.subject, B.data['id']) |
| 4013 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4014 | B.addApproval('approved', 1) |
| 4015 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4016 | self.waitUntilSettled() |
| 4017 | |
| 4018 | # Unknown projects cannot share a queue with any other |
| 4019 | # since they don't have common jobs with any other (they have no jobs). |
| 4020 | # Changes which depend on unknown project changes |
| 4021 | # should not be processed in dependent pipeline |
| 4022 | self.assertEqual(A.data['status'], 'NEW') |
| 4023 | self.assertEqual(B.data['status'], 'NEW') |
| 4024 | self.assertEqual(A.reported, 0) |
| 4025 | self.assertEqual(B.reported, 0) |
| 4026 | self.assertEqual(len(self.history), 0) |
| 4027 | |
| 4028 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4029 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4030 | B.setMerged() |
| 4031 | self.waitUntilSettled() |
| 4032 | self.assertEqual(len(self.history), 0) |
| 4033 | |
| 4034 | # Now that B is merged, A should be able to be enqueued and |
| 4035 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4036 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4037 | self.waitUntilSettled() |
| 4038 | |
| 4039 | self.assertEqual(A.data['status'], 'MERGED') |
| 4040 | self.assertEqual(A.reported, 2) |
| 4041 | self.assertEqual(B.data['status'], 'MERGED') |
| 4042 | self.assertEqual(B.reported, 0) |
| 4043 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4044 | def test_crd_check(self): |
| 4045 | "Test cross-repo dependencies in independent pipelines" |
| 4046 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4047 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4048 | self.gearman_server.hold_jobs_in_queue = True |
| 4049 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4050 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4051 | |
| 4052 | # A Depends-On: B |
| 4053 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4054 | A.subject, B.data['id']) |
| 4055 | |
| 4056 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4057 | self.waitUntilSettled() |
| 4058 | |
| 4059 | queue = self.gearman_server.getQueue() |
| 4060 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4061 | self.gearman_server.hold_jobs_in_queue = False |
| 4062 | self.gearman_server.release() |
| 4063 | self.waitUntilSettled() |
| 4064 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4065 | self.launch_server.release('.*-merge') |
| 4066 | self.waitUntilSettled() |
| 4067 | |
| 4068 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4069 | repo = git.Repo(path) |
| 4070 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4071 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4072 | correct_messages = [ |
| 4073 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4074 | self.assertEqual(repo_messages, correct_messages) |
| 4075 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4076 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4077 | repo = git.Repo(path) |
| 4078 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4079 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4080 | correct_messages = [ |
| 4081 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4082 | self.assertEqual(repo_messages, correct_messages) |
| 4083 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4084 | self.launch_server.hold_jobs_in_build = False |
| 4085 | self.launch_server.release() |
| 4086 | self.waitUntilSettled() |
| 4087 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4088 | self.assertEqual(A.data['status'], 'NEW') |
| 4089 | self.assertEqual(B.data['status'], 'NEW') |
| 4090 | self.assertEqual(A.reported, 1) |
| 4091 | self.assertEqual(B.reported, 0) |
| 4092 | |
| 4093 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4094 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4095 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4096 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4097 | def test_crd_check_git_depends(self): |
| 4098 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4099 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4100 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4101 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4102 | |
| 4103 | # Add two git-dependent changes and make sure they both report |
| 4104 | # success. |
| 4105 | B.setDependsOn(A, 1) |
| 4106 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4107 | self.waitUntilSettled() |
| 4108 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4109 | self.waitUntilSettled() |
| 4110 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4111 | self.orderedRelease() |
| 4112 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4113 | self.waitUntilSettled() |
| 4114 | |
| 4115 | self.assertEqual(A.data['status'], 'NEW') |
| 4116 | self.assertEqual(B.data['status'], 'NEW') |
| 4117 | self.assertEqual(A.reported, 1) |
| 4118 | self.assertEqual(B.reported, 1) |
| 4119 | |
| 4120 | self.assertEqual(self.history[0].changes, '1,1') |
| 4121 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4122 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4123 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4124 | |
| 4125 | self.assertIn('Build succeeded', A.messages[0]) |
| 4126 | self.assertIn('Build succeeded', B.messages[0]) |
| 4127 | |
| 4128 | def test_crd_check_duplicate(self): |
| 4129 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4130 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4131 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4132 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4133 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4134 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4135 | |
| 4136 | # Add two git-dependent changes... |
| 4137 | B.setDependsOn(A, 1) |
| 4138 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4139 | self.waitUntilSettled() |
| 4140 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4141 | |
| 4142 | # ...make sure the live one is not duplicated... |
| 4143 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4144 | self.waitUntilSettled() |
| 4145 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4146 | |
| 4147 | # ...but the non-live one is able to be. |
| 4148 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4149 | self.waitUntilSettled() |
| 4150 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4151 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4152 | # Release jobs in order to avoid races with change A jobs |
| 4153 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4154 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4155 | self.launch_server.hold_jobs_in_build = False |
| 4156 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4157 | self.waitUntilSettled() |
| 4158 | |
| 4159 | self.assertEqual(A.data['status'], 'NEW') |
| 4160 | self.assertEqual(B.data['status'], 'NEW') |
| 4161 | self.assertEqual(A.reported, 1) |
| 4162 | self.assertEqual(B.reported, 1) |
| 4163 | |
| 4164 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4165 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4166 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4167 | |
| 4168 | self.assertIn('Build succeeded', A.messages[0]) |
| 4169 | self.assertIn('Build succeeded', B.messages[0]) |
| 4170 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4171 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4172 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4173 | |
| 4174 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4175 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4176 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4177 | |
| 4178 | # A Depends-On: B |
| 4179 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4180 | A.subject, B.data['id']) |
| 4181 | |
| 4182 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4183 | self.waitUntilSettled() |
| 4184 | |
| 4185 | self.sched.reconfigure(self.config) |
| 4186 | |
| 4187 | # Make sure the items still share a change queue, and the |
| 4188 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4189 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4190 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4191 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4192 | first_item = queue.queue[0] |
| 4193 | for item in queue.queue: |
| 4194 | self.assertEqual(item.queue, first_item.queue) |
| 4195 | self.assertFalse(first_item.live) |
| 4196 | self.assertTrue(queue.queue[1].live) |
| 4197 | |
| 4198 | self.gearman_server.hold_jobs_in_queue = False |
| 4199 | self.gearman_server.release() |
| 4200 | self.waitUntilSettled() |
| 4201 | |
| 4202 | self.assertEqual(A.data['status'], 'NEW') |
| 4203 | self.assertEqual(B.data['status'], 'NEW') |
| 4204 | self.assertEqual(A.reported, 1) |
| 4205 | self.assertEqual(B.reported, 0) |
| 4206 | |
| 4207 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4208 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4209 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4210 | def test_crd_check_reconfiguration(self): |
| 4211 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4212 | |
| 4213 | def test_crd_undefined_project(self): |
| 4214 | """Test that undefined projects in dependencies are handled for |
| 4215 | independent pipelines""" |
| 4216 | # It's a hack for fake gerrit, |
| 4217 | # as it implies repo creation upon the creation of any change |
| 4218 | self.init_repo("org/unknown") |
| 4219 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4220 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4221 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4222 | def test_crd_check_ignore_dependencies(self): |
| 4223 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4224 | self.updateConfigLayout( |
| 4225 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4226 | self.sched.reconfigure(self.config) |
| 4227 | self.registerJobs() |
| 4228 | |
| 4229 | self.gearman_server.hold_jobs_in_queue = True |
| 4230 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4231 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4232 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4233 | |
| 4234 | # A Depends-On: B |
| 4235 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4236 | A.subject, B.data['id']) |
| 4237 | # C git-depends on B |
| 4238 | C.setDependsOn(B, 1) |
| 4239 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4240 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4241 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4242 | self.waitUntilSettled() |
| 4243 | |
| 4244 | # Make sure none of the items share a change queue, and all |
| 4245 | # are live. |
| 4246 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4247 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4248 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4249 | for item in check_pipeline.getAllItems(): |
| 4250 | self.assertTrue(item.live) |
| 4251 | |
| 4252 | self.gearman_server.hold_jobs_in_queue = False |
| 4253 | self.gearman_server.release() |
| 4254 | self.waitUntilSettled() |
| 4255 | |
| 4256 | self.assertEqual(A.data['status'], 'NEW') |
| 4257 | self.assertEqual(B.data['status'], 'NEW') |
| 4258 | self.assertEqual(C.data['status'], 'NEW') |
| 4259 | self.assertEqual(A.reported, 1) |
| 4260 | self.assertEqual(B.reported, 1) |
| 4261 | self.assertEqual(C.reported, 1) |
| 4262 | |
| 4263 | # Each job should have tested exactly one change |
| 4264 | for job in self.history: |
| 4265 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4266 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4267 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4268 | def test_crd_check_transitive(self): |
| 4269 | "Test transitive cross-repo dependencies" |
| 4270 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4271 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4272 | # and C,2 (not C,1 which would indicate stale data in the |
| 4273 | # cache for B). |
| 4274 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4275 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4276 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4277 | |
| 4278 | # A Depends-On: B |
| 4279 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4280 | A.subject, B.data['id']) |
| 4281 | |
| 4282 | # B Depends-On: C |
| 4283 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4284 | B.subject, C.data['id']) |
| 4285 | |
| 4286 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4287 | self.waitUntilSettled() |
| 4288 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4289 | |
| 4290 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4291 | self.waitUntilSettled() |
| 4292 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4293 | |
| 4294 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4295 | self.waitUntilSettled() |
| 4296 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4297 | |
| 4298 | C.addPatchset() |
| 4299 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4300 | self.waitUntilSettled() |
| 4301 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4302 | |
| 4303 | A.addPatchset() |
| 4304 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4305 | self.waitUntilSettled() |
| 4306 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4307 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4308 | def test_crd_check_unknown(self): |
| 4309 | "Test unknown projects in independent pipeline" |
| 4310 | self.init_repo("org/unknown") |
| 4311 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4312 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4313 | # A Depends-On: B |
| 4314 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4315 | A.subject, B.data['id']) |
| 4316 | |
| 4317 | # Make sure zuul has seen an event on B. |
| 4318 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4319 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4320 | self.waitUntilSettled() |
| 4321 | |
| 4322 | self.assertEqual(A.data['status'], 'NEW') |
| 4323 | self.assertEqual(A.reported, 1) |
| 4324 | self.assertEqual(B.data['status'], 'NEW') |
| 4325 | self.assertEqual(B.reported, 0) |
| 4326 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4327 | def test_crd_cycle_join(self): |
| 4328 | "Test an updated change creates a cycle" |
| 4329 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4330 | |
| 4331 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4332 | self.waitUntilSettled() |
| 4333 | |
| 4334 | # Create B->A |
| 4335 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4336 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4337 | B.subject, A.data['id']) |
| 4338 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4339 | self.waitUntilSettled() |
| 4340 | |
| 4341 | # Update A to add A->B (a cycle). |
| 4342 | A.addPatchset() |
| 4343 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4344 | A.subject, B.data['id']) |
| 4345 | # Normally we would submit the patchset-created event for |
| 4346 | # processing here, however, we have no way of noting whether |
| 4347 | # the dependency cycle detection correctly raised an |
| 4348 | # exception, so instead, we reach into the source driver and |
| 4349 | # call the method that would ultimately be called by the event |
| 4350 | # processing. |
| 4351 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4352 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4353 | source = tenant.layout.pipelines['gate'].source |
| 4354 | |
| 4355 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4356 | # it easier for users to create events for testing. |
| 4357 | event = zuul.model.TriggerEvent() |
| 4358 | event.trigger_name = 'gerrit' |
| 4359 | event.change_number = '1' |
| 4360 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4361 | with testtools.ExpectedException( |
| 4362 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4363 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4364 | self.log.debug("Got expected dependency cycle exception") |
| 4365 | |
| 4366 | # Now if we update B to remove the depends-on, everything |
| 4367 | # should be okay. B; A->B |
| 4368 | |
| 4369 | B.addPatchset() |
| 4370 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4371 | |
| 4372 | source.getChange(event, True) |
| 4373 | event.change_number = '2' |
| 4374 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4375 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4376 | def test_disable_at(self): |
| 4377 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4378 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4379 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4380 | self.sched.reconfigure(self.config) |
| 4381 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4382 | tenant = self.sched.abide.tenants.get('openstack') |
| 4383 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4384 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4385 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4386 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4387 | |
| 4388 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4389 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4390 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4391 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4392 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4393 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4394 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4395 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4396 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4397 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4398 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4399 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4400 | self.launch_server.failJob('project-test1', A) |
| 4401 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4402 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4403 | self.launch_server.failJob('project-test1', D) |
| 4404 | self.launch_server.failJob('project-test1', E) |
| 4405 | self.launch_server.failJob('project-test1', F) |
| 4406 | self.launch_server.failJob('project-test1', G) |
| 4407 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4408 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4409 | self.launch_server.failJob('project-test1', J) |
| 4410 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4411 | |
| 4412 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4413 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4414 | self.waitUntilSettled() |
| 4415 | |
| 4416 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4417 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4418 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4419 | |
| 4420 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4421 | self.waitUntilSettled() |
| 4422 | |
| 4423 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4424 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4425 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4426 | |
| 4427 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4428 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4429 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4430 | self.waitUntilSettled() |
| 4431 | |
| 4432 | # We should be disabled now |
| 4433 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4434 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4435 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4436 | |
| 4437 | # We need to wait between each of these patches to make sure the |
| 4438 | # smtp messages come back in an expected order |
| 4439 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4440 | self.waitUntilSettled() |
| 4441 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4442 | self.waitUntilSettled() |
| 4443 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4444 | self.waitUntilSettled() |
| 4445 | |
| 4446 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4447 | # leaving a message on each change |
| 4448 | self.assertEqual(1, len(A.messages)) |
| 4449 | self.assertIn('Build failed.', A.messages[0]) |
| 4450 | self.assertEqual(1, len(B.messages)) |
| 4451 | self.assertIn('Build failed.', B.messages[0]) |
| 4452 | self.assertEqual(1, len(C.messages)) |
| 4453 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4454 | self.assertEqual(1, len(D.messages)) |
| 4455 | self.assertIn('Build failed.', D.messages[0]) |
| 4456 | self.assertEqual(1, len(E.messages)) |
| 4457 | self.assertIn('Build failed.', E.messages[0]) |
| 4458 | self.assertEqual(1, len(F.messages)) |
| 4459 | self.assertIn('Build failed.', F.messages[0]) |
| 4460 | |
| 4461 | # The last 3 (GHI) would have only reported via smtp. |
| 4462 | self.assertEqual(3, len(self.smtp_messages)) |
| 4463 | self.assertEqual(0, len(G.messages)) |
| 4464 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4465 | self.assertIn( |
| 4466 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4467 | self.assertEqual(0, len(H.messages)) |
| 4468 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4469 | self.assertIn( |
| 4470 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4471 | self.assertEqual(0, len(I.messages)) |
| 4472 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4473 | self.assertIn( |
| 4474 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4475 | |
| 4476 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4477 | # comes out of disabled |
| 4478 | self.sched.reconfigure(self.config) |
| 4479 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4480 | tenant = self.sched.abide.tenants.get('openstack') |
| 4481 | |
| 4482 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4483 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4484 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4485 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4486 | |
| 4487 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4488 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4489 | self.waitUntilSettled() |
| 4490 | |
| 4491 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4492 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4493 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4494 | |
| 4495 | # J and K went back to gerrit |
| 4496 | self.assertEqual(1, len(J.messages)) |
| 4497 | self.assertIn('Build failed.', J.messages[0]) |
| 4498 | self.assertEqual(1, len(K.messages)) |
| 4499 | self.assertIn('Build failed.', K.messages[0]) |
| 4500 | # No more messages reported via smtp |
| 4501 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4502 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4503 | def test_rerun_on_abort(self): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4504 | "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] | 4505 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4506 | self.launch_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4507 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4508 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4509 | self.waitUntilSettled() |
| 4510 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4511 | self.launch_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4512 | self.waitUntilSettled() |
| 4513 | |
| 4514 | self.assertEqual(len(self.builds), 2) |
| 4515 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4516 | self.launch_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4517 | self.waitUntilSettled() |
| 4518 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4519 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4520 | self.assertEqual(len(self.builds), 1, |
| 4521 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4522 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4523 | self.launch_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4524 | self.waitUntilSettled() |
| 4525 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4526 | self.launch_server.hold_jobs_in_build = False |
| 4527 | self.launch_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4528 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4529 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4530 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4531 | self.assertEqual(A.reported, 1) |
| 4532 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4533 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4534 | def test_zookeeper_disconnect(self): |
| 4535 | "Test that jobs are launched after a zookeeper disconnect" |
| 4536 | |
| 4537 | self.fake_nodepool.paused = True |
| 4538 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4539 | A.addApproval('code-review', 2) |
| 4540 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4541 | self.waitUntilSettled() |
| 4542 | |
| 4543 | self.zk.client.stop() |
| 4544 | self.zk.client.start() |
| 4545 | self.fake_nodepool.paused = False |
| 4546 | self.waitUntilSettled() |
| 4547 | |
| 4548 | self.assertEqual(A.data['status'], 'MERGED') |
| 4549 | self.assertEqual(A.reported, 2) |
| 4550 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4551 | def test_nodepool_failure(self): |
| 4552 | "Test that jobs are reported after a nodepool failure" |
| 4553 | |
| 4554 | self.fake_nodepool.paused = True |
| 4555 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4556 | A.addApproval('code-review', 2) |
| 4557 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4558 | self.waitUntilSettled() |
| 4559 | |
| 4560 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4561 | self.fake_nodepool.addFailRequest(req) |
| 4562 | |
| 4563 | self.fake_nodepool.paused = False |
| 4564 | self.waitUntilSettled() |
| 4565 | |
| 4566 | self.assertEqual(A.data['status'], 'NEW') |
| 4567 | self.assertEqual(A.reported, 2) |
| 4568 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4569 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4570 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4571 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4572 | |
| 4573 | class TestDuplicatePipeline(ZuulTestCase): |
| 4574 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4575 | |
| 4576 | def test_duplicate_pipelines(self): |
| 4577 | "Test that a change matching multiple pipelines works" |
| 4578 | |
| 4579 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4580 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4581 | self.waitUntilSettled() |
| 4582 | |
| 4583 | self.assertHistory([ |
| 4584 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4585 | pipeline='dup1'), |
| 4586 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4587 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4588 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4589 | |
| 4590 | self.assertEqual(len(A.messages), 2) |
| 4591 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4592 | if 'dup1' in A.messages[0]: |
| 4593 | self.assertIn('dup1', A.messages[0]) |
| 4594 | self.assertNotIn('dup2', A.messages[0]) |
| 4595 | self.assertIn('project-test1', A.messages[0]) |
| 4596 | self.assertIn('dup2', A.messages[1]) |
| 4597 | self.assertNotIn('dup1', A.messages[1]) |
| 4598 | self.assertIn('project-test1', A.messages[1]) |
| 4599 | else: |
| 4600 | self.assertIn('dup1', A.messages[1]) |
| 4601 | self.assertNotIn('dup2', A.messages[1]) |
| 4602 | self.assertIn('project-test1', A.messages[1]) |
| 4603 | self.assertIn('dup2', A.messages[0]) |
| 4604 | self.assertNotIn('dup1', A.messages[0]) |
| 4605 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4606 | |
| 4607 | |
| 4608 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4609 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4610 | |
| 4611 | def test_one_job_project(self): |
| 4612 | "Test that queueing works with one job" |
| 4613 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4614 | 'master', 'A') |
| 4615 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4616 | 'master', 'B') |
| 4617 | A.addApproval('code-review', 2) |
| 4618 | B.addApproval('code-review', 2) |
| 4619 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4620 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4621 | self.waitUntilSettled() |
| 4622 | |
| 4623 | self.assertEqual(A.data['status'], 'MERGED') |
| 4624 | self.assertEqual(A.reported, 2) |
| 4625 | self.assertEqual(B.data['status'], 'MERGED') |
| 4626 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4627 | |
| 4628 | |
| 4629 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4630 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4631 | |
| 4632 | def test_job_from_templates_launched(self): |
| 4633 | "Test whether a job generated via a template can be launched" |
| 4634 | |
| 4635 | A = self.fake_gerrit.addFakeChange( |
| 4636 | 'org/templated-project', 'master', 'A') |
| 4637 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4638 | self.waitUntilSettled() |
| 4639 | |
| 4640 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4641 | 'SUCCESS') |
| 4642 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4643 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4644 | |
| 4645 | def test_layered_templates(self): |
| 4646 | "Test whether a job generated via a template can be launched" |
| 4647 | |
| 4648 | A = self.fake_gerrit.addFakeChange( |
| 4649 | 'org/layered-project', 'master', 'A') |
| 4650 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4651 | self.waitUntilSettled() |
| 4652 | |
| 4653 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4654 | 'SUCCESS') |
| 4655 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4656 | 'SUCCESS') |
| 4657 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4658 | ).result, 'SUCCESS') |
| 4659 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4660 | ).result, 'SUCCESS') |
| 4661 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4662 | ).result, 'SUCCESS') |
| 4663 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4664 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4665 | |
| 4666 | |
| 4667 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4668 | tenant_config_file = 'config/success-url/main.yaml' |
| 4669 | |
| 4670 | def test_success_url(self): |
| 4671 | "Ensure bad build params are ignored" |
| 4672 | self.sched.reconfigure(self.config) |
| 4673 | self.init_repo('org/docs') |
| 4674 | |
| 4675 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4676 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4677 | self.waitUntilSettled() |
| 4678 | |
| 4679 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4680 | self.assertEqual(len(self.history), 2) |
| 4681 | |
| 4682 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4683 | for build in self.history: |
| 4684 | if build.name == 'docs-draft-test': |
| 4685 | uuid = build.uuid[:7] |
| 4686 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4687 | |
| 4688 | # Two msgs: 'Starting...' + results |
| 4689 | self.assertEqual(len(self.smtp_messages), 2) |
| 4690 | body = self.smtp_messages[1]['body'].splitlines() |
| 4691 | self.assertEqual('Build succeeded.', body[0]) |
| 4692 | |
| 4693 | self.assertIn( |
| 4694 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4695 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4696 | body[2]) |
| 4697 | |
| 4698 | # NOTE: This default URL is currently hard-coded in launcher/server.py |
| 4699 | self.assertIn( |
| 4700 | '- docs-draft-test2 https://server/job', |
| 4701 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4702 | |
| 4703 | |
| 4704 | class TestSchedulerMergeModes(ZuulTestCase): |
| 4705 | tenant_config_file = 'config/merge-modes/main.yaml' |
| 4706 | |
| 4707 | def _test_project_merge_mode(self, mode): |
| 4708 | self.launch_server.keep_jobdir = False |
| 4709 | project = 'org/project-%s' % mode |
| 4710 | self.launch_server.hold_jobs_in_build = True |
| 4711 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4712 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4713 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4714 | A.addApproval('code-review', 2) |
| 4715 | B.addApproval('code-review', 2) |
| 4716 | C.addApproval('code-review', 2) |
| 4717 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4718 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4719 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4720 | self.waitUntilSettled() |
| 4721 | |
| 4722 | build = self.builds[-1] |
| 4723 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4724 | |
| 4725 | path = os.path.join(build.jobdir.git_root, project) |
| 4726 | repo = git.Repo(path) |
| 4727 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4728 | repo_messages.reverse() |
| 4729 | |
| 4730 | self.launch_server.hold_jobs_in_build = False |
| 4731 | self.launch_server.release() |
| 4732 | self.waitUntilSettled() |
| 4733 | |
| 4734 | return repo_messages |
| 4735 | |
| 4736 | def _test_merge(self, mode): |
| 4737 | us_path = os.path.join( |
| 4738 | self.upstream_root, 'org/project-%s' % mode) |
| 4739 | expected_messages = [ |
| 4740 | 'initial commit', |
| 4741 | 'add content from fixture', |
| 4742 | # the intermediate commits order is nondeterministic |
| 4743 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4744 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4745 | ] |
| 4746 | result = self._test_project_merge_mode(mode) |
| 4747 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4748 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4749 | |
| 4750 | def test_project_merge_mode_merge(self): |
| 4751 | self._test_merge('merge') |
| 4752 | |
| 4753 | def test_project_merge_mode_merge_resolve(self): |
| 4754 | self._test_merge('merge-resolve') |
| 4755 | |
| 4756 | def test_project_merge_mode_cherrypick(self): |
| 4757 | expected_messages = [ |
| 4758 | 'initial commit', |
| 4759 | 'add content from fixture', |
| 4760 | 'A-1', |
| 4761 | 'B-1', |
| 4762 | 'C-1'] |
| 4763 | result = self._test_project_merge_mode('cherry-pick') |
| 4764 | self.assertEqual(result, expected_messages) |