blob: 2a74eebb088c869bf03fc35f0f21782061acc6c5 [file] [log] [blame]
James E. Blairb0fcae42012-07-17 11:12:10 -07001#!/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. Blairb0fcae42012-07-17 11:12:10 -070017import json
Monty Taylorbc758832013-06-17 17:22:42 -040018import logging
19import os
James E. Blairb0fcae42012-07-17 11:12:10 -070020import re
James E. Blair4886cc12012-07-18 15:39:41 -070021import shutil
Monty Taylorbc758832013-06-17 17:22:42 -040022import time
Maru Newby3fe5f852015-01-13 04:22:14 +000023import yaml
James E. Blairec056492016-07-22 09:45:56 -070024from unittest import skip
Monty Taylorbc758832013-06-17 17:22:42 -040025
James E. Blair4886cc12012-07-18 15:39:41 -070026import git
Morgan Fainberg293f7f82016-05-30 14:01:22 -070027from six.moves import urllib
Monty Taylorbc758832013-06-17 17:22:42 -040028import testtools
James E. Blairb0fcae42012-07-17 11:12:10 -070029
Maru Newby3fe5f852015-01-13 04:22:14 +000030import zuul.change_matcher
James E. Blairb0fcae42012-07-17 11:12:10 -070031import zuul.scheduler
James E. Blairad28e912013-11-27 10:43:22 -080032import zuul.rpcclient
Joshua Hesketh1879cf72013-08-19 14:13:15 +100033import zuul.reporter.gerrit
Joshua Hesketh5fea8672013-08-19 17:32:01 +100034import zuul.reporter.smtp
James E. Blairb0fcae42012-07-17 11:12:10 -070035
Maru Newby3fe5f852015-01-13 04:22:14 +000036from tests.base import (
Maru Newby3fe5f852015-01-13 04:22:14 +000037 ZuulTestCase,
38 repack_repo,
39)
James E. Blairb0fcae42012-07-17 11:12:10 -070040
James E. Blair1f4c2bb2013-04-26 08:40:46 -070041logging.basicConfig(level=logging.DEBUG,
42 format='%(asctime)s %(name)-32s '
43 '%(levelname)-8s %(message)s')
James E. Blairb0fcae42012-07-17 11:12:10 -070044
45
Clark Boylanb640e052014-04-03 16:41:46 -070046class TestScheduler(ZuulTestCase):
James E. Blair552b54f2016-07-22 13:55:32 -070047 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobd86a312014-01-08 14:51:33 +010048
James E. Blairb0fcae42012-07-17 11:12:10 -070049 def test_jobs_launched(self):
50 "Test that jobs are launched and a change is merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -070051
James E. Blairb0fcae42012-07-17 11:12:10 -070052 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -070053 A.addApproval('code-review', 2)
54 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -070055 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -040056 self.assertEqual(self.getJobFromHistory('project-merge').result,
57 'SUCCESS')
58 self.assertEqual(self.getJobFromHistory('project-test1').result,
59 'SUCCESS')
60 self.assertEqual(self.getJobFromHistory('project-test2').result,
61 'SUCCESS')
62 self.assertEqual(A.data['status'], 'MERGED')
63 self.assertEqual(A.reported, 2)
James E. Blair34776ee2016-08-25 13:53:54 -070064 self.assertEqual(self.getJobFromHistory('project-test1').node,
65 'image1')
James E. Blairb0fcae42012-07-17 11:12:10 -070066
James E. Blair552b54f2016-07-22 13:55:32 -070067 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070068 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
69 self.assertReportedStat('zuul.pipeline.gate.current_changes',
70 value='1|g')
71 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
72 kind='ms')
73 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
74 value='1|c')
75 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
76 self.assertReportedStat('zuul.pipeline.gate.total_changes',
77 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070078 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070079 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
James E. Blair412e5582013-04-22 15:50:12 -070080 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070081 'zuul.pipeline.gate.org.project.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070082
James E. Blair5821bd92015-09-16 08:48:15 -070083 for build in self.builds:
84 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
85
James E. Blair3cb10702013-08-24 08:56:03 -070086 def test_initial_pipeline_gauges(self):
87 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070088 self.assertReportedStat('zuul.pipeline.gate.current_changes',
89 value='0|g')
90 self.assertReportedStat('zuul.pipeline.check.current_changes',
91 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070092
James E. Blair34776ee2016-08-25 13:53:54 -070093 def test_job_branch(self):
94 "Test the correct variant of a job runs on a branch"
95 self.create_branch('org/project', 'stable')
96 A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A')
97 A.addApproval('code-review', 2)
98 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
99 self.waitUntilSettled()
100 self.assertEqual(self.getJobFromHistory('project-test1').result,
101 'SUCCESS')
102 self.assertEqual(self.getJobFromHistory('project-test2').result,
103 'SUCCESS')
104 self.assertEqual(A.data['status'], 'MERGED')
105 self.assertEqual(A.reported, 2,
106 "A should report start and success")
107 self.assertIn('gate', A.messages[1],
108 "A should transit gate")
109 self.assertEqual(self.getJobFromHistory('project-test1').node,
110 'image2')
111
James E. Blairb0fcae42012-07-17 11:12:10 -0700112 def test_parallel_changes(self):
113 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700114
James E. Blair791b5392016-08-03 11:25:56 -0700115 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700116 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
117 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
118 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700119 A.addApproval('code-review', 2)
120 B.addApproval('code-review', 2)
121 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700122
James E. Blair8b5408c2016-08-08 15:37:46 -0700123 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
124 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
125 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700126
127 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400128 self.assertEqual(len(self.builds), 1)
129 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700130 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700131
James E. Blair791b5392016-08-03 11:25:56 -0700132 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700133 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400134 self.assertEqual(len(self.builds), 3)
135 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700136 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400137 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700138 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400139 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700140 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700141
James E. Blair791b5392016-08-03 11:25:56 -0700142 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700143 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400144 self.assertEqual(len(self.builds), 5)
145 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700146 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400147 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700148 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700149
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400150 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700151 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400152 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700153 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700154
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400155 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700156 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700157
James E. Blair791b5392016-08-03 11:25:56 -0700158 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700159 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400160 self.assertEqual(len(self.builds), 6)
161 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700162 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400163 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700164 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700165
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400166 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700167 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400168 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700169 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700170
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400171 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700172 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400173 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700174 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700175
James E. Blair791b5392016-08-03 11:25:56 -0700176 self.launch_server.hold_jobs_in_build = False
177 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700178 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400179 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700180
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400181 self.assertEqual(len(self.history), 9)
182 self.assertEqual(A.data['status'], 'MERGED')
183 self.assertEqual(B.data['status'], 'MERGED')
184 self.assertEqual(C.data['status'], 'MERGED')
185 self.assertEqual(A.reported, 2)
186 self.assertEqual(B.reported, 2)
187 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700188
189 def test_failed_changes(self):
190 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700191 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700192
James E. Blairb02a3bb2012-07-30 17:49:55 -0700193 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
194 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700195 A.addApproval('code-review', 2)
196 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700197
James E. Blair08d19992016-08-10 15:25:31 -0700198 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700199
James E. Blair8b5408c2016-08-08 15:37:46 -0700200 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
201 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700202 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700203 self.assertBuilds([dict(name='project-merge', changes='1,1')])
James E. Blaire2819012013-06-28 17:17:26 -0400204
James E. Blair08d19992016-08-10 15:25:31 -0700205 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400206 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700207 # A/project-merge is complete
208 self.assertBuilds([
209 dict(name='project-test1', changes='1,1'),
210 dict(name='project-test2', changes='1,1'),
211 dict(name='project-merge', changes='1,1 2,1'),
212 ])
James E. Blaire2819012013-06-28 17:17:26 -0400213
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700214 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400215 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700216 # A/project-merge is complete
217 # B/project-merge is complete
218 self.assertBuilds([
219 dict(name='project-test1', changes='1,1'),
220 dict(name='project-test2', changes='1,1'),
221 dict(name='project-test1', changes='1,1 2,1'),
222 dict(name='project-test2', changes='1,1 2,1'),
223 ])
224
225 # Release project-test1 for A which will fail. This will
226 # abort both running B jobs and relaunch project-merge for B.
227 self.builds[0].release()
228 self.waitUntilSettled()
229
230 self.orderedRelease()
231 self.assertHistory([
232 dict(name='project-merge', result='SUCCESS', changes='1,1'),
233 dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'),
234 dict(name='project-test1', result='FAILURE', changes='1,1'),
235 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
236 dict(name='project-test2', result='ABORTED', changes='1,1 2,1'),
237 dict(name='project-test2', result='SUCCESS', changes='1,1'),
238 dict(name='project-merge', result='SUCCESS', changes='2,1'),
239 dict(name='project-test1', result='SUCCESS', changes='2,1'),
240 dict(name='project-test2', result='SUCCESS', changes='2,1'),
James E. Blairb536ecc2016-08-31 10:11:42 -0700241 ], ordered=False)
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700242
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400243 self.assertEqual(A.data['status'], 'NEW')
244 self.assertEqual(B.data['status'], 'MERGED')
245 self.assertEqual(A.reported, 2)
246 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700247
248 def test_independent_queues(self):
249 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700250
James E. Blair08d19992016-08-10 15:25:31 -0700251 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900252 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700253 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
254 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700255 A.addApproval('code-review', 2)
256 B.addApproval('code-review', 2)
257 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700258
James E. Blair8b5408c2016-08-08 15:37:46 -0700259 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
260 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
261 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700262
James E. Blairb02a3bb2012-07-30 17:49:55 -0700263 self.waitUntilSettled()
264
265 # There should be one merge job at the head of each queue running
James E. Blair5f0d49e2016-08-19 09:36:50 -0700266 self.assertBuilds([
267 dict(name='project-merge', changes='1,1'),
268 dict(name='project-merge', changes='2,1'),
269 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700270
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700271 # Release the current merge builds
James E. Blair5f0d49e2016-08-19 09:36:50 -0700272 self.builds[0].release()
273 self.waitUntilSettled()
274 self.builds[0].release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700275 self.waitUntilSettled()
276 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700277 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700278 self.waitUntilSettled()
279
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700280 # All the test builds should be running:
James E. Blair5f0d49e2016-08-19 09:36:50 -0700281 self.assertBuilds([
282 dict(name='project-test1', changes='1,1'),
283 dict(name='project-test2', changes='1,1'),
284 dict(name='project-test1', changes='2,1'),
285 dict(name='project-test2', changes='2,1'),
286 dict(name='project-test1', changes='2,1 3,1'),
287 dict(name='project-test2', changes='2,1 3,1'),
288 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700289
James E. Blair5f0d49e2016-08-19 09:36:50 -0700290 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'),
299 dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'),
300 dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'),
301 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700302
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400303 self.assertEqual(A.data['status'], 'MERGED')
304 self.assertEqual(B.data['status'], 'MERGED')
305 self.assertEqual(C.data['status'], 'MERGED')
306 self.assertEqual(A.reported, 2)
307 self.assertEqual(B.reported, 2)
308 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700309
310 def test_failed_change_at_head(self):
311 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700312
James E. Blair08d19992016-08-10 15:25:31 -0700313 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700314 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
315 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
316 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700317 A.addApproval('code-review', 2)
318 B.addApproval('code-review', 2)
319 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700320
James E. Blair08d19992016-08-10 15:25:31 -0700321 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700322
James E. Blair8b5408c2016-08-08 15:37:46 -0700323 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
324 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
325 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700326
327 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700328
James E. Blairb536ecc2016-08-31 10:11:42 -0700329 self.assertBuilds([
330 dict(name='project-merge', changes='1,1'),
331 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700332
James E. Blair08d19992016-08-10 15:25:31 -0700333 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700334 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700335 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700336 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700337 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700338 self.waitUntilSettled()
339
James E. Blairb536ecc2016-08-31 10:11:42 -0700340 self.assertBuilds([
341 dict(name='project-test1', changes='1,1'),
342 dict(name='project-test2', changes='1,1'),
343 dict(name='project-test1', changes='1,1 2,1'),
344 dict(name='project-test2', changes='1,1 2,1'),
345 dict(name='project-test1', changes='1,1 2,1 3,1'),
346 dict(name='project-test2', changes='1,1 2,1 3,1'),
347 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700348
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400349 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700350 self.waitUntilSettled()
351
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400352 # project-test2, project-merge for B
James E. Blairb536ecc2016-08-31 10:11:42 -0700353 self.assertBuilds([
354 dict(name='project-test2', changes='1,1'),
355 dict(name='project-merge', changes='2,1'),
356 ])
357 # Unordered history comparison because the aborts can finish
358 # in any order.
359 self.assertHistory([
360 dict(name='project-merge', result='SUCCESS',
361 changes='1,1'),
362 dict(name='project-merge', result='SUCCESS',
363 changes='1,1 2,1'),
364 dict(name='project-merge', result='SUCCESS',
365 changes='1,1 2,1 3,1'),
366 dict(name='project-test1', result='FAILURE',
367 changes='1,1'),
368 dict(name='project-test1', result='ABORTED',
369 changes='1,1 2,1'),
370 dict(name='project-test2', result='ABORTED',
371 changes='1,1 2,1'),
372 dict(name='project-test1', result='ABORTED',
373 changes='1,1 2,1 3,1'),
374 dict(name='project-test2', result='ABORTED',
375 changes='1,1 2,1 3,1'),
376 ], ordered=False)
James E. Blaird466dc42012-07-31 10:42:56 -0700377
James E. Blairb536ecc2016-08-31 10:11:42 -0700378 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700379 self.waitUntilSettled()
James E. Blairb536ecc2016-08-31 10:11:42 -0700380 self.launch_server.release('.*-merge')
381 self.waitUntilSettled()
382 self.orderedRelease()
James E. Blaird466dc42012-07-31 10:42:56 -0700383
James E. Blairb536ecc2016-08-31 10:11:42 -0700384 self.assertBuilds([])
385 self.assertHistory([
386 dict(name='project-merge', result='SUCCESS',
387 changes='1,1'),
388 dict(name='project-merge', result='SUCCESS',
389 changes='1,1 2,1'),
390 dict(name='project-merge', result='SUCCESS',
391 changes='1,1 2,1 3,1'),
392 dict(name='project-test1', result='FAILURE',
393 changes='1,1'),
394 dict(name='project-test1', result='ABORTED',
395 changes='1,1 2,1'),
396 dict(name='project-test2', result='ABORTED',
397 changes='1,1 2,1'),
398 dict(name='project-test1', result='ABORTED',
399 changes='1,1 2,1 3,1'),
400 dict(name='project-test2', result='ABORTED',
401 changes='1,1 2,1 3,1'),
402 dict(name='project-merge', result='SUCCESS',
403 changes='2,1'),
404 dict(name='project-merge', result='SUCCESS',
405 changes='2,1 3,1'),
406 dict(name='project-test2', result='SUCCESS',
407 changes='1,1'),
408 dict(name='project-test1', result='SUCCESS',
409 changes='2,1'),
410 dict(name='project-test2', result='SUCCESS',
411 changes='2,1'),
412 dict(name='project-test1', result='SUCCESS',
413 changes='2,1 3,1'),
414 dict(name='project-test2', result='SUCCESS',
415 changes='2,1 3,1'),
416 ], ordered=False)
417
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400418 self.assertEqual(A.data['status'], 'NEW')
419 self.assertEqual(B.data['status'], 'MERGED')
420 self.assertEqual(C.data['status'], 'MERGED')
421 self.assertEqual(A.reported, 2)
422 self.assertEqual(B.reported, 2)
423 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700424
James E. Blair0aac4872013-08-23 14:02:38 -0700425 def test_failed_change_in_middle(self):
426 "Test a failed change in the middle of the queue"
427
James E. Blair08d19992016-08-10 15:25:31 -0700428 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700429 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
430 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
431 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700432 A.addApproval('code-review', 2)
433 B.addApproval('code-review', 2)
434 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700435
James E. Blair08d19992016-08-10 15:25:31 -0700436 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700437
James E. Blair8b5408c2016-08-08 15:37:46 -0700438 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
439 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
440 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700441
442 self.waitUntilSettled()
443
James E. Blair08d19992016-08-10 15:25:31 -0700444 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700445 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700446 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700447 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700448 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700449 self.waitUntilSettled()
450
451 self.assertEqual(len(self.builds), 6)
452 self.assertEqual(self.builds[0].name, 'project-test1')
453 self.assertEqual(self.builds[1].name, 'project-test2')
454 self.assertEqual(self.builds[2].name, 'project-test1')
455 self.assertEqual(self.builds[3].name, 'project-test2')
456 self.assertEqual(self.builds[4].name, 'project-test1')
457 self.assertEqual(self.builds[5].name, 'project-test2')
458
459 self.release(self.builds[2])
460 self.waitUntilSettled()
461
James E. Blair972e3c72013-08-29 12:04:55 -0700462 # project-test1 and project-test2 for A
463 # project-test2 for B
464 # project-merge for C (without B)
465 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700466 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
467
James E. Blair08d19992016-08-10 15:25:31 -0700468 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700469 self.waitUntilSettled()
470
471 # project-test1 and project-test2 for A
472 # project-test2 for B
473 # project-test1 and project-test2 for C
474 self.assertEqual(len(self.builds), 5)
475
Paul Belanger2e2a0492016-10-30 18:33:37 -0400476 tenant = self.sched.abide.tenants.get('tenant-one')
477 items = tenant.layout.pipelines['gate'].getAllItems()
James E. Blair0aac4872013-08-23 14:02:38 -0700478 builds = items[0].current_build_set.getBuilds()
479 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
480 self.assertEqual(self.countJobResults(builds, None), 2)
481 builds = items[1].current_build_set.getBuilds()
482 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
483 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
484 self.assertEqual(self.countJobResults(builds, None), 1)
485 builds = items[2].current_build_set.getBuilds()
486 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700487 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700488
James E. Blair08d19992016-08-10 15:25:31 -0700489 self.launch_server.hold_jobs_in_build = False
490 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700491 self.waitUntilSettled()
492
493 self.assertEqual(len(self.builds), 0)
494 self.assertEqual(len(self.history), 12)
495 self.assertEqual(A.data['status'], 'MERGED')
496 self.assertEqual(B.data['status'], 'NEW')
497 self.assertEqual(C.data['status'], 'MERGED')
498 self.assertEqual(A.reported, 2)
499 self.assertEqual(B.reported, 2)
500 self.assertEqual(C.reported, 2)
501
James E. Blairec056492016-07-22 09:45:56 -0700502 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700503 def test_failed_change_at_head_with_queue(self):
504 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700505
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700506 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700507 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
508 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
509 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700510 A.addApproval('code-review', 2)
511 B.addApproval('code-review', 2)
512 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700513
James E. Blair08d19992016-08-10 15:25:31 -0700514 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700515
James E. Blair8b5408c2016-08-08 15:37:46 -0700516 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
517 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
518 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700519
520 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700521 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400522 self.assertEqual(len(self.builds), 0)
523 self.assertEqual(len(queue), 1)
524 self.assertEqual(queue[0].name, 'build:project-merge')
525 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700526
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700527 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700528 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700529 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700530 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700531 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700532 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700533 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700534
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400535 self.assertEqual(len(self.builds), 0)
536 self.assertEqual(len(queue), 6)
537 self.assertEqual(queue[0].name, 'build:project-test1')
538 self.assertEqual(queue[1].name, 'build:project-test2')
539 self.assertEqual(queue[2].name, 'build:project-test1')
540 self.assertEqual(queue[3].name, 'build:project-test2')
541 self.assertEqual(queue[4].name, 'build:project-test1')
542 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700543
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700544 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700545 self.waitUntilSettled()
546
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400547 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700548 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400549 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
550 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700551
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700552 self.gearman_server.hold_jobs_in_queue = False
553 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700554 self.waitUntilSettled()
555
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400556 self.assertEqual(len(self.builds), 0)
557 self.assertEqual(len(self.history), 11)
558 self.assertEqual(A.data['status'], 'NEW')
559 self.assertEqual(B.data['status'], 'MERGED')
560 self.assertEqual(C.data['status'], 'MERGED')
561 self.assertEqual(A.reported, 2)
562 self.assertEqual(B.reported, 2)
563 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700564
James E. Blairec056492016-07-22 09:45:56 -0700565 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700566 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700567 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700568 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700569 A.addApproval('code-review', 2)
570 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700571 self.waitUntilSettled()
572 time.sleep(2)
573
574 data = json.loads(self.sched.formatStatusJSON())
575 found_job = None
576 for pipeline in data['pipelines']:
577 if pipeline['name'] != 'gate':
578 continue
579 for queue in pipeline['change_queues']:
580 for head in queue['heads']:
581 for item in head:
582 for job in item['jobs']:
583 if job['name'] == 'project-merge':
584 found_job = job
585 break
586
587 self.assertIsNotNone(found_job)
588 if iteration == 1:
589 self.assertIsNotNone(found_job['estimated_time'])
590 self.assertIsNone(found_job['remaining_time'])
591 else:
592 self.assertIsNotNone(found_job['estimated_time'])
593 self.assertTrue(found_job['estimated_time'] >= 2)
594 self.assertIsNotNone(found_job['remaining_time'])
595
James E. Blair08d19992016-08-10 15:25:31 -0700596 self.launch_server.hold_jobs_in_build = False
597 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700598 self.waitUntilSettled()
599
James E. Blairec056492016-07-22 09:45:56 -0700600 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700601 def test_time_database(self):
602 "Test the time database"
603
604 self._test_time_database(1)
605 self._test_time_database(2)
606
James E. Blairec056492016-07-22 09:45:56 -0700607 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700608 def test_two_failed_changes_at_head(self):
609 "Test that changes are reparented correctly if 2 fail at head"
610
James E. Blair08d19992016-08-10 15:25:31 -0700611 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700612 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
613 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
614 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700615 A.addApproval('code-review', 2)
616 B.addApproval('code-review', 2)
617 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700618
James E. Blair08d19992016-08-10 15:25:31 -0700619 self.launch_server.failJob('project-test1', A)
620 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700621
James E. Blair8b5408c2016-08-08 15:37:46 -0700622 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
623 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
624 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700625 self.waitUntilSettled()
626
James E. Blair08d19992016-08-10 15:25:31 -0700627 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700628 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700629 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700630 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700631 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700632 self.waitUntilSettled()
633
634 self.assertEqual(len(self.builds), 6)
635 self.assertEqual(self.builds[0].name, 'project-test1')
636 self.assertEqual(self.builds[1].name, 'project-test2')
637 self.assertEqual(self.builds[2].name, 'project-test1')
638 self.assertEqual(self.builds[3].name, 'project-test2')
639 self.assertEqual(self.builds[4].name, 'project-test1')
640 self.assertEqual(self.builds[5].name, 'project-test2')
641
642 self.assertTrue(self.job_has_changes(self.builds[0], A))
643 self.assertTrue(self.job_has_changes(self.builds[2], A))
644 self.assertTrue(self.job_has_changes(self.builds[2], B))
645 self.assertTrue(self.job_has_changes(self.builds[4], A))
646 self.assertTrue(self.job_has_changes(self.builds[4], B))
647 self.assertTrue(self.job_has_changes(self.builds[4], C))
648
649 # Fail change B first
650 self.release(self.builds[2])
651 self.waitUntilSettled()
652
653 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700654 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700655 self.waitUntilSettled()
656
657 self.assertEqual(len(self.builds), 5)
658 self.assertEqual(self.builds[0].name, 'project-test1')
659 self.assertEqual(self.builds[1].name, 'project-test2')
660 self.assertEqual(self.builds[2].name, 'project-test2')
661 self.assertEqual(self.builds[3].name, 'project-test1')
662 self.assertEqual(self.builds[4].name, 'project-test2')
663
664 self.assertTrue(self.job_has_changes(self.builds[1], A))
665 self.assertTrue(self.job_has_changes(self.builds[2], A))
666 self.assertTrue(self.job_has_changes(self.builds[2], B))
667 self.assertTrue(self.job_has_changes(self.builds[4], A))
668 self.assertFalse(self.job_has_changes(self.builds[4], B))
669 self.assertTrue(self.job_has_changes(self.builds[4], C))
670
671 # Finish running all passing jobs for change A
672 self.release(self.builds[1])
673 self.waitUntilSettled()
674 # Fail and report change A
675 self.release(self.builds[0])
676 self.waitUntilSettled()
677
678 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700679 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700680 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700681 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700682 self.waitUntilSettled()
683
684 self.assertEqual(len(self.builds), 4)
685 self.assertEqual(self.builds[0].name, 'project-test1') # B
686 self.assertEqual(self.builds[1].name, 'project-test2') # B
687 self.assertEqual(self.builds[2].name, 'project-test1') # C
688 self.assertEqual(self.builds[3].name, 'project-test2') # C
689
690 self.assertFalse(self.job_has_changes(self.builds[1], A))
691 self.assertTrue(self.job_has_changes(self.builds[1], B))
692 self.assertFalse(self.job_has_changes(self.builds[1], C))
693
694 self.assertFalse(self.job_has_changes(self.builds[2], A))
695 # After A failed and B and C restarted, B should be back in
696 # C's tests because it has not failed yet.
697 self.assertTrue(self.job_has_changes(self.builds[2], B))
698 self.assertTrue(self.job_has_changes(self.builds[2], C))
699
James E. Blair08d19992016-08-10 15:25:31 -0700700 self.launch_server.hold_jobs_in_build = False
701 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700702 self.waitUntilSettled()
703
704 self.assertEqual(len(self.builds), 0)
705 self.assertEqual(len(self.history), 21)
706 self.assertEqual(A.data['status'], 'NEW')
707 self.assertEqual(B.data['status'], 'NEW')
708 self.assertEqual(C.data['status'], 'MERGED')
709 self.assertEqual(A.reported, 2)
710 self.assertEqual(B.reported, 2)
711 self.assertEqual(C.reported, 2)
712
James E. Blairec056492016-07-22 09:45:56 -0700713 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700714 def test_parse_skip_if(self):
715 job_yaml = """
716jobs:
717 - name: job_name
718 skip-if:
719 - project: ^project_name$
720 branch: ^stable/icehouse$
721 all-files-match-any:
722 - ^filename$
723 - project: ^project2_name$
724 all-files-match-any:
725 - ^filename2$
726 """.strip()
727 data = yaml.load(job_yaml)
728 config_job = data.get('jobs')[0]
729 cm = zuul.change_matcher
730 expected = cm.MatchAny([
731 cm.MatchAll([
732 cm.ProjectMatcher('^project_name$'),
733 cm.BranchMatcher('^stable/icehouse$'),
734 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
735 ]),
736 cm.MatchAll([
737 cm.ProjectMatcher('^project2_name$'),
738 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
739 ]),
740 ])
741 matcher = self.sched._parseSkipIf(config_job)
742 self.assertEqual(expected, matcher)
743
James E. Blair8c803f82012-07-31 16:25:42 -0700744 def test_patch_order(self):
745 "Test that dependent patches are tested in the right order"
746 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
747 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
748 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700749 A.addApproval('code-review', 2)
750 B.addApproval('code-review', 2)
751 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700752
753 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
754 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
755 M2.setMerged()
756 M1.setMerged()
757
758 # C -> B -> A -> M1 -> M2
759 # M2 is here to make sure it is never queried. If it is, it
760 # means zuul is walking down the entire history of merged
761 # changes.
762
763 C.setDependsOn(B, 1)
764 B.setDependsOn(A, 1)
765 A.setDependsOn(M1, 1)
766 M1.setDependsOn(M2, 1)
767
James E. Blair8b5408c2016-08-08 15:37:46 -0700768 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700769
770 self.waitUntilSettled()
771
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400772 self.assertEqual(A.data['status'], 'NEW')
773 self.assertEqual(B.data['status'], 'NEW')
774 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700775
James E. Blair8b5408c2016-08-08 15:37:46 -0700776 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
777 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700778
779 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400780 self.assertEqual(M2.queried, 0)
781 self.assertEqual(A.data['status'], 'MERGED')
782 self.assertEqual(B.data['status'], 'MERGED')
783 self.assertEqual(C.data['status'], 'MERGED')
784 self.assertEqual(A.reported, 2)
785 self.assertEqual(B.reported, 2)
786 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700787
James E. Blairec056492016-07-22 09:45:56 -0700788 @skip("Disabled for early v3 development")
James E. Blair063672f2015-01-29 13:09:12 -0800789 def test_needed_changes_enqueue(self):
790 "Test that a needed change is enqueued ahead"
791 # A Given a git tree like this, if we enqueue
792 # / \ change C, we should walk up and down the tree
793 # B G and enqueue changes in the order ABCDEFG.
794 # /|\ This is also the order that you would get if
795 # *C E F you enqueued changes in the order ABCDEFG, so
796 # / the ordering is stable across re-enqueue events.
797 # D
798
799 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
800 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
801 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
802 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
803 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
804 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
805 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
806 B.setDependsOn(A, 1)
807 C.setDependsOn(B, 1)
808 D.setDependsOn(C, 1)
809 E.setDependsOn(B, 1)
810 F.setDependsOn(B, 1)
811 G.setDependsOn(A, 1)
812
James E. Blair8b5408c2016-08-08 15:37:46 -0700813 A.addApproval('code-review', 2)
814 B.addApproval('code-review', 2)
815 C.addApproval('code-review', 2)
816 D.addApproval('code-review', 2)
817 E.addApproval('code-review', 2)
818 F.addApproval('code-review', 2)
819 G.addApproval('code-review', 2)
820 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800821
822 self.waitUntilSettled()
823
824 self.assertEqual(A.data['status'], 'NEW')
825 self.assertEqual(B.data['status'], 'NEW')
826 self.assertEqual(C.data['status'], 'NEW')
827 self.assertEqual(D.data['status'], 'NEW')
828 self.assertEqual(E.data['status'], 'NEW')
829 self.assertEqual(F.data['status'], 'NEW')
830 self.assertEqual(G.data['status'], 'NEW')
831
832 # We're about to add approvals to changes without adding the
833 # triggering events to Zuul, so that we can be sure that it is
834 # enqueing the changes based on dependencies, not because of
835 # triggering events. Since it will have the changes cached
836 # already (without approvals), we need to clear the cache
837 # first.
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100838 for connection in self.connections.values():
839 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800840
James E. Blair08d19992016-08-10 15:25:31 -0700841 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700842 A.addApproval('approved', 1)
843 B.addApproval('approved', 1)
844 D.addApproval('approved', 1)
845 E.addApproval('approved', 1)
846 F.addApproval('approved', 1)
847 G.addApproval('approved', 1)
848 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800849
850 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700851 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800852 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700853 self.launch_server.hold_jobs_in_build = False
854 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800855 self.waitUntilSettled()
856
857 self.assertEqual(A.data['status'], 'MERGED')
858 self.assertEqual(B.data['status'], 'MERGED')
859 self.assertEqual(C.data['status'], 'MERGED')
860 self.assertEqual(D.data['status'], 'MERGED')
861 self.assertEqual(E.data['status'], 'MERGED')
862 self.assertEqual(F.data['status'], 'MERGED')
863 self.assertEqual(G.data['status'], 'MERGED')
864 self.assertEqual(A.reported, 2)
865 self.assertEqual(B.reported, 2)
866 self.assertEqual(C.reported, 2)
867 self.assertEqual(D.reported, 2)
868 self.assertEqual(E.reported, 2)
869 self.assertEqual(F.reported, 2)
870 self.assertEqual(G.reported, 2)
871 self.assertEqual(self.history[6].changes,
872 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
873
James E. Blairec056492016-07-22 09:45:56 -0700874 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100875 def test_source_cache(self):
876 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700877 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700878
879 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
880 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
881 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700882 A.addApproval('code-review', 2)
883 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700884
885 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
886 M1.setMerged()
887
888 B.setDependsOn(A, 1)
889 A.setDependsOn(M1, 1)
890
James E. Blair8b5408c2016-08-08 15:37:46 -0700891 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700892 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
893
894 self.waitUntilSettled()
895
896 for build in self.builds:
897 if build.parameters['ZUUL_PIPELINE'] == 'check':
898 build.release()
899 self.waitUntilSettled()
900 for build in self.builds:
901 if build.parameters['ZUUL_PIPELINE'] == 'check':
902 build.release()
903 self.waitUntilSettled()
904
James E. Blair8b5408c2016-08-08 15:37:46 -0700905 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700906 self.waitUntilSettled()
907
Joshua Hesketh352264b2015-08-11 23:42:08 +1000908 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700909 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000910 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700911
James E. Blair08d19992016-08-10 15:25:31 -0700912 self.launch_server.hold_jobs_in_build = False
913 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700914 self.waitUntilSettled()
915
916 self.assertEqual(A.data['status'], 'MERGED')
917 self.assertEqual(B.data['status'], 'MERGED')
918 self.assertEqual(A.queried, 2) # Initial and isMerged
919 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
920
James E. Blairec056492016-07-22 09:45:56 -0700921 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700922 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700923 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700924 # TODO: move to test_gerrit (this is a unit test!)
925 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairc0dedf82014-08-06 09:37:52 -0700926 source = self.sched.layout.pipelines['gate'].source
927 a = source._getChange(1, 2)
James E. Blaireff88162013-07-01 12:44:14 -0400928 mgr = self.sched.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700929 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700930
James E. Blair8b5408c2016-08-08 15:37:46 -0700931 A.addApproval('code-review', 2)
James E. Blairc0dedf82014-08-06 09:37:52 -0700932 a = source._getChange(1, 2, refresh=True)
933 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700934
James E. Blair8b5408c2016-08-08 15:37:46 -0700935 A.addApproval('approved', 1)
James E. Blairc0dedf82014-08-06 09:37:52 -0700936 a = source._getChange(1, 2, refresh=True)
937 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700938
James E. Blairec056492016-07-22 09:45:56 -0700939 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700940 def test_build_configuration(self):
941 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700942
943 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700944 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
945 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
946 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700947 A.addApproval('code-review', 2)
948 B.addApproval('code-review', 2)
949 C.addApproval('code-review', 2)
950 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
951 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
952 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700953 self.waitUntilSettled()
954
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700955 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700956 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700957 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700958 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700959 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700960 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700961 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700962 ref = self.getParameter(queue[-1], 'ZUUL_REF')
963 self.gearman_server.hold_jobs_in_queue = False
964 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700965 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700966
Monty Taylorbc758832013-06-17 17:22:42 -0400967 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700968 repo = git.Repo(path)
969 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
970 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700971 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400972 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700973
James E. Blairec056492016-07-22 09:45:56 -0700974 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700975 def test_build_configuration_conflict(self):
976 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700977
978 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700979 A = self.fake_gerrit.addFakeChange('org/conflict-project',
980 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700981 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700982 B = self.fake_gerrit.addFakeChange('org/conflict-project',
983 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700984 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700985 C = self.fake_gerrit.addFakeChange('org/conflict-project',
986 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700987 A.addApproval('code-review', 2)
988 B.addApproval('code-review', 2)
989 C.addApproval('code-review', 2)
990 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
991 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
992 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -0700993 self.waitUntilSettled()
994
James E. Blair6736beb2013-07-11 15:18:15 -0700995 self.assertEqual(A.reported, 1)
996 self.assertEqual(B.reported, 1)
997 self.assertEqual(C.reported, 1)
998
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700999 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001000 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001001 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001002 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001003 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001004 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001005
1006 self.assertEqual(len(self.history), 2) # A and C merge jobs
1007
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001008 self.gearman_server.hold_jobs_in_queue = False
1009 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001010 self.waitUntilSettled()
1011
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001012 self.assertEqual(A.data['status'], 'MERGED')
1013 self.assertEqual(B.data['status'], 'NEW')
1014 self.assertEqual(C.data['status'], 'MERGED')
1015 self.assertEqual(A.reported, 2)
1016 self.assertEqual(B.reported, 2)
1017 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001018 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001019
James E. Blairec056492016-07-22 09:45:56 -07001020 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001021 def test_post(self):
1022 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001023
Zhongyue Luo5d556072012-09-21 02:00:47 +09001024 e = {
1025 "type": "ref-updated",
1026 "submitter": {
1027 "name": "User Name",
1028 },
1029 "refUpdate": {
1030 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1031 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1032 "refName": "master",
1033 "project": "org/project",
1034 }
1035 }
James E. Blairdaabed22012-08-15 15:38:57 -07001036 self.fake_gerrit.addEvent(e)
1037 self.waitUntilSettled()
1038
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001039 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001040 self.assertEqual(len(self.history), 1)
1041 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001042
James E. Blairec056492016-07-22 09:45:56 -07001043 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001044 def test_post_ignore_deletes(self):
1045 "Test that deleting refs does not trigger post jobs"
1046
1047 e = {
1048 "type": "ref-updated",
1049 "submitter": {
1050 "name": "User Name",
1051 },
1052 "refUpdate": {
1053 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1054 "newRev": "0000000000000000000000000000000000000000",
1055 "refName": "master",
1056 "project": "org/project",
1057 }
1058 }
1059 self.fake_gerrit.addEvent(e)
1060 self.waitUntilSettled()
1061
1062 job_names = [x.name for x in self.history]
1063 self.assertEqual(len(self.history), 0)
1064 self.assertNotIn('project-post', job_names)
1065
James E. Blairec056492016-07-22 09:45:56 -07001066 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001067 def test_post_ignore_deletes_negative(self):
1068 "Test that deleting refs does trigger post jobs"
1069
James E. Blairf84026c2015-12-08 16:11:46 -08001070 self.updateConfigLayout(
1071 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001072 self.sched.reconfigure(self.config)
1073
1074 e = {
1075 "type": "ref-updated",
1076 "submitter": {
1077 "name": "User Name",
1078 },
1079 "refUpdate": {
1080 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1081 "newRev": "0000000000000000000000000000000000000000",
1082 "refName": "master",
1083 "project": "org/project",
1084 }
1085 }
1086 self.fake_gerrit.addEvent(e)
1087 self.waitUntilSettled()
1088
1089 job_names = [x.name for x in self.history]
1090 self.assertEqual(len(self.history), 1)
1091 self.assertIn('project-post', job_names)
1092
James E. Blairec056492016-07-22 09:45:56 -07001093 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001094 def test_build_configuration_branch(self):
1095 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001096
1097 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001098 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1099 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1100 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001101 A.addApproval('code-review', 2)
1102 B.addApproval('code-review', 2)
1103 C.addApproval('code-review', 2)
1104 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1105 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1106 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001107 self.waitUntilSettled()
1108
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001109 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001110 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001111 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001112 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001113 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001114 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001115 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001116 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1117 self.gearman_server.hold_jobs_in_queue = False
1118 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001119 self.waitUntilSettled()
1120
Monty Taylorbc758832013-06-17 17:22:42 -04001121 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001122 repo = git.Repo(path)
1123 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1124 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001125 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001126 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001127
James E. Blairec056492016-07-22 09:45:56 -07001128 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001129 def test_build_configuration_branch_interaction(self):
1130 "Test that switching between branches works"
1131 self.test_build_configuration()
1132 self.test_build_configuration_branch()
1133 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001134 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001135 repo = git.Repo(path)
1136 repo.heads.master.commit = repo.commit('init')
1137 self.test_build_configuration()
1138
James E. Blairec056492016-07-22 09:45:56 -07001139 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001140 def test_build_configuration_multi_branch(self):
1141 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001142
1143 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001144 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1145 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1146 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001147 A.addApproval('code-review', 2)
1148 B.addApproval('code-review', 2)
1149 C.addApproval('code-review', 2)
1150 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1151 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1152 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001153 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001154 queue = self.gearman_server.getQueue()
1155 job_A = None
1156 for job in queue:
1157 if 'project-merge' in job.name:
1158 job_A = job
1159 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1160 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1161 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1162 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001163
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001164 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001165 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001166 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001167 job_B = None
1168 for job in queue:
1169 if 'project-merge' in job.name:
1170 job_B = job
1171 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001172 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001173 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001174 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1175
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001176 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001177 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001178 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001179 for job in queue:
1180 if 'project-merge' in job.name:
1181 job_C = job
1182 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001183 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001184 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001185 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001186 self.gearman_server.hold_jobs_in_queue = False
1187 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001188 self.waitUntilSettled()
1189
Monty Taylorbc758832013-06-17 17:22:42 -04001190 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001191 repo = git.Repo(path)
1192
1193 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001194 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001195 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001196 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001197 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001198 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001199 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001200 # Ensure ZUUL_REF -> ZUUL_COMMIT
1201 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001202
1203 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001204 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001205 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001206 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001207 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001208 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001209 self.assertEqual(repo_shas[0], commit_B)
1210
1211 repo_messages = [c.message.strip()
1212 for c in repo.iter_commits(ref_A)]
1213 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1214 repo_messages.reverse()
1215 correct_messages = ['initial commit', 'A-1']
1216 self.assertEqual(repo_messages, correct_messages)
1217 self.assertEqual(repo_shas[0], commit_A)
1218
1219 self.assertNotEqual(ref_A, ref_B, ref_C)
1220 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001221
James E. Blairec056492016-07-22 09:45:56 -07001222 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001223 def test_one_job_project(self):
1224 "Test that queueing works with one job"
1225 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1226 'master', 'A')
1227 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1228 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001229 A.addApproval('code-review', 2)
1230 B.addApproval('code-review', 2)
1231 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1232 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001233 self.waitUntilSettled()
1234
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001235 self.assertEqual(A.data['status'], 'MERGED')
1236 self.assertEqual(A.reported, 2)
1237 self.assertEqual(B.data['status'], 'MERGED')
1238 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001239
James E. Blairec056492016-07-22 09:45:56 -07001240 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001241 def test_job_from_templates_launched(self):
1242 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001243
Antoine Musso80edd5a2013-02-13 15:37:53 +01001244 A = self.fake_gerrit.addFakeChange(
1245 'org/templated-project', 'master', 'A')
1246 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1247 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001248
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001249 self.assertEqual(self.getJobFromHistory('project-test1').result,
1250 'SUCCESS')
1251 self.assertEqual(self.getJobFromHistory('project-test2').result,
1252 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001253
James E. Blairec056492016-07-22 09:45:56 -07001254 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001255 def test_layered_templates(self):
1256 "Test whether a job generated via a template can be launched"
1257
1258 A = self.fake_gerrit.addFakeChange(
1259 'org/layered-project', 'master', 'A')
1260 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1261 self.waitUntilSettled()
1262
1263 self.assertEqual(self.getJobFromHistory('project-test1').result,
1264 'SUCCESS')
1265 self.assertEqual(self.getJobFromHistory('project-test2').result,
1266 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001267 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1268 ).result, 'SUCCESS')
1269 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1270 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001271 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1272 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001273 self.assertEqual(self.getJobFromHistory('project-test6').result,
1274 'SUCCESS')
1275
James E. Blaircaec0c52012-08-22 14:52:22 -07001276 def test_dependent_changes_dequeue(self):
1277 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001278
James E. Blaircaec0c52012-08-22 14:52:22 -07001279 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1280 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1281 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001282 A.addApproval('code-review', 2)
1283 B.addApproval('code-review', 2)
1284 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001285
1286 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1287 M1.setMerged()
1288
1289 # C -> B -> A -> M1
1290
1291 C.setDependsOn(B, 1)
1292 B.setDependsOn(A, 1)
1293 A.setDependsOn(M1, 1)
1294
James E. Blair08d19992016-08-10 15:25:31 -07001295 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001296
James E. Blair8b5408c2016-08-08 15:37:46 -07001297 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1298 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1299 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001300
1301 self.waitUntilSettled()
1302
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001303 self.assertEqual(A.data['status'], 'NEW')
1304 self.assertEqual(A.reported, 2)
1305 self.assertEqual(B.data['status'], 'NEW')
1306 self.assertEqual(B.reported, 2)
1307 self.assertEqual(C.data['status'], 'NEW')
1308 self.assertEqual(C.reported, 2)
1309 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001310
James E. Blair972e3c72013-08-29 12:04:55 -07001311 def test_failing_dependent_changes(self):
1312 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001313 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001314 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1315 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1316 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1317 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1318 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001319 A.addApproval('code-review', 2)
1320 B.addApproval('code-review', 2)
1321 C.addApproval('code-review', 2)
1322 D.addApproval('code-review', 2)
1323 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001324
1325 # E, D -> C -> B, A
1326
1327 D.setDependsOn(C, 1)
1328 C.setDependsOn(B, 1)
1329
James E. Blair08d19992016-08-10 15:25:31 -07001330 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001331
James E. Blair8b5408c2016-08-08 15:37:46 -07001332 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1333 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1334 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1335 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1336 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001337
1338 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001339 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001340 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001341 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001342 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001343 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001344 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001345 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001346 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001347 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001348 self.waitUntilSettled()
1349
James E. Blair08d19992016-08-10 15:25:31 -07001350 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001351 for build in self.builds:
1352 if build.parameters['ZUUL_CHANGE'] != '1':
1353 build.release()
1354 self.waitUntilSettled()
1355
James E. Blair08d19992016-08-10 15:25:31 -07001356 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001357 self.waitUntilSettled()
1358
1359 self.assertEqual(A.data['status'], 'MERGED')
1360 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001361 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001362 self.assertEqual(B.data['status'], 'NEW')
1363 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001364 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001365 self.assertEqual(C.data['status'], 'NEW')
1366 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001367 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001368 self.assertEqual(D.data['status'], 'NEW')
1369 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001370 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001371 self.assertEqual(E.data['status'], 'MERGED')
1372 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001373 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001374 self.assertEqual(len(self.history), 18)
1375
James E. Blairec056492016-07-22 09:45:56 -07001376 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001377 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001378 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001379 # If it's dequeued more than once, we should see extra
1380 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001381
James E. Blair08d19992016-08-10 15:25:31 -07001382 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001383 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1384 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1385 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001386 A.addApproval('code-review', 2)
1387 B.addApproval('code-review', 2)
1388 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001389
James E. Blair08d19992016-08-10 15:25:31 -07001390 self.launch_server.failJob('project1-test1', A)
1391 self.launch_server.failJob('project1-test2', A)
1392 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001393
James E. Blair8b5408c2016-08-08 15:37:46 -07001394 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1395 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1396 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001397
1398 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001399
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001400 self.assertEqual(len(self.builds), 1)
1401 self.assertEqual(self.builds[0].name, 'project1-merge')
1402 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001403
James E. Blair08d19992016-08-10 15:25:31 -07001404 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001405 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001406 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001407 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001408 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001409 self.waitUntilSettled()
1410
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001411 self.assertEqual(len(self.builds), 9)
1412 self.assertEqual(self.builds[0].name, 'project1-test1')
1413 self.assertEqual(self.builds[1].name, 'project1-test2')
1414 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1415 self.assertEqual(self.builds[3].name, 'project1-test1')
1416 self.assertEqual(self.builds[4].name, 'project1-test2')
1417 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1418 self.assertEqual(self.builds[6].name, 'project1-test1')
1419 self.assertEqual(self.builds[7].name, 'project1-test2')
1420 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001421
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001422 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001423 self.waitUntilSettled()
1424
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001425 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1426 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001427
James E. Blair08d19992016-08-10 15:25:31 -07001428 self.launch_server.hold_jobs_in_build = False
1429 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001430 self.waitUntilSettled()
1431
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001432 self.assertEqual(len(self.builds), 0)
1433 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001434
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001435 self.assertEqual(A.data['status'], 'NEW')
1436 self.assertEqual(B.data['status'], 'MERGED')
1437 self.assertEqual(C.data['status'], 'MERGED')
1438 self.assertEqual(A.reported, 2)
1439 self.assertEqual(B.reported, 2)
1440 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001441
James E. Blairec056492016-07-22 09:45:56 -07001442 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001443 def test_nonvoting_job(self):
1444 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001445
James E. Blair4ec821f2012-08-23 15:28:28 -07001446 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1447 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001448 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001449 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001450 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001451
1452 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001453
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001454 self.assertEqual(A.data['status'], 'MERGED')
1455 self.assertEqual(A.reported, 2)
1456 self.assertEqual(
1457 self.getJobFromHistory('nonvoting-project-merge').result,
1458 'SUCCESS')
1459 self.assertEqual(
1460 self.getJobFromHistory('nonvoting-project-test1').result,
1461 'SUCCESS')
1462 self.assertEqual(
1463 self.getJobFromHistory('nonvoting-project-test2').result,
1464 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001465
James E. Blair5821bd92015-09-16 08:48:15 -07001466 for build in self.builds:
1467 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1468
James E. Blairec056492016-07-22 09:45:56 -07001469 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001470 def test_check_queue_success(self):
1471 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001472
James E. Blaire0487072012-08-29 17:38:31 -07001473 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1474 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1475
1476 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001477
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001478 self.assertEqual(A.data['status'], 'NEW')
1479 self.assertEqual(A.reported, 1)
1480 self.assertEqual(self.getJobFromHistory('project-merge').result,
1481 'SUCCESS')
1482 self.assertEqual(self.getJobFromHistory('project-test1').result,
1483 'SUCCESS')
1484 self.assertEqual(self.getJobFromHistory('project-test2').result,
1485 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001486
James E. Blairec056492016-07-22 09:45:56 -07001487 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001488 def test_check_queue_failure(self):
1489 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001490
James E. Blaire0487072012-08-29 17:38:31 -07001491 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001492 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001493 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1494
1495 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001496
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001497 self.assertEqual(A.data['status'], 'NEW')
1498 self.assertEqual(A.reported, 1)
1499 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001500 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001501 self.assertEqual(self.getJobFromHistory('project-test1').result,
1502 'SUCCESS')
1503 self.assertEqual(self.getJobFromHistory('project-test2').result,
1504 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001505
James E. Blairec056492016-07-22 09:45:56 -07001506 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001507 def test_dependent_behind_dequeue(self):
1508 "test that dependent changes behind dequeued changes work"
1509 # This complicated test is a reproduction of a real life bug
1510 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001511
James E. Blair08d19992016-08-10 15:25:31 -07001512 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001513 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1514 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1515 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1516 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1517 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1518 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1519 D.setDependsOn(C, 1)
1520 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001521 A.addApproval('code-review', 2)
1522 B.addApproval('code-review', 2)
1523 C.addApproval('code-review', 2)
1524 D.addApproval('code-review', 2)
1525 E.addApproval('code-review', 2)
1526 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001527
1528 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001529
1530 # Change object re-use in the gerrit trigger is hidden if
1531 # changes are added in quick succession; waiting makes it more
1532 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001533 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001534 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001535 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001536 self.waitUntilSettled()
1537
James E. Blair08d19992016-08-10 15:25:31 -07001538 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001539 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001540 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001541 self.waitUntilSettled()
1542
James E. Blair8b5408c2016-08-08 15:37:46 -07001543 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001544 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001545 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001546 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001547 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001548 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001549 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001550 self.waitUntilSettled()
1551
James E. Blair08d19992016-08-10 15:25:31 -07001552 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001553 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001554 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001555 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001556 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001557 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001558 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001559 self.waitUntilSettled()
1560
1561 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001562
1563 # Grab pointers to the jobs we want to release before
1564 # releasing any, because list indexes may change as
1565 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001566 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001567 a.release()
1568 b.release()
1569 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001570 self.waitUntilSettled()
1571
James E. Blair08d19992016-08-10 15:25:31 -07001572 self.launch_server.hold_jobs_in_build = False
1573 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001574 self.waitUntilSettled()
1575
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001576 self.assertEqual(A.data['status'], 'NEW')
1577 self.assertEqual(B.data['status'], 'MERGED')
1578 self.assertEqual(C.data['status'], 'MERGED')
1579 self.assertEqual(D.data['status'], 'MERGED')
1580 self.assertEqual(E.data['status'], 'MERGED')
1581 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001582
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001583 self.assertEqual(A.reported, 2)
1584 self.assertEqual(B.reported, 2)
1585 self.assertEqual(C.reported, 2)
1586 self.assertEqual(D.reported, 2)
1587 self.assertEqual(E.reported, 2)
1588 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001589
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001590 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1591 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001592
James E. Blairec056492016-07-22 09:45:56 -07001593 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001594 def test_merger_repack(self):
1595 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001596
James E. Blair05fed602012-09-07 12:45:24 -07001597 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001598 A.addApproval('code-review', 2)
1599 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001600 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001601 self.assertEqual(self.getJobFromHistory('project-merge').result,
1602 'SUCCESS')
1603 self.assertEqual(self.getJobFromHistory('project-test1').result,
1604 'SUCCESS')
1605 self.assertEqual(self.getJobFromHistory('project-test2').result,
1606 'SUCCESS')
1607 self.assertEqual(A.data['status'], 'MERGED')
1608 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001609 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001610 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001611
Monty Taylorbc758832013-06-17 17:22:42 -04001612 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001613 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001614
1615 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001616 A.addApproval('code-review', 2)
1617 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001618 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001619 self.assertEqual(self.getJobFromHistory('project-merge').result,
1620 'SUCCESS')
1621 self.assertEqual(self.getJobFromHistory('project-test1').result,
1622 'SUCCESS')
1623 self.assertEqual(self.getJobFromHistory('project-test2').result,
1624 'SUCCESS')
1625 self.assertEqual(A.data['status'], 'MERGED')
1626 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001627
James E. Blairec056492016-07-22 09:45:56 -07001628 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001629 def test_merger_repack_large_change(self):
1630 "Test that the merger works with large changes after a repack"
1631 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001632 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001633 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001634 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001635 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001636 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1637 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001638 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001639 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001640 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001641 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001642
James E. Blair8b5408c2016-08-08 15:37:46 -07001643 A.addApproval('code-review', 2)
1644 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001645 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001646 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1647 'SUCCESS')
1648 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1649 'SUCCESS')
1650 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1651 'SUCCESS')
1652 self.assertEqual(A.data['status'], 'MERGED')
1653 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001654
James E. Blairec056492016-07-22 09:45:56 -07001655 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001656 def test_nonexistent_job(self):
1657 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001658 # Set to the state immediately after a restart
1659 self.resetGearmanServer()
1660 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001661
1662 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001663 A.addApproval('code-review', 2)
1664 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001665 # There may be a thread about to report a lost change
1666 while A.reported < 2:
1667 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001668 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001669 self.assertFalse(job_names)
1670 self.assertEqual(A.data['status'], 'NEW')
1671 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001672 self.assertEmptyQueues()
1673
1674 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001675 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001676 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001677 A.addApproval('code-review', 2)
1678 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001679 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001680 self.assertEqual(self.getJobFromHistory('project-merge').result,
1681 'SUCCESS')
1682 self.assertEqual(self.getJobFromHistory('project-test1').result,
1683 'SUCCESS')
1684 self.assertEqual(self.getJobFromHistory('project-test2').result,
1685 'SUCCESS')
1686 self.assertEqual(A.data['status'], 'MERGED')
1687 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001688
James E. Blairec056492016-07-22 09:45:56 -07001689 @skip("Disabled for early v3 development")
James E. Blairf62d4282012-12-31 17:01:50 -08001690 def test_single_nonexistent_post_job(self):
1691 "Test launching a single post job that doesn't exist"
James E. Blairf62d4282012-12-31 17:01:50 -08001692 e = {
1693 "type": "ref-updated",
1694 "submitter": {
1695 "name": "User Name",
1696 },
1697 "refUpdate": {
1698 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1699 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1700 "refName": "master",
1701 "project": "org/project",
1702 }
1703 }
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001704 # Set to the state immediately after a restart
1705 self.resetGearmanServer()
1706 self.launcher.negative_function_cache_ttl = 0
1707
James E. Blairf62d4282012-12-31 17:01:50 -08001708 self.fake_gerrit.addEvent(e)
1709 self.waitUntilSettled()
1710
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001711 self.assertEqual(len(self.history), 0)
James E. Blair2fa50962013-01-30 21:50:41 -08001712
James E. Blairec056492016-07-22 09:45:56 -07001713 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001714 def test_new_patchset_dequeues_old(self):
1715 "Test that a new patchset causes the old to be dequeued"
1716 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001717 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001718 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1719 M.setMerged()
1720
1721 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1722 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1723 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1724 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001725 A.addApproval('code-review', 2)
1726 B.addApproval('code-review', 2)
1727 C.addApproval('code-review', 2)
1728 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001729
1730 C.setDependsOn(B, 1)
1731 B.setDependsOn(A, 1)
1732 A.setDependsOn(M, 1)
1733
James E. Blair8b5408c2016-08-08 15:37:46 -07001734 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1735 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1736 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1737 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001738 self.waitUntilSettled()
1739
1740 B.addPatchset()
1741 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1742 self.waitUntilSettled()
1743
James E. Blair08d19992016-08-10 15:25:31 -07001744 self.launch_server.hold_jobs_in_build = False
1745 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001746 self.waitUntilSettled()
1747
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001748 self.assertEqual(A.data['status'], 'MERGED')
1749 self.assertEqual(A.reported, 2)
1750 self.assertEqual(B.data['status'], 'NEW')
1751 self.assertEqual(B.reported, 2)
1752 self.assertEqual(C.data['status'], 'NEW')
1753 self.assertEqual(C.reported, 2)
1754 self.assertEqual(D.data['status'], 'MERGED')
1755 self.assertEqual(D.reported, 2)
1756 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001757
James E. Blairec056492016-07-22 09:45:56 -07001758 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001759 def test_new_patchset_check(self):
1760 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001761
James E. Blair08d19992016-08-10 15:25:31 -07001762 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001763
1764 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001765 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1766 check_pipeline = self.sched.layout.pipelines['check']
1767
1768 # Add two git-dependent changes
1769 B.setDependsOn(A, 1)
1770 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1771 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001772 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1773 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001774
1775 # A live item, and a non-live/live pair
1776 items = check_pipeline.getAllItems()
1777 self.assertEqual(len(items), 3)
1778
1779 self.assertEqual(items[0].change.number, '1')
1780 self.assertEqual(items[0].change.patchset, '1')
1781 self.assertFalse(items[0].live)
1782
1783 self.assertEqual(items[1].change.number, '2')
1784 self.assertEqual(items[1].change.patchset, '1')
1785 self.assertTrue(items[1].live)
1786
1787 self.assertEqual(items[2].change.number, '1')
1788 self.assertEqual(items[2].change.patchset, '1')
1789 self.assertTrue(items[2].live)
1790
1791 # Add a new patchset to A
1792 A.addPatchset()
1793 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1794 self.waitUntilSettled()
1795
1796 # The live copy of A,1 should be gone, but the non-live and B
1797 # should continue, and we should have a new A,2
1798 items = check_pipeline.getAllItems()
1799 self.assertEqual(len(items), 3)
1800
1801 self.assertEqual(items[0].change.number, '1')
1802 self.assertEqual(items[0].change.patchset, '1')
1803 self.assertFalse(items[0].live)
1804
1805 self.assertEqual(items[1].change.number, '2')
1806 self.assertEqual(items[1].change.patchset, '1')
1807 self.assertTrue(items[1].live)
1808
1809 self.assertEqual(items[2].change.number, '1')
1810 self.assertEqual(items[2].change.patchset, '2')
1811 self.assertTrue(items[2].live)
1812
1813 # Add a new patchset to B
1814 B.addPatchset()
1815 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1816 self.waitUntilSettled()
1817
1818 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1819 # but we should have a new B,2 (still based on A,1)
1820 items = check_pipeline.getAllItems()
1821 self.assertEqual(len(items), 3)
1822
1823 self.assertEqual(items[0].change.number, '1')
1824 self.assertEqual(items[0].change.patchset, '2')
1825 self.assertTrue(items[0].live)
1826
1827 self.assertEqual(items[1].change.number, '1')
1828 self.assertEqual(items[1].change.patchset, '1')
1829 self.assertFalse(items[1].live)
1830
1831 self.assertEqual(items[2].change.number, '2')
1832 self.assertEqual(items[2].change.patchset, '2')
1833 self.assertTrue(items[2].live)
1834
1835 self.builds[0].release()
1836 self.waitUntilSettled()
1837 self.builds[0].release()
1838 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001839 self.launch_server.hold_jobs_in_build = False
1840 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001841 self.waitUntilSettled()
1842
1843 self.assertEqual(A.reported, 1)
1844 self.assertEqual(B.reported, 1)
1845 self.assertEqual(self.history[0].result, 'ABORTED')
1846 self.assertEqual(self.history[0].changes, '1,1')
1847 self.assertEqual(self.history[1].result, 'ABORTED')
1848 self.assertEqual(self.history[1].changes, '1,1 2,1')
1849 self.assertEqual(self.history[2].result, 'SUCCESS')
1850 self.assertEqual(self.history[2].changes, '1,2')
1851 self.assertEqual(self.history[3].result, 'SUCCESS')
1852 self.assertEqual(self.history[3].changes, '1,1 2,2')
1853
1854 def test_abandoned_gate(self):
1855 "Test that an abandoned change is dequeued from gate"
1856
James E. Blair08d19992016-08-10 15:25:31 -07001857 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001858
1859 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001860 A.addApproval('code-review', 2)
1861 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001862 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001863 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1864 self.assertEqual(self.builds[0].name, 'project-merge')
1865
1866 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1867 self.waitUntilSettled()
1868
James E. Blair08d19992016-08-10 15:25:31 -07001869 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001870 self.waitUntilSettled()
1871
Arie5b4048c2016-10-05 16:12:06 +03001872 self.assertBuilds([])
1873 self.assertHistory([
1874 dict(name='project-merge', result='ABORTED', changes='1,1')],
1875 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001876 self.assertEqual(A.reported, 1,
1877 "Abandoned gate change should report only start")
1878
James E. Blairec056492016-07-22 09:45:56 -07001879 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001880 def test_abandoned_check(self):
1881 "Test that an abandoned change is dequeued from check"
1882
James E. Blair08d19992016-08-10 15:25:31 -07001883 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001884
1885 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1886 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1887 check_pipeline = self.sched.layout.pipelines['check']
1888
1889 # Add two git-dependent changes
1890 B.setDependsOn(A, 1)
1891 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1892 self.waitUntilSettled()
1893 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1894 self.waitUntilSettled()
1895 # A live item, and a non-live/live pair
1896 items = check_pipeline.getAllItems()
1897 self.assertEqual(len(items), 3)
1898
1899 self.assertEqual(items[0].change.number, '1')
1900 self.assertFalse(items[0].live)
1901
1902 self.assertEqual(items[1].change.number, '2')
1903 self.assertTrue(items[1].live)
1904
1905 self.assertEqual(items[2].change.number, '1')
1906 self.assertTrue(items[2].live)
1907
1908 # Abandon A
1909 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1910 self.waitUntilSettled()
1911
1912 # The live copy of A should be gone, but the non-live and B
1913 # should continue
1914 items = check_pipeline.getAllItems()
1915 self.assertEqual(len(items), 2)
1916
1917 self.assertEqual(items[0].change.number, '1')
1918 self.assertFalse(items[0].live)
1919
1920 self.assertEqual(items[1].change.number, '2')
1921 self.assertTrue(items[1].live)
1922
James E. Blair08d19992016-08-10 15:25:31 -07001923 self.launch_server.hold_jobs_in_build = False
1924 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001925 self.waitUntilSettled()
1926
1927 self.assertEqual(len(self.history), 4)
1928 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001929 'Build should have been aborted')
1930 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001931 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001932
James E. Blairec056492016-07-22 09:45:56 -07001933 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001934 def test_abandoned_not_timer(self):
1935 "Test that an abandoned change does not cancel timer jobs"
1936
James E. Blair08d19992016-08-10 15:25:31 -07001937 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001938
1939 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001940 self.updateConfigLayout(
1941 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001942 self.sched.reconfigure(self.config)
1943 self.registerJobs()
1944 # The pipeline triggers every second, so we should have seen
1945 # several by now.
1946 time.sleep(5)
1947 self.waitUntilSettled()
1948 # Stop queuing timer triggered jobs so that the assertions
1949 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001950 self.updateConfigLayout(
1951 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001952 self.sched.reconfigure(self.config)
1953 self.registerJobs()
1954 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1955
1956 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1957 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1958 self.waitUntilSettled()
1959 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1960
1961 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1962 self.waitUntilSettled()
1963
1964 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1965
James E. Blair08d19992016-08-10 15:25:31 -07001966 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001967 self.waitUntilSettled()
1968
James E. Blairec056492016-07-22 09:45:56 -07001969 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001970 def test_zuul_url_return(self):
1971 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001972 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001973 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001974
1975 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001976 A.addApproval('code-review', 2)
1977 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001978 self.waitUntilSettled()
1979
1980 self.assertEqual(len(self.builds), 1)
1981 for build in self.builds:
1982 self.assertTrue('ZUUL_URL' in build.parameters)
1983
James E. Blair08d19992016-08-10 15:25:31 -07001984 self.launch_server.hold_jobs_in_build = False
1985 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001986 self.waitUntilSettled()
1987
James E. Blairec056492016-07-22 09:45:56 -07001988 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001989 def test_new_patchset_dequeues_old_on_head(self):
1990 "Test that a new patchset causes the old to be dequeued (at head)"
1991 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001992 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001993 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1994 M.setMerged()
1995 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1996 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1997 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1998 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001999 A.addApproval('code-review', 2)
2000 B.addApproval('code-review', 2)
2001 C.addApproval('code-review', 2)
2002 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002003
2004 C.setDependsOn(B, 1)
2005 B.setDependsOn(A, 1)
2006 A.setDependsOn(M, 1)
2007
James E. Blair8b5408c2016-08-08 15:37:46 -07002008 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2009 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2010 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2011 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002012 self.waitUntilSettled()
2013
2014 A.addPatchset()
2015 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2016 self.waitUntilSettled()
2017
James E. Blair08d19992016-08-10 15:25:31 -07002018 self.launch_server.hold_jobs_in_build = False
2019 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002020 self.waitUntilSettled()
2021
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002022 self.assertEqual(A.data['status'], 'NEW')
2023 self.assertEqual(A.reported, 2)
2024 self.assertEqual(B.data['status'], 'NEW')
2025 self.assertEqual(B.reported, 2)
2026 self.assertEqual(C.data['status'], 'NEW')
2027 self.assertEqual(C.reported, 2)
2028 self.assertEqual(D.data['status'], 'MERGED')
2029 self.assertEqual(D.reported, 2)
2030 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002031
James E. Blairec056492016-07-22 09:45:56 -07002032 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002033 def test_new_patchset_dequeues_old_without_dependents(self):
2034 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002035 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002036 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2037 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2038 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002039 A.addApproval('code-review', 2)
2040 B.addApproval('code-review', 2)
2041 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002042
James E. Blair8b5408c2016-08-08 15:37:46 -07002043 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2044 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2045 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002046 self.waitUntilSettled()
2047
2048 B.addPatchset()
2049 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2050 self.waitUntilSettled()
2051
James E. Blair08d19992016-08-10 15:25:31 -07002052 self.launch_server.hold_jobs_in_build = False
2053 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002054 self.waitUntilSettled()
2055
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002056 self.assertEqual(A.data['status'], 'MERGED')
2057 self.assertEqual(A.reported, 2)
2058 self.assertEqual(B.data['status'], 'NEW')
2059 self.assertEqual(B.reported, 2)
2060 self.assertEqual(C.data['status'], 'MERGED')
2061 self.assertEqual(C.reported, 2)
2062 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002063
James E. Blairec056492016-07-22 09:45:56 -07002064 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002065 def test_new_patchset_dequeues_old_independent_queue(self):
2066 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002067 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002068 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2069 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2070 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2071 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2072 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2073 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2074 self.waitUntilSettled()
2075
2076 B.addPatchset()
2077 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2078 self.waitUntilSettled()
2079
James E. Blair08d19992016-08-10 15:25:31 -07002080 self.launch_server.hold_jobs_in_build = False
2081 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002082 self.waitUntilSettled()
2083
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002084 self.assertEqual(A.data['status'], 'NEW')
2085 self.assertEqual(A.reported, 1)
2086 self.assertEqual(B.data['status'], 'NEW')
2087 self.assertEqual(B.reported, 1)
2088 self.assertEqual(C.data['status'], 'NEW')
2089 self.assertEqual(C.reported, 1)
2090 self.assertEqual(len(self.history), 10)
2091 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002092
James E. Blairec056492016-07-22 09:45:56 -07002093 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002094 def test_noop_job(self):
2095 "Test that the internal noop job works"
2096 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002097 A.addApproval('code-review', 2)
2098 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002099 self.waitUntilSettled()
2100
2101 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2102 self.assertTrue(self.sched._areAllBuildsComplete())
2103 self.assertEqual(len(self.history), 0)
2104 self.assertEqual(A.data['status'], 'MERGED')
2105 self.assertEqual(A.reported, 2)
2106
James E. Blairec056492016-07-22 09:45:56 -07002107 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002108 def test_no_job_project(self):
2109 "Test that reports with no jobs don't get sent"
2110 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2111 'master', 'A')
2112 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2113 self.waitUntilSettled()
2114
2115 # Change wasn't reported to
2116 self.assertEqual(A.reported, False)
2117
2118 # Check queue is empty afterwards
2119 check_pipeline = self.sched.layout.pipelines['check']
2120 items = check_pipeline.getAllItems()
2121 self.assertEqual(len(items), 0)
2122
2123 self.assertEqual(len(self.history), 0)
2124
James E. Blairec056492016-07-22 09:45:56 -07002125 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002126 def test_zuul_refs(self):
2127 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002128 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002129 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2130 M1.setMerged()
2131 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2132 M2.setMerged()
2133
2134 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2135 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2136 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2137 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002138 A.addApproval('code-review', 2)
2139 B.addApproval('code-review', 2)
2140 C.addApproval('code-review', 2)
2141 D.addApproval('code-review', 2)
2142 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2143 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2144 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2145 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002146
2147 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002148 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002149 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002150 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002151 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002152 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002153 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002154 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002155 self.waitUntilSettled()
2156
James E. Blair7d0dedc2013-02-21 17:26:09 -08002157 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002158 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002159 if x.parameters['ZUUL_CHANGE'] == '3':
2160 a_zref = x.parameters['ZUUL_REF']
2161 if x.parameters['ZUUL_CHANGE'] == '4':
2162 b_zref = x.parameters['ZUUL_REF']
2163 if x.parameters['ZUUL_CHANGE'] == '5':
2164 c_zref = x.parameters['ZUUL_REF']
2165 if x.parameters['ZUUL_CHANGE'] == '6':
2166 d_zref = x.parameters['ZUUL_REF']
2167
2168 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002169 self.assertIsNotNone(a_zref)
2170 self.assertIsNotNone(b_zref)
2171 self.assertIsNotNone(c_zref)
2172 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002173
2174 # And they should all be different
2175 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002176 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002177
2178 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002179 self.assertTrue(self.ref_has_change(a_zref, A))
2180 self.assertFalse(self.ref_has_change(a_zref, B))
2181 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002182
2183 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002184 self.assertTrue(self.ref_has_change(b_zref, A))
2185 self.assertTrue(self.ref_has_change(b_zref, B))
2186 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002187
2188 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002189 self.assertTrue(self.ref_has_change(c_zref, A))
2190 self.assertTrue(self.ref_has_change(c_zref, B))
2191 self.assertTrue(self.ref_has_change(c_zref, C))
2192 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002193
2194 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002195 self.assertTrue(self.ref_has_change(d_zref, A))
2196 self.assertTrue(self.ref_has_change(d_zref, B))
2197 self.assertTrue(self.ref_has_change(d_zref, C))
2198 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002199
James E. Blair08d19992016-08-10 15:25:31 -07002200 self.launch_server.hold_jobs_in_build = False
2201 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002202 self.waitUntilSettled()
2203
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002204 self.assertEqual(A.data['status'], 'MERGED')
2205 self.assertEqual(A.reported, 2)
2206 self.assertEqual(B.data['status'], 'MERGED')
2207 self.assertEqual(B.reported, 2)
2208 self.assertEqual(C.data['status'], 'MERGED')
2209 self.assertEqual(C.reported, 2)
2210 self.assertEqual(D.data['status'], 'MERGED')
2211 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002212
James E. Blairec056492016-07-22 09:45:56 -07002213 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002214 def test_rerun_on_error(self):
2215 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002216 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002217 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002218 A.addApproval('code-review', 2)
2219 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002220 self.waitUntilSettled()
2221
2222 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002223 self.launch_server.hold_jobs_in_build = False
2224 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002225 self.waitUntilSettled()
2226 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2227 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2228
James E. Blairec056492016-07-22 09:45:56 -07002229 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002230 def test_statsd(self):
2231 "Test each of the statsd methods used in the scheduler"
2232 import extras
2233 statsd = extras.try_import('statsd.statsd')
2234 statsd.incr('test-incr')
2235 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002236 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002237 self.assertReportedStat('test-incr', '1|c')
2238 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002239 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002240
James E. Blairec056492016-07-22 09:45:56 -07002241 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002242 def test_stuck_job_cleanup(self):
2243 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002244 # This job won't be registered at startup because it is not in
2245 # the standard layout, but we need it to already be registerd
2246 # for when we reconfigure, as that is when Zuul will attempt
2247 # to run the new job.
2248 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002249 self.gearman_server.hold_jobs_in_queue = True
2250 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002251 A.addApproval('code-review', 2)
2252 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002253 self.waitUntilSettled()
2254 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2255
James E. Blairf84026c2015-12-08 16:11:46 -08002256 self.updateConfigLayout(
2257 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002258 self.sched.reconfigure(self.config)
2259 self.waitUntilSettled()
2260
James E. Blair18c64442014-03-18 10:14:45 -07002261 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002262 self.waitUntilSettled()
2263 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2264 self.assertTrue(self.sched._areAllBuildsComplete())
2265
2266 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002267 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002268 self.assertEqual(self.history[0].result, 'SUCCESS')
2269
James E. Blairec056492016-07-22 09:45:56 -07002270 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002271 def test_file_head(self):
2272 # This is a regression test for an observed bug. A change
2273 # with a file named "HEAD" in the root directory of the repo
2274 # was processed by a merger. It then was unable to reset the
2275 # repo because of:
2276 # GitCommandError: 'git reset --hard HEAD' returned
2277 # with exit code 128
2278 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2279 # and filename
2280 # Use '--' to separate filenames from revisions'
2281
2282 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2283 A.addPatchset(['HEAD'])
2284 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2285
2286 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2287 self.waitUntilSettled()
2288
2289 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2290 self.waitUntilSettled()
2291
2292 self.assertIn('Build succeeded', A.messages[0])
2293 self.assertIn('Build succeeded', B.messages[0])
2294
James E. Blairec056492016-07-22 09:45:56 -07002295 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002296 def test_file_jobs(self):
2297 "Test that file jobs run only when appropriate"
2298 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2299 A.addPatchset(['pip-requires'])
2300 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002301 A.addApproval('code-review', 2)
2302 B.addApproval('code-review', 2)
2303 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2304 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002305 self.waitUntilSettled()
2306
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002307 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002308 if x.name == 'project-testfile']
2309
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002310 self.assertEqual(len(testfile_jobs), 1)
2311 self.assertEqual(testfile_jobs[0].changes, '1,2')
2312 self.assertEqual(A.data['status'], 'MERGED')
2313 self.assertEqual(A.reported, 2)
2314 self.assertEqual(B.data['status'], 'MERGED')
2315 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002316
James E. Blairec056492016-07-22 09:45:56 -07002317 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002318 def _test_skip_if_jobs(self, branch, should_skip):
2319 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002320 self.updateConfigLayout(
2321 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002322 self.sched.reconfigure(self.config)
2323 self.registerJobs()
2324
2325 change = self.fake_gerrit.addFakeChange('org/project',
2326 branch,
2327 'test skip-if')
2328 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2329 self.waitUntilSettled()
2330
2331 tested_change_ids = [x.changes[0] for x in self.history
2332 if x.name == 'project-test-skip-if']
2333
2334 if should_skip:
2335 self.assertEqual([], tested_change_ids)
2336 else:
2337 self.assertIn(change.data['number'], tested_change_ids)
2338
James E. Blairec056492016-07-22 09:45:56 -07002339 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002340 def test_skip_if_match_skips_job(self):
2341 self._test_skip_if_jobs(branch='master', should_skip=True)
2342
James E. Blairec056492016-07-22 09:45:56 -07002343 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002344 def test_skip_if_no_match_runs_job(self):
2345 self._test_skip_if_jobs(branch='mp', should_skip=False)
2346
James E. Blairec056492016-07-22 09:45:56 -07002347 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002348 def test_test_config(self):
2349 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002350 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002351 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002352
James E. Blairec056492016-07-22 09:45:56 -07002353 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002354 def test_queue_names(self):
2355 "Test shared change queue names"
2356 project1 = self.sched.layout.projects['org/project1']
2357 project2 = self.sched.layout.projects['org/project2']
2358 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2359 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2360 self.assertEqual(q1.name, 'integration')
2361 self.assertEqual(q2.name, 'integration')
2362
James E. Blairf84026c2015-12-08 16:11:46 -08002363 self.updateConfigLayout(
2364 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002365 with testtools.ExpectedException(
2366 Exception, "More than one name assigned to change queue"):
2367 self.sched.reconfigure(self.config)
2368
James E. Blairec056492016-07-22 09:45:56 -07002369 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002370 def test_queue_precedence(self):
2371 "Test that queue precedence works"
2372
2373 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002374 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002375 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2376 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002377 A.addApproval('code-review', 2)
2378 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002379
2380 self.waitUntilSettled()
2381 self.gearman_server.hold_jobs_in_queue = False
2382 self.gearman_server.release()
2383 self.waitUntilSettled()
2384
James E. Blair8de58bd2013-07-18 16:23:33 -07002385 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002386 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002387 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002388 self.waitUntilSettled()
2389
James E. Blair64ed6f22013-07-10 14:07:23 -07002390 self.log.debug(self.history)
2391 self.assertEqual(self.history[0].pipeline, 'gate')
2392 self.assertEqual(self.history[1].pipeline, 'check')
2393 self.assertEqual(self.history[2].pipeline, 'gate')
2394 self.assertEqual(self.history[3].pipeline, 'gate')
2395 self.assertEqual(self.history[4].pipeline, 'check')
2396 self.assertEqual(self.history[5].pipeline, 'check')
2397
James E. Blairec056492016-07-22 09:45:56 -07002398 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002399 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002400 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002401 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002402 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002403 A.addApproval('code-review', 2)
2404 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002405 self.waitUntilSettled()
2406
James E. Blair08d19992016-08-10 15:25:31 -07002407 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002408 self.waitUntilSettled()
2409
James E. Blair1843a552013-07-03 14:19:52 -07002410 port = self.webapp.server.socket.getsockname()[1]
2411
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002412 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2413 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002414 headers = f.info()
2415 self.assertIn('Content-Length', headers)
2416 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002417 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2418 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002419 self.assertIn('Access-Control-Allow-Origin', headers)
2420 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002421 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002422 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002423 data = f.read()
2424
James E. Blair08d19992016-08-10 15:25:31 -07002425 self.launch_server.hold_jobs_in_build = False
2426 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002427 self.waitUntilSettled()
2428
2429 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002430 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002431 for p in data['pipelines']:
2432 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002433 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002434 self.assertEqual(q['window'], 20)
2435 else:
2436 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002437 for head in q['heads']:
2438 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002439 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002440 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002441 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002442 status_jobs.append(job)
2443 self.assertEqual('project-merge', status_jobs[0]['name'])
2444 self.assertEqual('https://server/job/project-merge/0/',
2445 status_jobs[0]['url'])
2446 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2447 status_jobs[0]['report_url'])
2448
2449 self.assertEqual('project-test1', status_jobs[1]['name'])
2450 self.assertEqual('https://server/job/project-test1/1/',
2451 status_jobs[1]['url'])
2452 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2453 status_jobs[1]['report_url'])
2454
2455 self.assertEqual('project-test2', status_jobs[2]['name'])
2456 self.assertEqual('https://server/job/project-test2/2/',
2457 status_jobs[2]['url'])
2458 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2459 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002460
James E. Blairec056492016-07-22 09:45:56 -07002461 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002462 def test_merging_queues(self):
2463 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002464 self.updateConfigLayout(
2465 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002466 self.sched.reconfigure(self.config)
2467 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2468
James E. Blairec056492016-07-22 09:45:56 -07002469 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002470 def test_mutex(self):
2471 "Test job mutexes"
2472 self.config.set('zuul', 'layout_config',
2473 'tests/fixtures/layout-mutex.yaml')
2474 self.sched.reconfigure(self.config)
2475
James E. Blair08d19992016-08-10 15:25:31 -07002476 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002477 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2478 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2479 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2480
2481 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2482 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2483 self.waitUntilSettled()
2484 self.assertEqual(len(self.builds), 3)
2485 self.assertEqual(self.builds[0].name, 'project-test1')
2486 self.assertEqual(self.builds[1].name, 'mutex-one')
2487 self.assertEqual(self.builds[2].name, 'project-test1')
2488
James E. Blair08d19992016-08-10 15:25:31 -07002489 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002490 self.waitUntilSettled()
2491
2492 self.assertEqual(len(self.builds), 3)
2493 self.assertEqual(self.builds[0].name, 'project-test1')
2494 self.assertEqual(self.builds[1].name, 'project-test1')
2495 self.assertEqual(self.builds[2].name, 'mutex-two')
2496 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2497
James E. Blair08d19992016-08-10 15:25:31 -07002498 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002499 self.waitUntilSettled()
2500
2501 self.assertEqual(len(self.builds), 3)
2502 self.assertEqual(self.builds[0].name, 'project-test1')
2503 self.assertEqual(self.builds[1].name, 'project-test1')
2504 self.assertEqual(self.builds[2].name, 'mutex-one')
2505 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2506
James E. Blair08d19992016-08-10 15:25:31 -07002507 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002508 self.waitUntilSettled()
2509
2510 self.assertEqual(len(self.builds), 3)
2511 self.assertEqual(self.builds[0].name, 'project-test1')
2512 self.assertEqual(self.builds[1].name, 'project-test1')
2513 self.assertEqual(self.builds[2].name, 'mutex-two')
2514 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2515
James E. Blair08d19992016-08-10 15:25:31 -07002516 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002517 self.waitUntilSettled()
2518
2519 self.assertEqual(len(self.builds), 2)
2520 self.assertEqual(self.builds[0].name, 'project-test1')
2521 self.assertEqual(self.builds[1].name, 'project-test1')
2522 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2523
James E. Blair08d19992016-08-10 15:25:31 -07002524 self.launch_server.hold_jobs_in_build = False
2525 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002526
2527 self.waitUntilSettled()
2528 self.assertEqual(len(self.builds), 0)
2529
2530 self.assertEqual(A.reported, 1)
2531 self.assertEqual(B.reported, 1)
2532 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2533
James E. Blairec056492016-07-22 09:45:56 -07002534 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002535 def test_node_label(self):
2536 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002537 self.worker.registerFunction('build:node-project-test1:debian')
2538
2539 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002540 A.addApproval('code-review', 2)
2541 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002542 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002543
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002544 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2545 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2546 'debian')
2547 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002548
James E. Blairec056492016-07-22 09:45:56 -07002549 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002550 def test_live_reconfiguration(self):
2551 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002552 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002553 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002554 A.addApproval('code-review', 2)
2555 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002556 self.waitUntilSettled()
2557
2558 self.sched.reconfigure(self.config)
2559
James E. Blair08d19992016-08-10 15:25:31 -07002560 self.launch_server.hold_jobs_in_build = False
2561 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002562 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002563 self.assertEqual(self.getJobFromHistory('project-merge').result,
2564 'SUCCESS')
2565 self.assertEqual(self.getJobFromHistory('project-test1').result,
2566 'SUCCESS')
2567 self.assertEqual(self.getJobFromHistory('project-test2').result,
2568 'SUCCESS')
2569 self.assertEqual(A.data['status'], 'MERGED')
2570 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002571
James E. Blairec056492016-07-22 09:45:56 -07002572 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002573 def test_live_reconfiguration_merge_conflict(self):
2574 # A real-world bug: a change in a gate queue has a merge
2575 # conflict and a job is added to its project while it's
2576 # sitting in the queue. The job gets added to the change and
2577 # enqueued and the change gets stuck.
2578 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002579 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002580
2581 # This change is fine. It's here to stop the queue long
2582 # enough for the next change to be subject to the
2583 # reconfiguration, as well as to provide a conflict for the
2584 # next change. This change will succeed and merge.
2585 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2586 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002587 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002588
2589 # This change will be in merge conflict. During the
2590 # reconfiguration, we will add a job. We want to make sure
2591 # that doesn't cause it to get stuck.
2592 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2593 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002594 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002595
James E. Blair8b5408c2016-08-08 15:37:46 -07002596 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2597 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002598
2599 self.waitUntilSettled()
2600
2601 # No jobs have run yet
2602 self.assertEqual(A.data['status'], 'NEW')
2603 self.assertEqual(A.reported, 1)
2604 self.assertEqual(B.data['status'], 'NEW')
2605 self.assertEqual(B.reported, 1)
2606 self.assertEqual(len(self.history), 0)
2607
2608 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002609 self.updateConfigLayout(
2610 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002611 self.sched.reconfigure(self.config)
2612 self.waitUntilSettled()
2613
James E. Blair08d19992016-08-10 15:25:31 -07002614 self.launch_server.hold_jobs_in_build = False
2615 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002616 self.waitUntilSettled()
2617
2618 self.assertEqual(A.data['status'], 'MERGED')
2619 self.assertEqual(A.reported, 2)
2620 self.assertEqual(B.data['status'], 'NEW')
2621 self.assertEqual(B.reported, 2)
2622 self.assertEqual(self.getJobFromHistory('project-merge').result,
2623 'SUCCESS')
2624 self.assertEqual(self.getJobFromHistory('project-test1').result,
2625 'SUCCESS')
2626 self.assertEqual(self.getJobFromHistory('project-test2').result,
2627 'SUCCESS')
2628 self.assertEqual(self.getJobFromHistory('project-test3').result,
2629 'SUCCESS')
2630 self.assertEqual(len(self.history), 4)
2631
James E. Blairec056492016-07-22 09:45:56 -07002632 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002633 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002634 # An extrapolation of test_live_reconfiguration_merge_conflict
2635 # that tests a job added to a job tree with a failed root does
2636 # not run.
2637 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002638 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002639
2640 # This change is fine. It's here to stop the queue long
2641 # enough for the next change to be subject to the
2642 # reconfiguration. This change will succeed and merge.
2643 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2644 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002645 A.addApproval('code-review', 2)
2646 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002647 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002648 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002649 self.waitUntilSettled()
2650
2651 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002652 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002653 B.addApproval('code-review', 2)
2654 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002655 self.waitUntilSettled()
2656
James E. Blair08d19992016-08-10 15:25:31 -07002657 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002658 self.waitUntilSettled()
2659
2660 # Both -merge jobs have run, but no others.
2661 self.assertEqual(A.data['status'], 'NEW')
2662 self.assertEqual(A.reported, 1)
2663 self.assertEqual(B.data['status'], 'NEW')
2664 self.assertEqual(B.reported, 1)
2665 self.assertEqual(self.history[0].result, 'SUCCESS')
2666 self.assertEqual(self.history[0].name, 'project-merge')
2667 self.assertEqual(self.history[1].result, 'FAILURE')
2668 self.assertEqual(self.history[1].name, 'project-merge')
2669 self.assertEqual(len(self.history), 2)
2670
2671 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002672 self.updateConfigLayout(
2673 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002674 self.sched.reconfigure(self.config)
2675 self.waitUntilSettled()
2676
James E. Blair08d19992016-08-10 15:25:31 -07002677 self.launch_server.hold_jobs_in_build = False
2678 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002679 self.waitUntilSettled()
2680
2681 self.assertEqual(A.data['status'], 'MERGED')
2682 self.assertEqual(A.reported, 2)
2683 self.assertEqual(B.data['status'], 'NEW')
2684 self.assertEqual(B.reported, 2)
2685 self.assertEqual(self.history[0].result, 'SUCCESS')
2686 self.assertEqual(self.history[0].name, 'project-merge')
2687 self.assertEqual(self.history[1].result, 'FAILURE')
2688 self.assertEqual(self.history[1].name, 'project-merge')
2689 self.assertEqual(self.history[2].result, 'SUCCESS')
2690 self.assertEqual(self.history[3].result, 'SUCCESS')
2691 self.assertEqual(self.history[4].result, 'SUCCESS')
2692 self.assertEqual(len(self.history), 5)
2693
James E. Blairec056492016-07-22 09:45:56 -07002694 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002695 def test_live_reconfiguration_failed_job(self):
2696 # Test that a change with a removed failing job does not
2697 # disrupt reconfiguration. If a change has a failed job and
2698 # that job is removed during a reconfiguration, we observed a
2699 # bug where the code to re-set build statuses would run on
2700 # that build and raise an exception because the job no longer
2701 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002702 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002703
2704 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2705
2706 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002707 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002708
2709 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2710 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002711 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002712 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002713 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002714 self.waitUntilSettled()
2715
2716 self.assertEqual(A.data['status'], 'NEW')
2717 self.assertEqual(A.reported, 0)
2718
2719 self.assertEqual(self.getJobFromHistory('project-merge').result,
2720 'SUCCESS')
2721 self.assertEqual(self.getJobFromHistory('project-test1').result,
2722 'FAILURE')
2723 self.assertEqual(len(self.history), 2)
2724
2725 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002726 self.updateConfigLayout(
2727 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002728 self.sched.reconfigure(self.config)
2729 self.waitUntilSettled()
2730
James E. Blair08d19992016-08-10 15:25:31 -07002731 self.launch_server.hold_jobs_in_build = False
2732 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002733 self.waitUntilSettled()
2734
2735 self.assertEqual(self.getJobFromHistory('project-test2').result,
2736 'SUCCESS')
2737 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2738 'SUCCESS')
2739 self.assertEqual(len(self.history), 4)
2740
2741 self.assertEqual(A.data['status'], 'NEW')
2742 self.assertEqual(A.reported, 1)
2743 self.assertIn('Build succeeded', A.messages[0])
2744 # Ensure the removed job was not included in the report.
2745 self.assertNotIn('project-test1', A.messages[0])
2746
James E. Blairec056492016-07-22 09:45:56 -07002747 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002748 def test_live_reconfiguration_shared_queue(self):
2749 # Test that a change with a failing job which was removed from
2750 # this project but otherwise still exists in the system does
2751 # not disrupt reconfiguration.
2752
James E. Blair08d19992016-08-10 15:25:31 -07002753 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002754
2755 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2756
James E. Blair08d19992016-08-10 15:25:31 -07002757 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002758
2759 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2760 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002761 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002762 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002763 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002764 self.waitUntilSettled()
2765
2766 self.assertEqual(A.data['status'], 'NEW')
2767 self.assertEqual(A.reported, 0)
2768
2769 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2770 'SUCCESS')
2771 self.assertEqual(self.getJobFromHistory(
2772 'project1-project2-integration').result, 'FAILURE')
2773 self.assertEqual(len(self.history), 2)
2774
2775 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002776 self.updateConfigLayout(
2777 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002778 self.sched.reconfigure(self.config)
2779 self.waitUntilSettled()
2780
James E. Blair08d19992016-08-10 15:25:31 -07002781 self.launch_server.hold_jobs_in_build = False
2782 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002783 self.waitUntilSettled()
2784
2785 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2786 'SUCCESS')
2787 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2788 'SUCCESS')
2789 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2790 'SUCCESS')
2791 self.assertEqual(self.getJobFromHistory(
2792 'project1-project2-integration').result, 'FAILURE')
2793 self.assertEqual(len(self.history), 4)
2794
2795 self.assertEqual(A.data['status'], 'NEW')
2796 self.assertEqual(A.reported, 1)
2797 self.assertIn('Build succeeded', A.messages[0])
2798 # Ensure the removed job was not included in the report.
2799 self.assertNotIn('project1-project2-integration', A.messages[0])
2800
James E. Blairec056492016-07-22 09:45:56 -07002801 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002802 def test_double_live_reconfiguration_shared_queue(self):
2803 # This was a real-world regression. A change is added to
2804 # gate; a reconfigure happens, a second change which depends
2805 # on the first is added, and a second reconfiguration happens.
2806 # Ensure that both changes merge.
2807
2808 # A failure may indicate incorrect caching or cleaning up of
2809 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002810 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002811
2812 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2813 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2814 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002815 A.addApproval('code-review', 2)
2816 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002817
2818 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002819 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002820 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002821 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002822 self.waitUntilSettled()
2823
2824 # Reconfigure (with only one change in the pipeline).
2825 self.sched.reconfigure(self.config)
2826 self.waitUntilSettled()
2827
2828 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002829 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002830 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002831 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002832 self.waitUntilSettled()
2833
2834 # Reconfigure (with both in the pipeline).
2835 self.sched.reconfigure(self.config)
2836 self.waitUntilSettled()
2837
James E. Blair08d19992016-08-10 15:25:31 -07002838 self.launch_server.hold_jobs_in_build = False
2839 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002840 self.waitUntilSettled()
2841
2842 self.assertEqual(len(self.history), 8)
2843
2844 self.assertEqual(A.data['status'], 'MERGED')
2845 self.assertEqual(A.reported, 2)
2846 self.assertEqual(B.data['status'], 'MERGED')
2847 self.assertEqual(B.reported, 2)
2848
James E. Blairec056492016-07-22 09:45:56 -07002849 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002850 def test_live_reconfiguration_del_project(self):
2851 # Test project deletion from layout
2852 # while changes are enqueued
2853
James E. Blair08d19992016-08-10 15:25:31 -07002854 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002855 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2856 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2857 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2858
2859 # A Depends-On: B
2860 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2861 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002862 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002863
2864 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2865 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2866 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002867 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002868 self.waitUntilSettled()
2869 self.assertEqual(len(self.builds), 5)
2870
2871 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002872 self.updateConfigLayout(
2873 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002874 self.sched.reconfigure(self.config)
2875 self.waitUntilSettled()
2876
2877 # Builds for C aborted, builds for A succeed,
2878 # and have change B applied ahead
2879 job_c = self.getJobFromHistory('project1-test1')
2880 self.assertEqual(job_c.changes, '3,1')
2881 self.assertEqual(job_c.result, 'ABORTED')
2882
James E. Blair08d19992016-08-10 15:25:31 -07002883 self.launch_server.hold_jobs_in_build = False
2884 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002885 self.waitUntilSettled()
2886
2887 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2888 '2,1 1,1')
2889
2890 self.assertEqual(A.data['status'], 'NEW')
2891 self.assertEqual(B.data['status'], 'NEW')
2892 self.assertEqual(C.data['status'], 'NEW')
2893 self.assertEqual(A.reported, 1)
2894 self.assertEqual(B.reported, 0)
2895 self.assertEqual(C.reported, 0)
2896
2897 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2898 self.assertIn('Build succeeded', A.messages[0])
2899
James E. Blairec056492016-07-22 09:45:56 -07002900 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002901 def test_live_reconfiguration_functions(self):
2902 "Test live reconfiguration with a custom function"
2903 self.worker.registerFunction('build:node-project-test1:debian')
2904 self.worker.registerFunction('build:node-project-test1:wheezy')
2905 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002906 A.addApproval('code-review', 2)
2907 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002908 self.waitUntilSettled()
2909
2910 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2911 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2912 'debian')
2913 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2914
James E. Blairf84026c2015-12-08 16:11:46 -08002915 self.updateConfigLayout(
2916 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002917 self.sched.reconfigure(self.config)
2918 self.worker.build_history = []
2919
2920 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002921 B.addApproval('code-review', 2)
2922 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002923 self.waitUntilSettled()
2924
2925 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2926 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2927 'wheezy')
2928 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2929
James E. Blairec056492016-07-22 09:45:56 -07002930 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002931 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002932 self.updateConfigLayout(
2933 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002934 self.sched.reconfigure(self.config)
2935
2936 self.init_repo("org/new-project")
2937 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2938
James E. Blair8b5408c2016-08-08 15:37:46 -07002939 A.addApproval('code-review', 2)
2940 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002941 self.waitUntilSettled()
2942 self.assertEqual(self.getJobFromHistory('project-merge').result,
2943 'SUCCESS')
2944 self.assertEqual(self.getJobFromHistory('project-test1').result,
2945 'SUCCESS')
2946 self.assertEqual(self.getJobFromHistory('project-test2').result,
2947 'SUCCESS')
2948 self.assertEqual(A.data['status'], 'MERGED')
2949 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002950
James E. Blairec056492016-07-22 09:45:56 -07002951 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002952 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002953 self.updateConfigLayout(
2954 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002955 self.sched.reconfigure(self.config)
2956
2957 self.init_repo("org/delete-project")
2958 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2959
James E. Blair8b5408c2016-08-08 15:37:46 -07002960 A.addApproval('code-review', 2)
2961 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002962 self.waitUntilSettled()
2963 self.assertEqual(self.getJobFromHistory('project-merge').result,
2964 'SUCCESS')
2965 self.assertEqual(self.getJobFromHistory('project-test1').result,
2966 'SUCCESS')
2967 self.assertEqual(self.getJobFromHistory('project-test2').result,
2968 'SUCCESS')
2969 self.assertEqual(A.data['status'], 'MERGED')
2970 self.assertEqual(A.reported, 2)
2971
2972 # Delete org/new-project zuul repo. Should be recloned.
2973 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2974
2975 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2976
James E. Blair8b5408c2016-08-08 15:37:46 -07002977 B.addApproval('code-review', 2)
2978 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002979 self.waitUntilSettled()
2980 self.assertEqual(self.getJobFromHistory('project-merge').result,
2981 'SUCCESS')
2982 self.assertEqual(self.getJobFromHistory('project-test1').result,
2983 'SUCCESS')
2984 self.assertEqual(self.getJobFromHistory('project-test2').result,
2985 'SUCCESS')
2986 self.assertEqual(B.data['status'], 'MERGED')
2987 self.assertEqual(B.reported, 2)
2988
James E. Blairec056492016-07-22 09:45:56 -07002989 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002990 def test_tags(self):
2991 "Test job tags"
2992 self.config.set('zuul', 'layout_config',
2993 'tests/fixtures/layout-tags.yaml')
2994 self.sched.reconfigure(self.config)
2995
2996 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2997 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2998 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2999 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
3000 self.waitUntilSettled()
3001
3002 results = {'project1-merge': 'extratag merge project1',
3003 'project2-merge': 'merge'}
3004
3005 for build in self.history:
3006 self.assertEqual(results.get(build.name, ''),
3007 build.parameters.get('BUILD_TAGS'))
3008
James E. Blairec056492016-07-22 09:45:56 -07003009 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07003010 def test_timer(self):
3011 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003012 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003013 self.updateConfigLayout(
3014 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07003015 self.sched.reconfigure(self.config)
3016 self.registerJobs()
3017
Clark Boylan3ee090a2014-04-03 20:55:09 -07003018 # The pipeline triggers every second, so we should have seen
3019 # several by now.
3020 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003021 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003022
3023 self.assertEqual(len(self.builds), 2)
3024
James E. Blair63bb0ef2013-07-29 17:14:51 -07003025 port = self.webapp.server.socket.getsockname()[1]
3026
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003027 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3028 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003029 data = f.read()
3030
James E. Blair08d19992016-08-10 15:25:31 -07003031 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003032 # Stop queuing timer triggered jobs so that the assertions
3033 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003034 self.updateConfigLayout(
3035 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003036 self.sched.reconfigure(self.config)
3037 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003038 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003039 self.waitUntilSettled()
3040
3041 self.assertEqual(self.getJobFromHistory(
3042 'project-bitrot-stable-old').result, 'SUCCESS')
3043 self.assertEqual(self.getJobFromHistory(
3044 'project-bitrot-stable-older').result, 'SUCCESS')
3045
3046 data = json.loads(data)
3047 status_jobs = set()
3048 for p in data['pipelines']:
3049 for q in p['change_queues']:
3050 for head in q['heads']:
3051 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003052 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003053 for job in change['jobs']:
3054 status_jobs.add(job['name'])
3055 self.assertIn('project-bitrot-stable-old', status_jobs)
3056 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003057
James E. Blairec056492016-07-22 09:45:56 -07003058 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003059 def test_idle(self):
3060 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003061 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003062
Clark Boylan3ee090a2014-04-03 20:55:09 -07003063 for x in range(1, 3):
3064 # Test that timer triggers periodic jobs even across
3065 # layout config reloads.
3066 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003067 self.updateConfigLayout(
3068 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003069 self.sched.reconfigure(self.config)
3070 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003071 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003072
Clark Boylan3ee090a2014-04-03 20:55:09 -07003073 # The pipeline triggers every second, so we should have seen
3074 # several by now.
3075 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003076
3077 # Stop queuing timer triggered jobs so that the assertions
3078 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003079 self.updateConfigLayout(
3080 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003081 self.sched.reconfigure(self.config)
3082 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003083 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003084
3085 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003086 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003087 self.waitUntilSettled()
3088 self.assertEqual(len(self.builds), 0)
3089 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003090
James E. Blairec056492016-07-22 09:45:56 -07003091 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003092 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003093 self.updateConfigLayout(
3094 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003095 self.sched.reconfigure(self.config)
3096
3097 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3098 self.waitUntilSettled()
3099
3100 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3101 self.waitUntilSettled()
3102
James E. Blairff80a2f2013-12-27 13:24:06 -08003103 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003104
3105 # A.messages only holds what FakeGerrit places in it. Thus we
3106 # work on the knowledge of what the first message should be as
3107 # it is only configured to go to SMTP.
3108
3109 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003110 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003111 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003112 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003113 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003114 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003115
3116 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003117 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003118 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003119 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003120 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003121 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003122
James E. Blairec056492016-07-22 09:45:56 -07003123 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003124 def test_timer_smtp(self):
3125 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003126 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003127 self.updateConfigLayout(
3128 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003129 self.sched.reconfigure(self.config)
3130 self.registerJobs()
3131
Clark Boylan3ee090a2014-04-03 20:55:09 -07003132 # The pipeline triggers every second, so we should have seen
3133 # several by now.
3134 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003135 self.waitUntilSettled()
3136
Clark Boylan3ee090a2014-04-03 20:55:09 -07003137 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003138 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003139 self.waitUntilSettled()
3140 self.assertEqual(len(self.history), 2)
3141
James E. Blaire5910202013-12-27 09:50:31 -08003142 self.assertEqual(self.getJobFromHistory(
3143 'project-bitrot-stable-old').result, 'SUCCESS')
3144 self.assertEqual(self.getJobFromHistory(
3145 'project-bitrot-stable-older').result, 'SUCCESS')
3146
James E. Blairff80a2f2013-12-27 13:24:06 -08003147 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003148
3149 # A.messages only holds what FakeGerrit places in it. Thus we
3150 # work on the knowledge of what the first message should be as
3151 # it is only configured to go to SMTP.
3152
3153 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003154 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003155 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003156 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003157 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003158 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003159
Clark Boylan3ee090a2014-04-03 20:55:09 -07003160 # Stop queuing timer triggered jobs and let any that may have
3161 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003162 self.updateConfigLayout(
3163 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003164 self.sched.reconfigure(self.config)
3165 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003166 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003167 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003168 self.waitUntilSettled()
3169
James E. Blairec056492016-07-22 09:45:56 -07003170 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003171 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003172 "Test that the RPC client can enqueue a change"
3173 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003174 A.addApproval('code-review', 2)
3175 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003176
3177 client = zuul.rpcclient.RPCClient('127.0.0.1',
3178 self.gearman_server.port)
3179 r = client.enqueue(pipeline='gate',
3180 project='org/project',
3181 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003182 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003183 self.waitUntilSettled()
3184 self.assertEqual(self.getJobFromHistory('project-merge').result,
3185 'SUCCESS')
3186 self.assertEqual(self.getJobFromHistory('project-test1').result,
3187 'SUCCESS')
3188 self.assertEqual(self.getJobFromHistory('project-test2').result,
3189 'SUCCESS')
3190 self.assertEqual(A.data['status'], 'MERGED')
3191 self.assertEqual(A.reported, 2)
3192 self.assertEqual(r, True)
3193
James E. Blairec056492016-07-22 09:45:56 -07003194 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003195 def test_client_enqueue_ref(self):
3196 "Test that the RPC client can enqueue a ref"
3197
3198 client = zuul.rpcclient.RPCClient('127.0.0.1',
3199 self.gearman_server.port)
3200 r = client.enqueue_ref(
3201 pipeline='post',
3202 project='org/project',
3203 trigger='gerrit',
3204 ref='master',
3205 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3206 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3207 self.waitUntilSettled()
3208 job_names = [x.name for x in self.history]
3209 self.assertEqual(len(self.history), 1)
3210 self.assertIn('project-post', job_names)
3211 self.assertEqual(r, True)
3212
James E. Blairec056492016-07-22 09:45:56 -07003213 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003214 def test_client_enqueue_negative(self):
3215 "Test that the RPC client returns errors"
3216 client = zuul.rpcclient.RPCClient('127.0.0.1',
3217 self.gearman_server.port)
3218 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3219 "Invalid project"):
3220 r = client.enqueue(pipeline='gate',
3221 project='project-does-not-exist',
3222 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003223 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003224 client.shutdown()
3225 self.assertEqual(r, False)
3226
3227 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3228 "Invalid pipeline"):
3229 r = client.enqueue(pipeline='pipeline-does-not-exist',
3230 project='org/project',
3231 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003232 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003233 client.shutdown()
3234 self.assertEqual(r, False)
3235
3236 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3237 "Invalid trigger"):
3238 r = client.enqueue(pipeline='gate',
3239 project='org/project',
3240 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003241 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003242 client.shutdown()
3243 self.assertEqual(r, False)
3244
3245 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3246 "Invalid change"):
3247 r = client.enqueue(pipeline='gate',
3248 project='org/project',
3249 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003250 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003251 client.shutdown()
3252 self.assertEqual(r, False)
3253
3254 self.waitUntilSettled()
3255 self.assertEqual(len(self.history), 0)
3256 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003257
James E. Blairec056492016-07-22 09:45:56 -07003258 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003259 def test_client_promote(self):
3260 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003261 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003262 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3263 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3264 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003265 A.addApproval('code-review', 2)
3266 B.addApproval('code-review', 2)
3267 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003268
James E. Blair8b5408c2016-08-08 15:37:46 -07003269 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3270 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3271 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003272
3273 self.waitUntilSettled()
3274
Sean Daguef39b9ca2014-01-10 21:34:35 -05003275 items = self.sched.layout.pipelines['gate'].getAllItems()
3276 enqueue_times = {}
3277 for item in items:
3278 enqueue_times[str(item.change)] = item.enqueue_time
3279
James E. Blair36658cf2013-12-06 17:53:48 -08003280 client = zuul.rpcclient.RPCClient('127.0.0.1',
3281 self.gearman_server.port)
3282 r = client.promote(pipeline='gate',
3283 change_ids=['2,1', '3,1'])
3284
Sean Daguef39b9ca2014-01-10 21:34:35 -05003285 # ensure that enqueue times are durable
3286 items = self.sched.layout.pipelines['gate'].getAllItems()
3287 for item in items:
3288 self.assertEqual(
3289 enqueue_times[str(item.change)], item.enqueue_time)
3290
James E. Blair78acec92014-02-06 07:11:32 -08003291 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003292 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003293 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003294 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003295 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003296 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003297 self.waitUntilSettled()
3298
3299 self.assertEqual(len(self.builds), 6)
3300 self.assertEqual(self.builds[0].name, 'project-test1')
3301 self.assertEqual(self.builds[1].name, 'project-test2')
3302 self.assertEqual(self.builds[2].name, 'project-test1')
3303 self.assertEqual(self.builds[3].name, 'project-test2')
3304 self.assertEqual(self.builds[4].name, 'project-test1')
3305 self.assertEqual(self.builds[5].name, 'project-test2')
3306
3307 self.assertTrue(self.job_has_changes(self.builds[0], B))
3308 self.assertFalse(self.job_has_changes(self.builds[0], A))
3309 self.assertFalse(self.job_has_changes(self.builds[0], C))
3310
3311 self.assertTrue(self.job_has_changes(self.builds[2], B))
3312 self.assertTrue(self.job_has_changes(self.builds[2], C))
3313 self.assertFalse(self.job_has_changes(self.builds[2], A))
3314
3315 self.assertTrue(self.job_has_changes(self.builds[4], B))
3316 self.assertTrue(self.job_has_changes(self.builds[4], C))
3317 self.assertTrue(self.job_has_changes(self.builds[4], A))
3318
James E. Blair08d19992016-08-10 15:25:31 -07003319 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003320 self.waitUntilSettled()
3321
3322 self.assertEqual(A.data['status'], 'MERGED')
3323 self.assertEqual(A.reported, 2)
3324 self.assertEqual(B.data['status'], 'MERGED')
3325 self.assertEqual(B.reported, 2)
3326 self.assertEqual(C.data['status'], 'MERGED')
3327 self.assertEqual(C.reported, 2)
3328
3329 client.shutdown()
3330 self.assertEqual(r, True)
3331
James E. Blairec056492016-07-22 09:45:56 -07003332 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003333 def test_client_promote_dependent(self):
3334 "Test that the RPC client can promote a dependent change"
3335 # C (depends on B) -> B -> A ; then promote C to get:
3336 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003337 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003338 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3339 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3340 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3341
3342 C.setDependsOn(B, 1)
3343
James E. Blair8b5408c2016-08-08 15:37:46 -07003344 A.addApproval('code-review', 2)
3345 B.addApproval('code-review', 2)
3346 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003347
James E. Blair8b5408c2016-08-08 15:37:46 -07003348 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3349 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3350 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003351
3352 self.waitUntilSettled()
3353
3354 client = zuul.rpcclient.RPCClient('127.0.0.1',
3355 self.gearman_server.port)
3356 r = client.promote(pipeline='gate',
3357 change_ids=['3,1'])
3358
James E. Blair78acec92014-02-06 07:11:32 -08003359 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003360 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003361 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003362 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003363 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003364 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003365 self.waitUntilSettled()
3366
3367 self.assertEqual(len(self.builds), 6)
3368 self.assertEqual(self.builds[0].name, 'project-test1')
3369 self.assertEqual(self.builds[1].name, 'project-test2')
3370 self.assertEqual(self.builds[2].name, 'project-test1')
3371 self.assertEqual(self.builds[3].name, 'project-test2')
3372 self.assertEqual(self.builds[4].name, 'project-test1')
3373 self.assertEqual(self.builds[5].name, 'project-test2')
3374
3375 self.assertTrue(self.job_has_changes(self.builds[0], B))
3376 self.assertFalse(self.job_has_changes(self.builds[0], A))
3377 self.assertFalse(self.job_has_changes(self.builds[0], C))
3378
3379 self.assertTrue(self.job_has_changes(self.builds[2], B))
3380 self.assertTrue(self.job_has_changes(self.builds[2], C))
3381 self.assertFalse(self.job_has_changes(self.builds[2], A))
3382
3383 self.assertTrue(self.job_has_changes(self.builds[4], B))
3384 self.assertTrue(self.job_has_changes(self.builds[4], C))
3385 self.assertTrue(self.job_has_changes(self.builds[4], A))
3386
James E. Blair08d19992016-08-10 15:25:31 -07003387 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003388 self.waitUntilSettled()
3389
3390 self.assertEqual(A.data['status'], 'MERGED')
3391 self.assertEqual(A.reported, 2)
3392 self.assertEqual(B.data['status'], 'MERGED')
3393 self.assertEqual(B.reported, 2)
3394 self.assertEqual(C.data['status'], 'MERGED')
3395 self.assertEqual(C.reported, 2)
3396
3397 client.shutdown()
3398 self.assertEqual(r, True)
3399
James E. Blairec056492016-07-22 09:45:56 -07003400 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003401 def test_client_promote_negative(self):
3402 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003403 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003404 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003405 A.addApproval('code-review', 2)
3406 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003407 self.waitUntilSettled()
3408
3409 client = zuul.rpcclient.RPCClient('127.0.0.1',
3410 self.gearman_server.port)
3411
3412 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3413 r = client.promote(pipeline='nonexistent',
3414 change_ids=['2,1', '3,1'])
3415 client.shutdown()
3416 self.assertEqual(r, False)
3417
3418 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3419 r = client.promote(pipeline='gate',
3420 change_ids=['4,1'])
3421 client.shutdown()
3422 self.assertEqual(r, False)
3423
James E. Blair08d19992016-08-10 15:25:31 -07003424 self.launch_server.hold_jobs_in_build = False
3425 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003426 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003427
James E. Blairec056492016-07-22 09:45:56 -07003428 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003429 def test_queue_rate_limiting(self):
3430 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003431 self.updateConfigLayout(
3432 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003433 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003434 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003435 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3436 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3437 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3438
3439 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003440 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003441
James E. Blair8b5408c2016-08-08 15:37:46 -07003442 A.addApproval('code-review', 2)
3443 B.addApproval('code-review', 2)
3444 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003445
James E. Blair8b5408c2016-08-08 15:37:46 -07003446 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3447 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3448 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003449 self.waitUntilSettled()
3450
3451 # Only A and B will have their merge jobs queued because
3452 # window is 2.
3453 self.assertEqual(len(self.builds), 2)
3454 self.assertEqual(self.builds[0].name, 'project-merge')
3455 self.assertEqual(self.builds[1].name, 'project-merge')
3456
James E. Blair08d19992016-08-10 15:25:31 -07003457 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003458 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003459 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003460 self.waitUntilSettled()
3461
3462 # Only A and B will have their test jobs queued because
3463 # window is 2.
3464 self.assertEqual(len(self.builds), 4)
3465 self.assertEqual(self.builds[0].name, 'project-test1')
3466 self.assertEqual(self.builds[1].name, 'project-test2')
3467 self.assertEqual(self.builds[2].name, 'project-test1')
3468 self.assertEqual(self.builds[3].name, 'project-test2')
3469
James E. Blair08d19992016-08-10 15:25:31 -07003470 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003471 self.waitUntilSettled()
3472
3473 queue = self.sched.layout.pipelines['gate'].queues[0]
3474 # A failed so window is reduced by 1 to 1.
3475 self.assertEqual(queue.window, 1)
3476 self.assertEqual(queue.window_floor, 1)
3477 self.assertEqual(A.data['status'], 'NEW')
3478
3479 # Gate is reset and only B's merge job is queued because
3480 # window shrunk to 1.
3481 self.assertEqual(len(self.builds), 1)
3482 self.assertEqual(self.builds[0].name, 'project-merge')
3483
James E. Blair08d19992016-08-10 15:25:31 -07003484 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003485 self.waitUntilSettled()
3486
3487 # Only B's test jobs are queued because window is still 1.
3488 self.assertEqual(len(self.builds), 2)
3489 self.assertEqual(self.builds[0].name, 'project-test1')
3490 self.assertEqual(self.builds[1].name, 'project-test2')
3491
James E. Blair08d19992016-08-10 15:25:31 -07003492 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003493 self.waitUntilSettled()
3494
3495 # B was successfully merged so window is increased to 2.
3496 self.assertEqual(queue.window, 2)
3497 self.assertEqual(queue.window_floor, 1)
3498 self.assertEqual(B.data['status'], 'MERGED')
3499
3500 # Only C is left and its merge job is queued.
3501 self.assertEqual(len(self.builds), 1)
3502 self.assertEqual(self.builds[0].name, 'project-merge')
3503
James E. Blair08d19992016-08-10 15:25:31 -07003504 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003505 self.waitUntilSettled()
3506
3507 # After successful merge job the test jobs for C are queued.
3508 self.assertEqual(len(self.builds), 2)
3509 self.assertEqual(self.builds[0].name, 'project-test1')
3510 self.assertEqual(self.builds[1].name, 'project-test2')
3511
James E. Blair08d19992016-08-10 15:25:31 -07003512 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003513 self.waitUntilSettled()
3514
3515 # C successfully merged so window is bumped to 3.
3516 self.assertEqual(queue.window, 3)
3517 self.assertEqual(queue.window_floor, 1)
3518 self.assertEqual(C.data['status'], 'MERGED')
3519
James E. Blairec056492016-07-22 09:45:56 -07003520 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003521 def test_queue_rate_limiting_dependent(self):
3522 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003523 self.updateConfigLayout(
3524 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003525 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003526 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003527 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3528 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3529 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3530
3531 B.setDependsOn(A, 1)
3532
James E. Blair08d19992016-08-10 15:25:31 -07003533 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003534
James E. Blair8b5408c2016-08-08 15:37:46 -07003535 A.addApproval('code-review', 2)
3536 B.addApproval('code-review', 2)
3537 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003538
James E. Blair8b5408c2016-08-08 15:37:46 -07003539 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3540 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3541 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003542 self.waitUntilSettled()
3543
3544 # Only A and B will have their merge jobs queued because
3545 # window is 2.
3546 self.assertEqual(len(self.builds), 2)
3547 self.assertEqual(self.builds[0].name, 'project-merge')
3548 self.assertEqual(self.builds[1].name, 'project-merge')
3549
James E. Blair08d19992016-08-10 15:25:31 -07003550 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003551 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003552 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003553 self.waitUntilSettled()
3554
3555 # Only A and B will have their test jobs queued because
3556 # window is 2.
3557 self.assertEqual(len(self.builds), 4)
3558 self.assertEqual(self.builds[0].name, 'project-test1')
3559 self.assertEqual(self.builds[1].name, 'project-test2')
3560 self.assertEqual(self.builds[2].name, 'project-test1')
3561 self.assertEqual(self.builds[3].name, 'project-test2')
3562
James E. Blair08d19992016-08-10 15:25:31 -07003563 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003564 self.waitUntilSettled()
3565
3566 queue = self.sched.layout.pipelines['gate'].queues[0]
3567 # A failed so window is reduced by 1 to 1.
3568 self.assertEqual(queue.window, 1)
3569 self.assertEqual(queue.window_floor, 1)
3570 self.assertEqual(A.data['status'], 'NEW')
3571 self.assertEqual(B.data['status'], 'NEW')
3572
3573 # Gate is reset and only C's merge job is queued because
3574 # window shrunk to 1 and A and B were dequeued.
3575 self.assertEqual(len(self.builds), 1)
3576 self.assertEqual(self.builds[0].name, 'project-merge')
3577
James E. Blair08d19992016-08-10 15:25:31 -07003578 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003579 self.waitUntilSettled()
3580
3581 # Only C's test jobs are queued because window is still 1.
3582 self.assertEqual(len(self.builds), 2)
3583 self.assertEqual(self.builds[0].name, 'project-test1')
3584 self.assertEqual(self.builds[1].name, 'project-test2')
3585
James E. Blair08d19992016-08-10 15:25:31 -07003586 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003587 self.waitUntilSettled()
3588
3589 # C was successfully merged so window is increased to 2.
3590 self.assertEqual(queue.window, 2)
3591 self.assertEqual(queue.window_floor, 1)
3592 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003593
James E. Blairec056492016-07-22 09:45:56 -07003594 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003595 def test_worker_update_metadata(self):
3596 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003597 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003598
3599 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003600 A.addApproval('code-review', 2)
3601 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003602 self.waitUntilSettled()
3603
3604 self.assertEqual(len(self.launcher.builds), 1)
3605
3606 self.log.debug('Current builds:')
3607 self.log.debug(self.launcher.builds)
3608
3609 start = time.time()
3610 while True:
3611 if time.time() - start > 10:
3612 raise Exception("Timeout waiting for gearman server to report "
3613 + "back to the client")
3614 build = self.launcher.builds.values()[0]
3615 if build.worker.name == "My Worker":
3616 break
3617 else:
3618 time.sleep(0)
3619
3620 self.log.debug(build)
3621 self.assertEqual("My Worker", build.worker.name)
3622 self.assertEqual("localhost", build.worker.hostname)
3623 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3624 self.assertEqual("zuul.example.org", build.worker.fqdn)
3625 self.assertEqual("FakeBuilder", build.worker.program)
3626 self.assertEqual("v1.1", build.worker.version)
3627 self.assertEqual({'something': 'else'}, build.worker.extra)
3628
James E. Blair08d19992016-08-10 15:25:31 -07003629 self.launch_server.hold_jobs_in_build = False
3630 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003631 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003632
James E. Blairec056492016-07-22 09:45:56 -07003633 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003634 def test_footer_message(self):
3635 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003636 self.updateConfigLayout(
3637 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003638 self.sched.reconfigure(self.config)
3639 self.registerJobs()
3640
3641 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003642 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003643 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003644 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003645 self.waitUntilSettled()
3646
3647 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003648 B.addApproval('code-review', 2)
3649 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003650 self.waitUntilSettled()
3651
3652 self.assertEqual(2, len(self.smtp_messages))
3653
3654 failure_body = """\
3655Build failed. For information on how to proceed, see \
3656http://wiki.example.org/Test_Failures
3657
3658- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3659- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3660
3661For CI problems and help debugging, contact ci@example.org"""
3662
3663 success_body = """\
3664Build succeeded.
3665
3666- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3667- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3668
3669For CI problems and help debugging, contact ci@example.org"""
3670
3671 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3672 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003673
James E. Blairec056492016-07-22 09:45:56 -07003674 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003675 def test_merge_failure_reporters(self):
3676 """Check that the config is set up correctly"""
3677
James E. Blairf84026c2015-12-08 16:11:46 -08003678 self.updateConfigLayout(
3679 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003680 self.sched.reconfigure(self.config)
3681 self.registerJobs()
3682
3683 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003684 "Merge Failed.\n\nThis change or one of its cross-repo "
3685 "dependencies was unable to be automatically merged with the "
3686 "current state of its repository. Please rebase the change and "
3687 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003688 self.sched.layout.pipelines['check'].merge_failure_message)
3689 self.assertEqual(
3690 "The merge failed! For more information...",
3691 self.sched.layout.pipelines['gate'].merge_failure_message)
3692
3693 self.assertEqual(
3694 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3695 self.assertEqual(
3696 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3697
3698 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003699 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3700 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003701
3702 self.assertTrue(
3703 (
3704 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003705 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003706 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003707 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003708 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003709 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003710 ) or (
3711 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003712 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003713 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003714 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003715 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003716 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003717 )
3718 )
3719
James E. Blairec056492016-07-22 09:45:56 -07003720 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003721 def test_merge_failure_reports(self):
3722 """Check that when a change fails to merge the correct message is sent
3723 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003724 self.updateConfigLayout(
3725 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003726 self.sched.reconfigure(self.config)
3727 self.registerJobs()
3728
3729 # Check a test failure isn't reported to SMTP
3730 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003731 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003732 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003733 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003734 self.waitUntilSettled()
3735
3736 self.assertEqual(3, len(self.history)) # 3 jobs
3737 self.assertEqual(0, len(self.smtp_messages))
3738
3739 # Check a merge failure is reported to SMTP
3740 # B should be merged, but C will conflict with B
3741 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3742 B.addPatchset(['conflict'])
3743 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3744 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003745 B.addApproval('code-review', 2)
3746 C.addApproval('code-review', 2)
3747 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3748 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003749 self.waitUntilSettled()
3750
3751 self.assertEqual(6, len(self.history)) # A and B jobs
3752 self.assertEqual(1, len(self.smtp_messages))
3753 self.assertEqual('The merge failed! For more information...',
3754 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003755
James E. Blairec056492016-07-22 09:45:56 -07003756 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003757 def test_default_merge_failure_reports(self):
3758 """Check that the default merge failure reports are correct."""
3759
3760 # A should report success, B should report merge failure.
3761 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3762 A.addPatchset(['conflict'])
3763 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3764 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003765 A.addApproval('code-review', 2)
3766 B.addApproval('code-review', 2)
3767 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3768 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003769 self.waitUntilSettled()
3770
3771 self.assertEqual(3, len(self.history)) # A jobs
3772 self.assertEqual(A.reported, 2)
3773 self.assertEqual(B.reported, 2)
3774 self.assertEqual(A.data['status'], 'MERGED')
3775 self.assertEqual(B.data['status'], 'NEW')
3776 self.assertIn('Build succeeded', A.messages[1])
3777 self.assertIn('Merge Failed', B.messages[1])
3778 self.assertIn('automatically merged', B.messages[1])
3779 self.assertNotIn('logs.example.com', B.messages[1])
3780 self.assertNotIn('SKIPPED', B.messages[1])
3781
James E. Blairec056492016-07-22 09:45:56 -07003782 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003783 def test_swift_instructions(self):
3784 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003785 self.updateConfigLayout(
3786 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003787 self.sched.reconfigure(self.config)
3788 self.registerJobs()
3789
James E. Blair08d19992016-08-10 15:25:31 -07003790 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003791 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3792
James E. Blair8b5408c2016-08-08 15:37:46 -07003793 A.addApproval('code-review', 2)
3794 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003795 self.waitUntilSettled()
3796
3797 self.assertEqual(
3798 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3799 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003800 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003801 self.assertEqual(5,
3802 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3803 split('\n')))
3804 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3805
3806 self.assertEqual(
3807 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3808 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003809 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003810 self.assertEqual(5,
3811 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3812 split('\n')))
3813 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3814
3815 self.assertEqual(
3816 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3817 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003818 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003819 self.assertEqual(5,
3820 len(self.builds[1].
3821 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3822 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3823
James E. Blair08d19992016-08-10 15:25:31 -07003824 self.launch_server.hold_jobs_in_build = False
3825 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003826 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003827
James E. Blairec056492016-07-22 09:45:56 -07003828 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003829 def test_client_get_running_jobs(self):
3830 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003831 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003832 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003833 A.addApproval('code-review', 2)
3834 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003835 self.waitUntilSettled()
3836
3837 client = zuul.rpcclient.RPCClient('127.0.0.1',
3838 self.gearman_server.port)
3839
3840 # Wait for gearman server to send the initial workData back to zuul
3841 start = time.time()
3842 while True:
3843 if time.time() - start > 10:
3844 raise Exception("Timeout waiting for gearman server to report "
3845 + "back to the client")
3846 build = self.launcher.builds.values()[0]
3847 if build.worker.name == "My Worker":
3848 break
3849 else:
3850 time.sleep(0)
3851
3852 running_items = client.get_running_jobs()
3853
3854 self.assertEqual(1, len(running_items))
3855 running_item = running_items[0]
3856 self.assertEqual([], running_item['failing_reasons'])
3857 self.assertEqual([], running_item['items_behind'])
3858 self.assertEqual('https://hostname/1', running_item['url'])
3859 self.assertEqual(None, running_item['item_ahead'])
3860 self.assertEqual('org/project', running_item['project'])
3861 self.assertEqual(None, running_item['remaining_time'])
3862 self.assertEqual(True, running_item['active'])
3863 self.assertEqual('1,1', running_item['id'])
3864
3865 self.assertEqual(3, len(running_item['jobs']))
3866 for job in running_item['jobs']:
3867 if job['name'] == 'project-merge':
3868 self.assertEqual('project-merge', job['name'])
3869 self.assertEqual('gate', job['pipeline'])
3870 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003871 self.assertEqual('https://server/job/project-merge/0/',
3872 job['url'])
3873 self.assertEqual(7, len(job['worker']))
3874 self.assertEqual(False, job['canceled'])
3875 self.assertEqual(True, job['voting'])
3876 self.assertEqual(None, job['result'])
3877 self.assertEqual('gate', job['pipeline'])
3878 break
3879
James E. Blair08d19992016-08-10 15:25:31 -07003880 self.launch_server.hold_jobs_in_build = False
3881 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003882 self.waitUntilSettled()
3883
3884 running_items = client.get_running_jobs()
3885 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003886
3887 def test_nonvoting_pipeline(self):
3888 "Test that a nonvoting pipeline (experimental) can still report"
3889
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003890 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3891 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003892 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3893 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003894
3895 self.assertEqual(self.getJobFromHistory('project-merge').result,
3896 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003897 self.assertEqual(
3898 self.getJobFromHistory('experimental-project-test').result,
3899 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003900 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003901
James E. Blairec056492016-07-22 09:45:56 -07003902 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003903 def test_crd_gate(self):
3904 "Test cross-repo dependencies"
3905 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3906 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003907 A.addApproval('code-review', 2)
3908 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003909
3910 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3911 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3912 AM2.setMerged()
3913 AM1.setMerged()
3914
3915 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3916 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3917 BM2.setMerged()
3918 BM1.setMerged()
3919
3920 # A -> AM1 -> AM2
3921 # B -> BM1 -> BM2
3922 # A Depends-On: B
3923 # M2 is here to make sure it is never queried. If it is, it
3924 # means zuul is walking down the entire history of merged
3925 # changes.
3926
3927 B.setDependsOn(BM1, 1)
3928 BM1.setDependsOn(BM2, 1)
3929
3930 A.setDependsOn(AM1, 1)
3931 AM1.setDependsOn(AM2, 1)
3932
3933 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3934 A.subject, B.data['id'])
3935
James E. Blair8b5408c2016-08-08 15:37:46 -07003936 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003937 self.waitUntilSettled()
3938
3939 self.assertEqual(A.data['status'], 'NEW')
3940 self.assertEqual(B.data['status'], 'NEW')
3941
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003942 for connection in self.connections.values():
3943 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003944
James E. Blair08d19992016-08-10 15:25:31 -07003945 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003946 B.addApproval('approved', 1)
3947 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003948 self.waitUntilSettled()
3949
James E. Blair08d19992016-08-10 15:25:31 -07003950 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003951 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003952 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003953 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003954 self.launch_server.hold_jobs_in_build = False
3955 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003956 self.waitUntilSettled()
3957
3958 self.assertEqual(AM2.queried, 0)
3959 self.assertEqual(BM2.queried, 0)
3960 self.assertEqual(A.data['status'], 'MERGED')
3961 self.assertEqual(B.data['status'], 'MERGED')
3962 self.assertEqual(A.reported, 2)
3963 self.assertEqual(B.reported, 2)
3964
James E. Blair8f78d882015-02-05 08:51:37 -08003965 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3966 '2,1 1,1')
3967
James E. Blairec056492016-07-22 09:45:56 -07003968 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003969 def test_crd_branch(self):
3970 "Test cross-repo dependencies in multiple branches"
3971 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3972 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3973 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3974 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003975 A.addApproval('code-review', 2)
3976 B.addApproval('code-review', 2)
3977 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003978
3979 # A Depends-On: B+C
3980 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3981 A.subject, B.data['id'])
3982
James E. Blair08d19992016-08-10 15:25:31 -07003983 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003984 B.addApproval('approved', 1)
3985 C.addApproval('approved', 1)
3986 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003987 self.waitUntilSettled()
3988
James E. Blair08d19992016-08-10 15:25:31 -07003989 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003990 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003991 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003992 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003993 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003994 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003995 self.launch_server.hold_jobs_in_build = False
3996 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003997 self.waitUntilSettled()
3998
3999 self.assertEqual(A.data['status'], 'MERGED')
4000 self.assertEqual(B.data['status'], 'MERGED')
4001 self.assertEqual(C.data['status'], 'MERGED')
4002 self.assertEqual(A.reported, 2)
4003 self.assertEqual(B.reported, 2)
4004 self.assertEqual(C.reported, 2)
4005
4006 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4007 '2,1 3,1 1,1')
4008
James E. Blairec056492016-07-22 09:45:56 -07004009 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08004010 def test_crd_multiline(self):
4011 "Test multiple depends-on lines in commit"
4012 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4013 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4014 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07004015 A.addApproval('code-review', 2)
4016 B.addApproval('code-review', 2)
4017 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004018
4019 # A Depends-On: B+C
4020 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
4021 A.subject, B.data['id'], C.data['id'])
4022
James E. Blair08d19992016-08-10 15:25:31 -07004023 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004024 B.addApproval('approved', 1)
4025 C.addApproval('approved', 1)
4026 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004027 self.waitUntilSettled()
4028
James E. Blair08d19992016-08-10 15:25:31 -07004029 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004030 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004031 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004032 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004033 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004034 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004035 self.launch_server.hold_jobs_in_build = False
4036 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004037 self.waitUntilSettled()
4038
4039 self.assertEqual(A.data['status'], 'MERGED')
4040 self.assertEqual(B.data['status'], 'MERGED')
4041 self.assertEqual(C.data['status'], 'MERGED')
4042 self.assertEqual(A.reported, 2)
4043 self.assertEqual(B.reported, 2)
4044 self.assertEqual(C.reported, 2)
4045
4046 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4047 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004048
James E. Blairec056492016-07-22 09:45:56 -07004049 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004050 def test_crd_unshared_gate(self):
4051 "Test cross-repo dependencies in unshared gate queues"
4052 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4053 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004054 A.addApproval('code-review', 2)
4055 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004056
4057 # A Depends-On: B
4058 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4059 A.subject, B.data['id'])
4060
4061 # A and B do not share a queue, make sure that A is unable to
4062 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004063 B.addApproval('approved', 1)
4064 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004065 self.waitUntilSettled()
4066
4067 self.assertEqual(A.data['status'], 'NEW')
4068 self.assertEqual(B.data['status'], 'NEW')
4069 self.assertEqual(A.reported, 0)
4070 self.assertEqual(B.reported, 0)
4071 self.assertEqual(len(self.history), 0)
4072
4073 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004074 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004075 self.waitUntilSettled()
4076
4077 self.assertEqual(B.data['status'], 'MERGED')
4078 self.assertEqual(B.reported, 2)
4079
4080 # Now that B is merged, A should be able to be enqueued and
4081 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004082 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004083 self.waitUntilSettled()
4084
4085 self.assertEqual(A.data['status'], 'MERGED')
4086 self.assertEqual(A.reported, 2)
4087
James E. Blairec056492016-07-22 09:45:56 -07004088 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004089 def test_crd_gate_reverse(self):
4090 "Test reverse cross-repo dependencies"
4091 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4092 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004093 A.addApproval('code-review', 2)
4094 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004095
4096 # A Depends-On: B
4097
4098 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4099 A.subject, B.data['id'])
4100
James E. Blair8b5408c2016-08-08 15:37:46 -07004101 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004102 self.waitUntilSettled()
4103
4104 self.assertEqual(A.data['status'], 'NEW')
4105 self.assertEqual(B.data['status'], 'NEW')
4106
James E. Blair08d19992016-08-10 15:25:31 -07004107 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004108 A.addApproval('approved', 1)
4109 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004110 self.waitUntilSettled()
4111
James E. Blair08d19992016-08-10 15:25:31 -07004112 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004113 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004114 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004115 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004116 self.launch_server.hold_jobs_in_build = False
4117 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004118 self.waitUntilSettled()
4119
4120 self.assertEqual(A.data['status'], 'MERGED')
4121 self.assertEqual(B.data['status'], 'MERGED')
4122 self.assertEqual(A.reported, 2)
4123 self.assertEqual(B.reported, 2)
4124
4125 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4126 '2,1 1,1')
4127
James E. Blairec056492016-07-22 09:45:56 -07004128 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004129 def test_crd_cycle(self):
4130 "Test cross-repo dependency cycles"
4131 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4132 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004133 A.addApproval('code-review', 2)
4134 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004135
4136 # A -> B -> A (via commit-depends)
4137
4138 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4139 A.subject, B.data['id'])
4140 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4141 B.subject, A.data['id'])
4142
James E. Blair8b5408c2016-08-08 15:37:46 -07004143 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004144 self.waitUntilSettled()
4145
4146 self.assertEqual(A.reported, 0)
4147 self.assertEqual(B.reported, 0)
4148 self.assertEqual(A.data['status'], 'NEW')
4149 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004150
James E. Blairec056492016-07-22 09:45:56 -07004151 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004152 def test_crd_gate_unknown(self):
4153 "Test unknown projects in dependent pipeline"
4154 self.init_repo("org/unknown")
4155 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4156 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004157 A.addApproval('code-review', 2)
4158 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004159
4160 # A Depends-On: B
4161 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4162 A.subject, B.data['id'])
4163
James E. Blair8b5408c2016-08-08 15:37:46 -07004164 B.addApproval('approved', 1)
4165 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004166 self.waitUntilSettled()
4167
4168 # Unknown projects cannot share a queue with any other
4169 # since they don't have common jobs with any other (they have no jobs).
4170 # Changes which depend on unknown project changes
4171 # should not be processed in dependent pipeline
4172 self.assertEqual(A.data['status'], 'NEW')
4173 self.assertEqual(B.data['status'], 'NEW')
4174 self.assertEqual(A.reported, 0)
4175 self.assertEqual(B.reported, 0)
4176 self.assertEqual(len(self.history), 0)
4177
4178 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004179 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004180 B.setMerged()
4181 self.waitUntilSettled()
4182 self.assertEqual(len(self.history), 0)
4183
4184 # Now that B is merged, A should be able to be enqueued and
4185 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004186 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004187 self.waitUntilSettled()
4188
4189 self.assertEqual(A.data['status'], 'MERGED')
4190 self.assertEqual(A.reported, 2)
4191 self.assertEqual(B.data['status'], 'MERGED')
4192 self.assertEqual(B.reported, 0)
4193
James E. Blairec056492016-07-22 09:45:56 -07004194 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004195 def test_crd_check(self):
4196 "Test cross-repo dependencies in independent pipelines"
4197
4198 self.gearman_server.hold_jobs_in_queue = True
4199 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4200 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4201
4202 # A Depends-On: B
4203 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4204 A.subject, B.data['id'])
4205
4206 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4207 self.waitUntilSettled()
4208
4209 queue = self.gearman_server.getQueue()
4210 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4211 self.gearman_server.hold_jobs_in_queue = False
4212 self.gearman_server.release()
4213 self.waitUntilSettled()
4214
4215 path = os.path.join(self.git_root, "org/project1")
4216 repo = git.Repo(path)
4217 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4218 repo_messages.reverse()
4219 correct_messages = ['initial commit', 'A-1']
4220 self.assertEqual(repo_messages, correct_messages)
4221
4222 path = os.path.join(self.git_root, "org/project2")
4223 repo = git.Repo(path)
4224 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4225 repo_messages.reverse()
4226 correct_messages = ['initial commit', 'B-1']
4227 self.assertEqual(repo_messages, correct_messages)
4228
4229 self.assertEqual(A.data['status'], 'NEW')
4230 self.assertEqual(B.data['status'], 'NEW')
4231 self.assertEqual(A.reported, 1)
4232 self.assertEqual(B.reported, 0)
4233
4234 self.assertEqual(self.history[0].changes, '2,1 1,1')
4235 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004236
James E. Blairec056492016-07-22 09:45:56 -07004237 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004238 def test_crd_check_git_depends(self):
4239 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004240 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004241 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4242 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4243
4244 # Add two git-dependent changes and make sure they both report
4245 # success.
4246 B.setDependsOn(A, 1)
4247 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4248 self.waitUntilSettled()
4249 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4250 self.waitUntilSettled()
4251
James E. Blairb8c16472015-05-05 14:55:26 -07004252 self.orderedRelease()
4253 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004254 self.waitUntilSettled()
4255
4256 self.assertEqual(A.data['status'], 'NEW')
4257 self.assertEqual(B.data['status'], 'NEW')
4258 self.assertEqual(A.reported, 1)
4259 self.assertEqual(B.reported, 1)
4260
4261 self.assertEqual(self.history[0].changes, '1,1')
4262 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4263 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4264
4265 self.assertIn('Build succeeded', A.messages[0])
4266 self.assertIn('Build succeeded', B.messages[0])
4267
James E. Blairec056492016-07-22 09:45:56 -07004268 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004269 def test_crd_check_duplicate(self):
4270 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004271 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004272 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4273 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4274 check_pipeline = self.sched.layout.pipelines['check']
4275
4276 # Add two git-dependent changes...
4277 B.setDependsOn(A, 1)
4278 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4279 self.waitUntilSettled()
4280 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4281
4282 # ...make sure the live one is not duplicated...
4283 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4284 self.waitUntilSettled()
4285 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4286
4287 # ...but the non-live one is able to be.
4288 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4289 self.waitUntilSettled()
4290 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4291
Clark Boylandd849822015-03-02 12:38:14 -08004292 # Release jobs in order to avoid races with change A jobs
4293 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004294 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004295 self.launch_server.hold_jobs_in_build = False
4296 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004297 self.waitUntilSettled()
4298
4299 self.assertEqual(A.data['status'], 'NEW')
4300 self.assertEqual(B.data['status'], 'NEW')
4301 self.assertEqual(A.reported, 1)
4302 self.assertEqual(B.reported, 1)
4303
4304 self.assertEqual(self.history[0].changes, '1,1 2,1')
4305 self.assertEqual(self.history[1].changes, '1,1')
4306 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4307
4308 self.assertIn('Build succeeded', A.messages[0])
4309 self.assertIn('Build succeeded', B.messages[0])
4310
James E. Blairec056492016-07-22 09:45:56 -07004311 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004312 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004313 "Test cross-repo dependencies re-enqueued in independent pipelines"
4314
4315 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004316 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4317 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004318
4319 # A Depends-On: B
4320 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4321 A.subject, B.data['id'])
4322
4323 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4324 self.waitUntilSettled()
4325
4326 self.sched.reconfigure(self.config)
4327
4328 # Make sure the items still share a change queue, and the
4329 # first one is not live.
4330 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4331 queue = self.sched.layout.pipelines['check'].queues[0]
4332 first_item = queue.queue[0]
4333 for item in queue.queue:
4334 self.assertEqual(item.queue, first_item.queue)
4335 self.assertFalse(first_item.live)
4336 self.assertTrue(queue.queue[1].live)
4337
4338 self.gearman_server.hold_jobs_in_queue = False
4339 self.gearman_server.release()
4340 self.waitUntilSettled()
4341
4342 self.assertEqual(A.data['status'], 'NEW')
4343 self.assertEqual(B.data['status'], 'NEW')
4344 self.assertEqual(A.reported, 1)
4345 self.assertEqual(B.reported, 0)
4346
4347 self.assertEqual(self.history[0].changes, '2,1 1,1')
4348 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004349
James E. Blairec056492016-07-22 09:45:56 -07004350 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004351 def test_crd_check_reconfiguration(self):
4352 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4353
James E. Blairec056492016-07-22 09:45:56 -07004354 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004355 def test_crd_undefined_project(self):
4356 """Test that undefined projects in dependencies are handled for
4357 independent pipelines"""
4358 # It's a hack for fake gerrit,
4359 # as it implies repo creation upon the creation of any change
4360 self.init_repo("org/unknown")
4361 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4362
James E. Blairec056492016-07-22 09:45:56 -07004363 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004364 def test_crd_check_ignore_dependencies(self):
4365 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004366 self.updateConfigLayout(
4367 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004368 self.sched.reconfigure(self.config)
4369 self.registerJobs()
4370
4371 self.gearman_server.hold_jobs_in_queue = True
4372 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4373 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4374 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4375
4376 # A Depends-On: B
4377 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4378 A.subject, B.data['id'])
4379 # C git-depends on B
4380 C.setDependsOn(B, 1)
4381 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4382 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4383 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4384 self.waitUntilSettled()
4385
4386 # Make sure none of the items share a change queue, and all
4387 # are live.
4388 check_pipeline = self.sched.layout.pipelines['check']
4389 self.assertEqual(len(check_pipeline.queues), 3)
4390 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4391 for item in check_pipeline.getAllItems():
4392 self.assertTrue(item.live)
4393
4394 self.gearman_server.hold_jobs_in_queue = False
4395 self.gearman_server.release()
4396 self.waitUntilSettled()
4397
4398 self.assertEqual(A.data['status'], 'NEW')
4399 self.assertEqual(B.data['status'], 'NEW')
4400 self.assertEqual(C.data['status'], 'NEW')
4401 self.assertEqual(A.reported, 1)
4402 self.assertEqual(B.reported, 1)
4403 self.assertEqual(C.reported, 1)
4404
4405 # Each job should have tested exactly one change
4406 for job in self.history:
4407 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004408
James E. Blairec056492016-07-22 09:45:56 -07004409 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004410 def test_crd_check_transitive(self):
4411 "Test transitive cross-repo dependencies"
4412 # Specifically, if A -> B -> C, and C gets a new patchset and
4413 # A gets a new patchset, ensure the test of A,2 includes B,1
4414 # and C,2 (not C,1 which would indicate stale data in the
4415 # cache for B).
4416 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4417 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4418 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4419
4420 # A Depends-On: B
4421 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4422 A.subject, B.data['id'])
4423
4424 # B Depends-On: C
4425 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4426 B.subject, C.data['id'])
4427
4428 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4429 self.waitUntilSettled()
4430 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4431
4432 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4433 self.waitUntilSettled()
4434 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4435
4436 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4437 self.waitUntilSettled()
4438 self.assertEqual(self.history[-1].changes, '3,1')
4439
4440 C.addPatchset()
4441 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4442 self.waitUntilSettled()
4443 self.assertEqual(self.history[-1].changes, '3,2')
4444
4445 A.addPatchset()
4446 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4447 self.waitUntilSettled()
4448 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004449
James E. Blairec056492016-07-22 09:45:56 -07004450 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004451 def test_crd_check_unknown(self):
4452 "Test unknown projects in independent pipeline"
4453 self.init_repo("org/unknown")
4454 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4455 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4456 # A Depends-On: B
4457 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4458 A.subject, B.data['id'])
4459
4460 # Make sure zuul has seen an event on B.
4461 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4462 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4463 self.waitUntilSettled()
4464
4465 self.assertEqual(A.data['status'], 'NEW')
4466 self.assertEqual(A.reported, 1)
4467 self.assertEqual(B.data['status'], 'NEW')
4468 self.assertEqual(B.reported, 0)
4469
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004470 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004471 def test_crd_cycle_join(self):
4472 "Test an updated change creates a cycle"
4473 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4474
4475 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4476 self.waitUntilSettled()
4477
4478 # Create B->A
4479 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4480 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4481 B.subject, A.data['id'])
4482 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4483 self.waitUntilSettled()
4484
4485 # Update A to add A->B (a cycle).
4486 A.addPatchset()
4487 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4488 A.subject, B.data['id'])
4489 # Normally we would submit the patchset-created event for
4490 # processing here, however, we have no way of noting whether
4491 # the dependency cycle detection correctly raised an
4492 # exception, so instead, we reach into the source driver and
4493 # call the method that would ultimately be called by the event
4494 # processing.
4495
4496 source = self.sched.layout.pipelines['gate'].source
4497 with testtools.ExpectedException(
4498 Exception, "Dependency cycle detected"):
4499 source._getChange(u'1', u'2', True)
4500 self.log.debug("Got expected dependency cycle exception")
4501
4502 # Now if we update B to remove the depends-on, everything
4503 # should be okay. B; A->B
4504
4505 B.addPatchset()
4506 B.data['commitMessage'] = '%s\n' % (B.subject,)
4507 source._getChange(u'1', u'2', True)
4508 source._getChange(u'2', u'2', True)
4509
James E. Blairec056492016-07-22 09:45:56 -07004510 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004511 def test_disable_at(self):
4512 "Test a pipeline will only report to the disabled trigger when failing"
4513
James E. Blairf84026c2015-12-08 16:11:46 -08004514 self.updateConfigLayout(
4515 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004516 self.sched.reconfigure(self.config)
4517
4518 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4519 self.assertEqual(
4520 0, self.sched.layout.pipelines['check']._consecutive_failures)
4521 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4522
4523 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4524 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4525 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4526 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4527 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4528 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4529 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4530 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4531 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4532 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4533 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4534
James E. Blair08d19992016-08-10 15:25:31 -07004535 self.launch_server.failJob('project-test1', A)
4536 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004537 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004538 self.launch_server.failJob('project-test1', D)
4539 self.launch_server.failJob('project-test1', E)
4540 self.launch_server.failJob('project-test1', F)
4541 self.launch_server.failJob('project-test1', G)
4542 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004543 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004544 self.launch_server.failJob('project-test1', J)
4545 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004546
4547 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4548 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4549 self.waitUntilSettled()
4550
4551 self.assertEqual(
4552 2, self.sched.layout.pipelines['check']._consecutive_failures)
4553 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4554
4555 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4556 self.waitUntilSettled()
4557
4558 self.assertEqual(
4559 0, self.sched.layout.pipelines['check']._consecutive_failures)
4560 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4561
4562 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4563 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4564 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4565 self.waitUntilSettled()
4566
4567 # We should be disabled now
4568 self.assertEqual(
4569 3, self.sched.layout.pipelines['check']._consecutive_failures)
4570 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4571
4572 # We need to wait between each of these patches to make sure the
4573 # smtp messages come back in an expected order
4574 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4575 self.waitUntilSettled()
4576 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4577 self.waitUntilSettled()
4578 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4579 self.waitUntilSettled()
4580
4581 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4582 # leaving a message on each change
4583 self.assertEqual(1, len(A.messages))
4584 self.assertIn('Build failed.', A.messages[0])
4585 self.assertEqual(1, len(B.messages))
4586 self.assertIn('Build failed.', B.messages[0])
4587 self.assertEqual(1, len(C.messages))
4588 self.assertIn('Build succeeded.', C.messages[0])
4589 self.assertEqual(1, len(D.messages))
4590 self.assertIn('Build failed.', D.messages[0])
4591 self.assertEqual(1, len(E.messages))
4592 self.assertIn('Build failed.', E.messages[0])
4593 self.assertEqual(1, len(F.messages))
4594 self.assertIn('Build failed.', F.messages[0])
4595
4596 # The last 3 (GHI) would have only reported via smtp.
4597 self.assertEqual(3, len(self.smtp_messages))
4598 self.assertEqual(0, len(G.messages))
4599 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4600 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4601 self.assertEqual(0, len(H.messages))
4602 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4603 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4604 self.assertEqual(0, len(I.messages))
4605 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4606 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4607
4608 # Now reload the configuration (simulate a HUP) to check the pipeline
4609 # comes out of disabled
4610 self.sched.reconfigure(self.config)
4611
4612 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4613 self.assertEqual(
4614 0, self.sched.layout.pipelines['check']._consecutive_failures)
4615 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4616
4617 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4618 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4619 self.waitUntilSettled()
4620
4621 self.assertEqual(
4622 2, self.sched.layout.pipelines['check']._consecutive_failures)
4623 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4624
4625 # J and K went back to gerrit
4626 self.assertEqual(1, len(J.messages))
4627 self.assertIn('Build failed.', J.messages[0])
4628 self.assertEqual(1, len(K.messages))
4629 self.assertIn('Build failed.', K.messages[0])
4630 # No more messages reported via smtp
4631 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004632
James E. Blairec056492016-07-22 09:45:56 -07004633 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004634 def test_success_pattern(self):
4635 "Ensure bad build params are ignored"
4636
4637 # Use SMTP reporter to grab the result message easier
4638 self.init_repo("org/docs")
4639 self.config.set('zuul', 'layout_config',
4640 'tests/fixtures/layout-success-pattern.yaml')
4641 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004642 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004643 self.registerJobs()
4644
4645 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4646 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4647 self.waitUntilSettled()
4648
4649 # Grab build id
4650 self.assertEqual(len(self.builds), 1)
4651 uuid = self.builds[0].unique[:7]
4652
James E. Blair08d19992016-08-10 15:25:31 -07004653 self.launch_server.hold_jobs_in_build = False
4654 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004655 self.waitUntilSettled()
4656
4657 self.assertEqual(len(self.smtp_messages), 1)
4658 body = self.smtp_messages[0]['body'].splitlines()
4659 self.assertEqual('Build succeeded.', body[0])
4660
4661 self.assertIn(
4662 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4663 'docs-draft-test/%s/publish-docs/' % uuid,
4664 body[2])
4665 self.assertIn(
4666 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4667 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004668
4669
4670class TestDuplicatePipeline(ZuulTestCase):
4671 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4672
4673 def test_duplicate_pipelines(self):
4674 "Test that a change matching multiple pipelines works"
4675
4676 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4677 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4678 self.waitUntilSettled()
4679
4680 self.assertHistory([
4681 dict(name='project-test1', result='SUCCESS', changes='1,1',
4682 pipeline='dup1'),
4683 dict(name='project-test1', result='SUCCESS', changes='1,1',
4684 pipeline='dup2'),
4685 ])
4686
4687 self.assertEqual(len(A.messages), 2)
4688
4689 self.assertIn('dup1', A.messages[0])
4690 self.assertNotIn('dup2', A.messages[0])
4691 self.assertIn('project-test1', A.messages[0])
4692
4693 self.assertIn('dup2', A.messages[1])
4694 self.assertNotIn('dup1', A.messages[1])
4695 self.assertIn('project-test1', A.messages[1])