blob: ffc0da1a1c1caf9f336a8dd8364fc65ce7e36511 [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. Blair2fa50962013-01-30 21:50:41 -08001690 def test_new_patchset_dequeues_old(self):
1691 "Test that a new patchset causes the old to be dequeued"
1692 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001693 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001694 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1695 M.setMerged()
1696
1697 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1698 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1699 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1700 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001701 A.addApproval('code-review', 2)
1702 B.addApproval('code-review', 2)
1703 C.addApproval('code-review', 2)
1704 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001705
1706 C.setDependsOn(B, 1)
1707 B.setDependsOn(A, 1)
1708 A.setDependsOn(M, 1)
1709
James E. Blair8b5408c2016-08-08 15:37:46 -07001710 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1711 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1712 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1713 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001714 self.waitUntilSettled()
1715
1716 B.addPatchset()
1717 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1718 self.waitUntilSettled()
1719
James E. Blair08d19992016-08-10 15:25:31 -07001720 self.launch_server.hold_jobs_in_build = False
1721 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001722 self.waitUntilSettled()
1723
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001724 self.assertEqual(A.data['status'], 'MERGED')
1725 self.assertEqual(A.reported, 2)
1726 self.assertEqual(B.data['status'], 'NEW')
1727 self.assertEqual(B.reported, 2)
1728 self.assertEqual(C.data['status'], 'NEW')
1729 self.assertEqual(C.reported, 2)
1730 self.assertEqual(D.data['status'], 'MERGED')
1731 self.assertEqual(D.reported, 2)
1732 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001733
James E. Blairec056492016-07-22 09:45:56 -07001734 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001735 def test_new_patchset_check(self):
1736 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001737
James E. Blair08d19992016-08-10 15:25:31 -07001738 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001739
1740 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001741 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1742 check_pipeline = self.sched.layout.pipelines['check']
1743
1744 # Add two git-dependent changes
1745 B.setDependsOn(A, 1)
1746 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1747 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001748 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1749 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001750
1751 # A live item, and a non-live/live pair
1752 items = check_pipeline.getAllItems()
1753 self.assertEqual(len(items), 3)
1754
1755 self.assertEqual(items[0].change.number, '1')
1756 self.assertEqual(items[0].change.patchset, '1')
1757 self.assertFalse(items[0].live)
1758
1759 self.assertEqual(items[1].change.number, '2')
1760 self.assertEqual(items[1].change.patchset, '1')
1761 self.assertTrue(items[1].live)
1762
1763 self.assertEqual(items[2].change.number, '1')
1764 self.assertEqual(items[2].change.patchset, '1')
1765 self.assertTrue(items[2].live)
1766
1767 # Add a new patchset to A
1768 A.addPatchset()
1769 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1770 self.waitUntilSettled()
1771
1772 # The live copy of A,1 should be gone, but the non-live and B
1773 # should continue, and we should have a new A,2
1774 items = check_pipeline.getAllItems()
1775 self.assertEqual(len(items), 3)
1776
1777 self.assertEqual(items[0].change.number, '1')
1778 self.assertEqual(items[0].change.patchset, '1')
1779 self.assertFalse(items[0].live)
1780
1781 self.assertEqual(items[1].change.number, '2')
1782 self.assertEqual(items[1].change.patchset, '1')
1783 self.assertTrue(items[1].live)
1784
1785 self.assertEqual(items[2].change.number, '1')
1786 self.assertEqual(items[2].change.patchset, '2')
1787 self.assertTrue(items[2].live)
1788
1789 # Add a new patchset to B
1790 B.addPatchset()
1791 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1792 self.waitUntilSettled()
1793
1794 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1795 # but we should have a new B,2 (still based on A,1)
1796 items = check_pipeline.getAllItems()
1797 self.assertEqual(len(items), 3)
1798
1799 self.assertEqual(items[0].change.number, '1')
1800 self.assertEqual(items[0].change.patchset, '2')
1801 self.assertTrue(items[0].live)
1802
1803 self.assertEqual(items[1].change.number, '1')
1804 self.assertEqual(items[1].change.patchset, '1')
1805 self.assertFalse(items[1].live)
1806
1807 self.assertEqual(items[2].change.number, '2')
1808 self.assertEqual(items[2].change.patchset, '2')
1809 self.assertTrue(items[2].live)
1810
1811 self.builds[0].release()
1812 self.waitUntilSettled()
1813 self.builds[0].release()
1814 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001815 self.launch_server.hold_jobs_in_build = False
1816 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001817 self.waitUntilSettled()
1818
1819 self.assertEqual(A.reported, 1)
1820 self.assertEqual(B.reported, 1)
1821 self.assertEqual(self.history[0].result, 'ABORTED')
1822 self.assertEqual(self.history[0].changes, '1,1')
1823 self.assertEqual(self.history[1].result, 'ABORTED')
1824 self.assertEqual(self.history[1].changes, '1,1 2,1')
1825 self.assertEqual(self.history[2].result, 'SUCCESS')
1826 self.assertEqual(self.history[2].changes, '1,2')
1827 self.assertEqual(self.history[3].result, 'SUCCESS')
1828 self.assertEqual(self.history[3].changes, '1,1 2,2')
1829
1830 def test_abandoned_gate(self):
1831 "Test that an abandoned change is dequeued from gate"
1832
James E. Blair08d19992016-08-10 15:25:31 -07001833 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001834
1835 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001836 A.addApproval('code-review', 2)
1837 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001838 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001839 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1840 self.assertEqual(self.builds[0].name, 'project-merge')
1841
1842 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1843 self.waitUntilSettled()
1844
James E. Blair08d19992016-08-10 15:25:31 -07001845 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001846 self.waitUntilSettled()
1847
Arie5b4048c2016-10-05 16:12:06 +03001848 self.assertBuilds([])
1849 self.assertHistory([
1850 dict(name='project-merge', result='ABORTED', changes='1,1')],
1851 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001852 self.assertEqual(A.reported, 1,
1853 "Abandoned gate change should report only start")
1854
James E. Blairec056492016-07-22 09:45:56 -07001855 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001856 def test_abandoned_check(self):
1857 "Test that an abandoned change is dequeued from check"
1858
James E. Blair08d19992016-08-10 15:25:31 -07001859 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001860
1861 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1862 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1863 check_pipeline = self.sched.layout.pipelines['check']
1864
1865 # Add two git-dependent changes
1866 B.setDependsOn(A, 1)
1867 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1868 self.waitUntilSettled()
1869 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1870 self.waitUntilSettled()
1871 # A live item, and a non-live/live pair
1872 items = check_pipeline.getAllItems()
1873 self.assertEqual(len(items), 3)
1874
1875 self.assertEqual(items[0].change.number, '1')
1876 self.assertFalse(items[0].live)
1877
1878 self.assertEqual(items[1].change.number, '2')
1879 self.assertTrue(items[1].live)
1880
1881 self.assertEqual(items[2].change.number, '1')
1882 self.assertTrue(items[2].live)
1883
1884 # Abandon A
1885 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1886 self.waitUntilSettled()
1887
1888 # The live copy of A should be gone, but the non-live and B
1889 # should continue
1890 items = check_pipeline.getAllItems()
1891 self.assertEqual(len(items), 2)
1892
1893 self.assertEqual(items[0].change.number, '1')
1894 self.assertFalse(items[0].live)
1895
1896 self.assertEqual(items[1].change.number, '2')
1897 self.assertTrue(items[1].live)
1898
James E. Blair08d19992016-08-10 15:25:31 -07001899 self.launch_server.hold_jobs_in_build = False
1900 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001901 self.waitUntilSettled()
1902
1903 self.assertEqual(len(self.history), 4)
1904 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001905 'Build should have been aborted')
1906 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001907 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001908
James E. Blairec056492016-07-22 09:45:56 -07001909 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001910 def test_abandoned_not_timer(self):
1911 "Test that an abandoned change does not cancel timer jobs"
1912
James E. Blair08d19992016-08-10 15:25:31 -07001913 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001914
1915 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001916 self.updateConfigLayout(
1917 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001918 self.sched.reconfigure(self.config)
1919 self.registerJobs()
1920 # The pipeline triggers every second, so we should have seen
1921 # several by now.
1922 time.sleep(5)
1923 self.waitUntilSettled()
1924 # Stop queuing timer triggered jobs so that the assertions
1925 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001926 self.updateConfigLayout(
1927 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001928 self.sched.reconfigure(self.config)
1929 self.registerJobs()
1930 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1931
1932 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1933 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1934 self.waitUntilSettled()
1935 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1936
1937 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1938 self.waitUntilSettled()
1939
1940 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1941
James E. Blair08d19992016-08-10 15:25:31 -07001942 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001943 self.waitUntilSettled()
1944
James E. Blairec056492016-07-22 09:45:56 -07001945 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001946 def test_zuul_url_return(self):
1947 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001948 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001949 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001950
1951 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001952 A.addApproval('code-review', 2)
1953 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001954 self.waitUntilSettled()
1955
1956 self.assertEqual(len(self.builds), 1)
1957 for build in self.builds:
1958 self.assertTrue('ZUUL_URL' in build.parameters)
1959
James E. Blair08d19992016-08-10 15:25:31 -07001960 self.launch_server.hold_jobs_in_build = False
1961 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001962 self.waitUntilSettled()
1963
James E. Blairec056492016-07-22 09:45:56 -07001964 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001965 def test_new_patchset_dequeues_old_on_head(self):
1966 "Test that a new patchset causes the old to be dequeued (at head)"
1967 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001968 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001969 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1970 M.setMerged()
1971 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1972 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1973 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1974 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001975 A.addApproval('code-review', 2)
1976 B.addApproval('code-review', 2)
1977 C.addApproval('code-review', 2)
1978 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001979
1980 C.setDependsOn(B, 1)
1981 B.setDependsOn(A, 1)
1982 A.setDependsOn(M, 1)
1983
James E. Blair8b5408c2016-08-08 15:37:46 -07001984 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1985 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1986 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1987 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001988 self.waitUntilSettled()
1989
1990 A.addPatchset()
1991 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1992 self.waitUntilSettled()
1993
James E. Blair08d19992016-08-10 15:25:31 -07001994 self.launch_server.hold_jobs_in_build = False
1995 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001996 self.waitUntilSettled()
1997
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001998 self.assertEqual(A.data['status'], 'NEW')
1999 self.assertEqual(A.reported, 2)
2000 self.assertEqual(B.data['status'], 'NEW')
2001 self.assertEqual(B.reported, 2)
2002 self.assertEqual(C.data['status'], 'NEW')
2003 self.assertEqual(C.reported, 2)
2004 self.assertEqual(D.data['status'], 'MERGED')
2005 self.assertEqual(D.reported, 2)
2006 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002007
James E. Blairec056492016-07-22 09:45:56 -07002008 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002009 def test_new_patchset_dequeues_old_without_dependents(self):
2010 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002011 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002012 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2013 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2014 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002015 A.addApproval('code-review', 2)
2016 B.addApproval('code-review', 2)
2017 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002018
James E. Blair8b5408c2016-08-08 15:37:46 -07002019 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2020 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2021 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002022 self.waitUntilSettled()
2023
2024 B.addPatchset()
2025 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2026 self.waitUntilSettled()
2027
James E. Blair08d19992016-08-10 15:25:31 -07002028 self.launch_server.hold_jobs_in_build = False
2029 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002030 self.waitUntilSettled()
2031
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002032 self.assertEqual(A.data['status'], 'MERGED')
2033 self.assertEqual(A.reported, 2)
2034 self.assertEqual(B.data['status'], 'NEW')
2035 self.assertEqual(B.reported, 2)
2036 self.assertEqual(C.data['status'], 'MERGED')
2037 self.assertEqual(C.reported, 2)
2038 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002039
James E. Blairec056492016-07-22 09:45:56 -07002040 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002041 def test_new_patchset_dequeues_old_independent_queue(self):
2042 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002043 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002044 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2045 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2046 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2047 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2048 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2049 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2050 self.waitUntilSettled()
2051
2052 B.addPatchset()
2053 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2054 self.waitUntilSettled()
2055
James E. Blair08d19992016-08-10 15:25:31 -07002056 self.launch_server.hold_jobs_in_build = False
2057 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002058 self.waitUntilSettled()
2059
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002060 self.assertEqual(A.data['status'], 'NEW')
2061 self.assertEqual(A.reported, 1)
2062 self.assertEqual(B.data['status'], 'NEW')
2063 self.assertEqual(B.reported, 1)
2064 self.assertEqual(C.data['status'], 'NEW')
2065 self.assertEqual(C.reported, 1)
2066 self.assertEqual(len(self.history), 10)
2067 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002068
James E. Blairec056492016-07-22 09:45:56 -07002069 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002070 def test_noop_job(self):
2071 "Test that the internal noop job works"
2072 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002073 A.addApproval('code-review', 2)
2074 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002075 self.waitUntilSettled()
2076
2077 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2078 self.assertTrue(self.sched._areAllBuildsComplete())
2079 self.assertEqual(len(self.history), 0)
2080 self.assertEqual(A.data['status'], 'MERGED')
2081 self.assertEqual(A.reported, 2)
2082
James E. Blairec056492016-07-22 09:45:56 -07002083 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002084 def test_no_job_project(self):
2085 "Test that reports with no jobs don't get sent"
2086 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2087 'master', 'A')
2088 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2089 self.waitUntilSettled()
2090
2091 # Change wasn't reported to
2092 self.assertEqual(A.reported, False)
2093
2094 # Check queue is empty afterwards
2095 check_pipeline = self.sched.layout.pipelines['check']
2096 items = check_pipeline.getAllItems()
2097 self.assertEqual(len(items), 0)
2098
2099 self.assertEqual(len(self.history), 0)
2100
James E. Blairec056492016-07-22 09:45:56 -07002101 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002102 def test_zuul_refs(self):
2103 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002104 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002105 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2106 M1.setMerged()
2107 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2108 M2.setMerged()
2109
2110 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2111 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2112 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2113 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002114 A.addApproval('code-review', 2)
2115 B.addApproval('code-review', 2)
2116 C.addApproval('code-review', 2)
2117 D.addApproval('code-review', 2)
2118 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2119 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2120 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2121 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002122
2123 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002124 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002125 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002126 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002127 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002128 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002129 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002130 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002131 self.waitUntilSettled()
2132
James E. Blair7d0dedc2013-02-21 17:26:09 -08002133 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002134 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002135 if x.parameters['ZUUL_CHANGE'] == '3':
2136 a_zref = x.parameters['ZUUL_REF']
2137 if x.parameters['ZUUL_CHANGE'] == '4':
2138 b_zref = x.parameters['ZUUL_REF']
2139 if x.parameters['ZUUL_CHANGE'] == '5':
2140 c_zref = x.parameters['ZUUL_REF']
2141 if x.parameters['ZUUL_CHANGE'] == '6':
2142 d_zref = x.parameters['ZUUL_REF']
2143
2144 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002145 self.assertIsNotNone(a_zref)
2146 self.assertIsNotNone(b_zref)
2147 self.assertIsNotNone(c_zref)
2148 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002149
2150 # And they should all be different
2151 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002152 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002153
2154 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002155 self.assertTrue(self.ref_has_change(a_zref, A))
2156 self.assertFalse(self.ref_has_change(a_zref, B))
2157 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002158
2159 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002160 self.assertTrue(self.ref_has_change(b_zref, A))
2161 self.assertTrue(self.ref_has_change(b_zref, B))
2162 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002163
2164 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002165 self.assertTrue(self.ref_has_change(c_zref, A))
2166 self.assertTrue(self.ref_has_change(c_zref, B))
2167 self.assertTrue(self.ref_has_change(c_zref, C))
2168 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002169
2170 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002171 self.assertTrue(self.ref_has_change(d_zref, A))
2172 self.assertTrue(self.ref_has_change(d_zref, B))
2173 self.assertTrue(self.ref_has_change(d_zref, C))
2174 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002175
James E. Blair08d19992016-08-10 15:25:31 -07002176 self.launch_server.hold_jobs_in_build = False
2177 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002178 self.waitUntilSettled()
2179
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002180 self.assertEqual(A.data['status'], 'MERGED')
2181 self.assertEqual(A.reported, 2)
2182 self.assertEqual(B.data['status'], 'MERGED')
2183 self.assertEqual(B.reported, 2)
2184 self.assertEqual(C.data['status'], 'MERGED')
2185 self.assertEqual(C.reported, 2)
2186 self.assertEqual(D.data['status'], 'MERGED')
2187 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002188
James E. Blairec056492016-07-22 09:45:56 -07002189 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002190 def test_rerun_on_error(self):
2191 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002192 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002193 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002194 A.addApproval('code-review', 2)
2195 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002196 self.waitUntilSettled()
2197
2198 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002199 self.launch_server.hold_jobs_in_build = False
2200 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002201 self.waitUntilSettled()
2202 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2203 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2204
James E. Blairec056492016-07-22 09:45:56 -07002205 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002206 def test_statsd(self):
2207 "Test each of the statsd methods used in the scheduler"
2208 import extras
2209 statsd = extras.try_import('statsd.statsd')
2210 statsd.incr('test-incr')
2211 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002212 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002213 self.assertReportedStat('test-incr', '1|c')
2214 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002215 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002216
James E. Blairec056492016-07-22 09:45:56 -07002217 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002218 def test_stuck_job_cleanup(self):
2219 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002220 # This job won't be registered at startup because it is not in
2221 # the standard layout, but we need it to already be registerd
2222 # for when we reconfigure, as that is when Zuul will attempt
2223 # to run the new job.
2224 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002225 self.gearman_server.hold_jobs_in_queue = True
2226 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002227 A.addApproval('code-review', 2)
2228 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002229 self.waitUntilSettled()
2230 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2231
James E. Blairf84026c2015-12-08 16:11:46 -08002232 self.updateConfigLayout(
2233 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002234 self.sched.reconfigure(self.config)
2235 self.waitUntilSettled()
2236
James E. Blair18c64442014-03-18 10:14:45 -07002237 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002238 self.waitUntilSettled()
2239 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2240 self.assertTrue(self.sched._areAllBuildsComplete())
2241
2242 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002243 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002244 self.assertEqual(self.history[0].result, 'SUCCESS')
2245
James E. Blairec056492016-07-22 09:45:56 -07002246 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002247 def test_file_head(self):
2248 # This is a regression test for an observed bug. A change
2249 # with a file named "HEAD" in the root directory of the repo
2250 # was processed by a merger. It then was unable to reset the
2251 # repo because of:
2252 # GitCommandError: 'git reset --hard HEAD' returned
2253 # with exit code 128
2254 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2255 # and filename
2256 # Use '--' to separate filenames from revisions'
2257
2258 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2259 A.addPatchset(['HEAD'])
2260 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2261
2262 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2263 self.waitUntilSettled()
2264
2265 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2266 self.waitUntilSettled()
2267
2268 self.assertIn('Build succeeded', A.messages[0])
2269 self.assertIn('Build succeeded', B.messages[0])
2270
James E. Blairec056492016-07-22 09:45:56 -07002271 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002272 def test_file_jobs(self):
2273 "Test that file jobs run only when appropriate"
2274 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2275 A.addPatchset(['pip-requires'])
2276 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002277 A.addApproval('code-review', 2)
2278 B.addApproval('code-review', 2)
2279 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2280 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002281 self.waitUntilSettled()
2282
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002283 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002284 if x.name == 'project-testfile']
2285
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002286 self.assertEqual(len(testfile_jobs), 1)
2287 self.assertEqual(testfile_jobs[0].changes, '1,2')
2288 self.assertEqual(A.data['status'], 'MERGED')
2289 self.assertEqual(A.reported, 2)
2290 self.assertEqual(B.data['status'], 'MERGED')
2291 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002292
James E. Blairec056492016-07-22 09:45:56 -07002293 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002294 def _test_skip_if_jobs(self, branch, should_skip):
2295 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002296 self.updateConfigLayout(
2297 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002298 self.sched.reconfigure(self.config)
2299 self.registerJobs()
2300
2301 change = self.fake_gerrit.addFakeChange('org/project',
2302 branch,
2303 'test skip-if')
2304 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2305 self.waitUntilSettled()
2306
2307 tested_change_ids = [x.changes[0] for x in self.history
2308 if x.name == 'project-test-skip-if']
2309
2310 if should_skip:
2311 self.assertEqual([], tested_change_ids)
2312 else:
2313 self.assertIn(change.data['number'], tested_change_ids)
2314
James E. Blairec056492016-07-22 09:45:56 -07002315 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002316 def test_skip_if_match_skips_job(self):
2317 self._test_skip_if_jobs(branch='master', should_skip=True)
2318
James E. Blairec056492016-07-22 09:45:56 -07002319 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002320 def test_skip_if_no_match_runs_job(self):
2321 self._test_skip_if_jobs(branch='mp', should_skip=False)
2322
James E. Blairec056492016-07-22 09:45:56 -07002323 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002324 def test_test_config(self):
2325 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002326 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002327 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002328
James E. Blairec056492016-07-22 09:45:56 -07002329 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002330 def test_queue_names(self):
2331 "Test shared change queue names"
2332 project1 = self.sched.layout.projects['org/project1']
2333 project2 = self.sched.layout.projects['org/project2']
2334 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2335 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2336 self.assertEqual(q1.name, 'integration')
2337 self.assertEqual(q2.name, 'integration')
2338
James E. Blairf84026c2015-12-08 16:11:46 -08002339 self.updateConfigLayout(
2340 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002341 with testtools.ExpectedException(
2342 Exception, "More than one name assigned to change queue"):
2343 self.sched.reconfigure(self.config)
2344
James E. Blairec056492016-07-22 09:45:56 -07002345 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002346 def test_queue_precedence(self):
2347 "Test that queue precedence works"
2348
2349 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002350 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002351 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2352 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002353 A.addApproval('code-review', 2)
2354 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002355
2356 self.waitUntilSettled()
2357 self.gearman_server.hold_jobs_in_queue = False
2358 self.gearman_server.release()
2359 self.waitUntilSettled()
2360
James E. Blair8de58bd2013-07-18 16:23:33 -07002361 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002362 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002363 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002364 self.waitUntilSettled()
2365
James E. Blair64ed6f22013-07-10 14:07:23 -07002366 self.log.debug(self.history)
2367 self.assertEqual(self.history[0].pipeline, 'gate')
2368 self.assertEqual(self.history[1].pipeline, 'check')
2369 self.assertEqual(self.history[2].pipeline, 'gate')
2370 self.assertEqual(self.history[3].pipeline, 'gate')
2371 self.assertEqual(self.history[4].pipeline, 'check')
2372 self.assertEqual(self.history[5].pipeline, 'check')
2373
James E. Blairec056492016-07-22 09:45:56 -07002374 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002375 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002376 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002377 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002378 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002379 A.addApproval('code-review', 2)
2380 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002381 self.waitUntilSettled()
2382
James E. Blair08d19992016-08-10 15:25:31 -07002383 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002384 self.waitUntilSettled()
2385
James E. Blair1843a552013-07-03 14:19:52 -07002386 port = self.webapp.server.socket.getsockname()[1]
2387
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002388 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2389 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002390 headers = f.info()
2391 self.assertIn('Content-Length', headers)
2392 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002393 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2394 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002395 self.assertIn('Access-Control-Allow-Origin', headers)
2396 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002397 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002398 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002399 data = f.read()
2400
James E. Blair08d19992016-08-10 15:25:31 -07002401 self.launch_server.hold_jobs_in_build = False
2402 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002403 self.waitUntilSettled()
2404
2405 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002406 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002407 for p in data['pipelines']:
2408 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002409 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002410 self.assertEqual(q['window'], 20)
2411 else:
2412 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002413 for head in q['heads']:
2414 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002415 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002416 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002417 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002418 status_jobs.append(job)
2419 self.assertEqual('project-merge', status_jobs[0]['name'])
2420 self.assertEqual('https://server/job/project-merge/0/',
2421 status_jobs[0]['url'])
2422 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2423 status_jobs[0]['report_url'])
2424
2425 self.assertEqual('project-test1', status_jobs[1]['name'])
2426 self.assertEqual('https://server/job/project-test1/1/',
2427 status_jobs[1]['url'])
2428 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2429 status_jobs[1]['report_url'])
2430
2431 self.assertEqual('project-test2', status_jobs[2]['name'])
2432 self.assertEqual('https://server/job/project-test2/2/',
2433 status_jobs[2]['url'])
2434 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2435 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002436
James E. Blairec056492016-07-22 09:45:56 -07002437 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002438 def test_merging_queues(self):
2439 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002440 self.updateConfigLayout(
2441 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002442 self.sched.reconfigure(self.config)
2443 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2444
James E. Blairec056492016-07-22 09:45:56 -07002445 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002446 def test_mutex(self):
2447 "Test job mutexes"
2448 self.config.set('zuul', 'layout_config',
2449 'tests/fixtures/layout-mutex.yaml')
2450 self.sched.reconfigure(self.config)
2451
James E. Blair08d19992016-08-10 15:25:31 -07002452 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002453 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2454 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2455 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2456
2457 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2458 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2459 self.waitUntilSettled()
2460 self.assertEqual(len(self.builds), 3)
2461 self.assertEqual(self.builds[0].name, 'project-test1')
2462 self.assertEqual(self.builds[1].name, 'mutex-one')
2463 self.assertEqual(self.builds[2].name, 'project-test1')
2464
James E. Blair08d19992016-08-10 15:25:31 -07002465 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002466 self.waitUntilSettled()
2467
2468 self.assertEqual(len(self.builds), 3)
2469 self.assertEqual(self.builds[0].name, 'project-test1')
2470 self.assertEqual(self.builds[1].name, 'project-test1')
2471 self.assertEqual(self.builds[2].name, 'mutex-two')
2472 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2473
James E. Blair08d19992016-08-10 15:25:31 -07002474 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002475 self.waitUntilSettled()
2476
2477 self.assertEqual(len(self.builds), 3)
2478 self.assertEqual(self.builds[0].name, 'project-test1')
2479 self.assertEqual(self.builds[1].name, 'project-test1')
2480 self.assertEqual(self.builds[2].name, 'mutex-one')
2481 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2482
James E. Blair08d19992016-08-10 15:25:31 -07002483 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002484 self.waitUntilSettled()
2485
2486 self.assertEqual(len(self.builds), 3)
2487 self.assertEqual(self.builds[0].name, 'project-test1')
2488 self.assertEqual(self.builds[1].name, 'project-test1')
2489 self.assertEqual(self.builds[2].name, 'mutex-two')
2490 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2491
James E. Blair08d19992016-08-10 15:25:31 -07002492 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002493 self.waitUntilSettled()
2494
2495 self.assertEqual(len(self.builds), 2)
2496 self.assertEqual(self.builds[0].name, 'project-test1')
2497 self.assertEqual(self.builds[1].name, 'project-test1')
2498 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2499
James E. Blair08d19992016-08-10 15:25:31 -07002500 self.launch_server.hold_jobs_in_build = False
2501 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002502
2503 self.waitUntilSettled()
2504 self.assertEqual(len(self.builds), 0)
2505
2506 self.assertEqual(A.reported, 1)
2507 self.assertEqual(B.reported, 1)
2508 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2509
James E. Blairec056492016-07-22 09:45:56 -07002510 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002511 def test_node_label(self):
2512 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002513 self.worker.registerFunction('build:node-project-test1:debian')
2514
2515 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002516 A.addApproval('code-review', 2)
2517 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002518 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002519
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002520 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2521 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2522 'debian')
2523 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002524
James E. Blairec056492016-07-22 09:45:56 -07002525 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002526 def test_live_reconfiguration(self):
2527 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002528 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002529 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002530 A.addApproval('code-review', 2)
2531 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002532 self.waitUntilSettled()
2533
2534 self.sched.reconfigure(self.config)
2535
James E. Blair08d19992016-08-10 15:25:31 -07002536 self.launch_server.hold_jobs_in_build = False
2537 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002538 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002539 self.assertEqual(self.getJobFromHistory('project-merge').result,
2540 'SUCCESS')
2541 self.assertEqual(self.getJobFromHistory('project-test1').result,
2542 'SUCCESS')
2543 self.assertEqual(self.getJobFromHistory('project-test2').result,
2544 'SUCCESS')
2545 self.assertEqual(A.data['status'], 'MERGED')
2546 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002547
James E. Blairec056492016-07-22 09:45:56 -07002548 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002549 def test_live_reconfiguration_merge_conflict(self):
2550 # A real-world bug: a change in a gate queue has a merge
2551 # conflict and a job is added to its project while it's
2552 # sitting in the queue. The job gets added to the change and
2553 # enqueued and the change gets stuck.
2554 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002555 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002556
2557 # This change is fine. It's here to stop the queue long
2558 # enough for the next change to be subject to the
2559 # reconfiguration, as well as to provide a conflict for the
2560 # next change. This change will succeed and merge.
2561 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2562 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002563 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002564
2565 # This change will be in merge conflict. During the
2566 # reconfiguration, we will add a job. We want to make sure
2567 # that doesn't cause it to get stuck.
2568 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2569 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002570 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002571
James E. Blair8b5408c2016-08-08 15:37:46 -07002572 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2573 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002574
2575 self.waitUntilSettled()
2576
2577 # No jobs have run yet
2578 self.assertEqual(A.data['status'], 'NEW')
2579 self.assertEqual(A.reported, 1)
2580 self.assertEqual(B.data['status'], 'NEW')
2581 self.assertEqual(B.reported, 1)
2582 self.assertEqual(len(self.history), 0)
2583
2584 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002585 self.updateConfigLayout(
2586 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002587 self.sched.reconfigure(self.config)
2588 self.waitUntilSettled()
2589
James E. Blair08d19992016-08-10 15:25:31 -07002590 self.launch_server.hold_jobs_in_build = False
2591 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002592 self.waitUntilSettled()
2593
2594 self.assertEqual(A.data['status'], 'MERGED')
2595 self.assertEqual(A.reported, 2)
2596 self.assertEqual(B.data['status'], 'NEW')
2597 self.assertEqual(B.reported, 2)
2598 self.assertEqual(self.getJobFromHistory('project-merge').result,
2599 'SUCCESS')
2600 self.assertEqual(self.getJobFromHistory('project-test1').result,
2601 'SUCCESS')
2602 self.assertEqual(self.getJobFromHistory('project-test2').result,
2603 'SUCCESS')
2604 self.assertEqual(self.getJobFromHistory('project-test3').result,
2605 'SUCCESS')
2606 self.assertEqual(len(self.history), 4)
2607
James E. Blairec056492016-07-22 09:45:56 -07002608 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002609 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002610 # An extrapolation of test_live_reconfiguration_merge_conflict
2611 # that tests a job added to a job tree with a failed root does
2612 # not run.
2613 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002614 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002615
2616 # This change is fine. It's here to stop the queue long
2617 # enough for the next change to be subject to the
2618 # reconfiguration. This change will succeed and merge.
2619 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2620 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002621 A.addApproval('code-review', 2)
2622 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002623 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002624 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002625 self.waitUntilSettled()
2626
2627 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002628 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002629 B.addApproval('code-review', 2)
2630 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002631 self.waitUntilSettled()
2632
James E. Blair08d19992016-08-10 15:25:31 -07002633 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002634 self.waitUntilSettled()
2635
2636 # Both -merge jobs have run, but no others.
2637 self.assertEqual(A.data['status'], 'NEW')
2638 self.assertEqual(A.reported, 1)
2639 self.assertEqual(B.data['status'], 'NEW')
2640 self.assertEqual(B.reported, 1)
2641 self.assertEqual(self.history[0].result, 'SUCCESS')
2642 self.assertEqual(self.history[0].name, 'project-merge')
2643 self.assertEqual(self.history[1].result, 'FAILURE')
2644 self.assertEqual(self.history[1].name, 'project-merge')
2645 self.assertEqual(len(self.history), 2)
2646
2647 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002648 self.updateConfigLayout(
2649 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002650 self.sched.reconfigure(self.config)
2651 self.waitUntilSettled()
2652
James E. Blair08d19992016-08-10 15:25:31 -07002653 self.launch_server.hold_jobs_in_build = False
2654 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002655 self.waitUntilSettled()
2656
2657 self.assertEqual(A.data['status'], 'MERGED')
2658 self.assertEqual(A.reported, 2)
2659 self.assertEqual(B.data['status'], 'NEW')
2660 self.assertEqual(B.reported, 2)
2661 self.assertEqual(self.history[0].result, 'SUCCESS')
2662 self.assertEqual(self.history[0].name, 'project-merge')
2663 self.assertEqual(self.history[1].result, 'FAILURE')
2664 self.assertEqual(self.history[1].name, 'project-merge')
2665 self.assertEqual(self.history[2].result, 'SUCCESS')
2666 self.assertEqual(self.history[3].result, 'SUCCESS')
2667 self.assertEqual(self.history[4].result, 'SUCCESS')
2668 self.assertEqual(len(self.history), 5)
2669
James E. Blairec056492016-07-22 09:45:56 -07002670 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002671 def test_live_reconfiguration_failed_job(self):
2672 # Test that a change with a removed failing job does not
2673 # disrupt reconfiguration. If a change has a failed job and
2674 # that job is removed during a reconfiguration, we observed a
2675 # bug where the code to re-set build statuses would run on
2676 # that build and raise an exception because the job no longer
2677 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002678 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002679
2680 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2681
2682 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002683 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002684
2685 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2686 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002687 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002688 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002689 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002690 self.waitUntilSettled()
2691
2692 self.assertEqual(A.data['status'], 'NEW')
2693 self.assertEqual(A.reported, 0)
2694
2695 self.assertEqual(self.getJobFromHistory('project-merge').result,
2696 'SUCCESS')
2697 self.assertEqual(self.getJobFromHistory('project-test1').result,
2698 'FAILURE')
2699 self.assertEqual(len(self.history), 2)
2700
2701 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002702 self.updateConfigLayout(
2703 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002704 self.sched.reconfigure(self.config)
2705 self.waitUntilSettled()
2706
James E. Blair08d19992016-08-10 15:25:31 -07002707 self.launch_server.hold_jobs_in_build = False
2708 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002709 self.waitUntilSettled()
2710
2711 self.assertEqual(self.getJobFromHistory('project-test2').result,
2712 'SUCCESS')
2713 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2714 'SUCCESS')
2715 self.assertEqual(len(self.history), 4)
2716
2717 self.assertEqual(A.data['status'], 'NEW')
2718 self.assertEqual(A.reported, 1)
2719 self.assertIn('Build succeeded', A.messages[0])
2720 # Ensure the removed job was not included in the report.
2721 self.assertNotIn('project-test1', A.messages[0])
2722
James E. Blairec056492016-07-22 09:45:56 -07002723 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002724 def test_live_reconfiguration_shared_queue(self):
2725 # Test that a change with a failing job which was removed from
2726 # this project but otherwise still exists in the system does
2727 # not disrupt reconfiguration.
2728
James E. Blair08d19992016-08-10 15:25:31 -07002729 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002730
2731 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2732
James E. Blair08d19992016-08-10 15:25:31 -07002733 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002734
2735 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2736 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002737 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002738 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002739 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002740 self.waitUntilSettled()
2741
2742 self.assertEqual(A.data['status'], 'NEW')
2743 self.assertEqual(A.reported, 0)
2744
2745 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2746 'SUCCESS')
2747 self.assertEqual(self.getJobFromHistory(
2748 'project1-project2-integration').result, 'FAILURE')
2749 self.assertEqual(len(self.history), 2)
2750
2751 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002752 self.updateConfigLayout(
2753 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002754 self.sched.reconfigure(self.config)
2755 self.waitUntilSettled()
2756
James E. Blair08d19992016-08-10 15:25:31 -07002757 self.launch_server.hold_jobs_in_build = False
2758 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002759 self.waitUntilSettled()
2760
2761 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2762 'SUCCESS')
2763 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2764 'SUCCESS')
2765 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2766 'SUCCESS')
2767 self.assertEqual(self.getJobFromHistory(
2768 'project1-project2-integration').result, 'FAILURE')
2769 self.assertEqual(len(self.history), 4)
2770
2771 self.assertEqual(A.data['status'], 'NEW')
2772 self.assertEqual(A.reported, 1)
2773 self.assertIn('Build succeeded', A.messages[0])
2774 # Ensure the removed job was not included in the report.
2775 self.assertNotIn('project1-project2-integration', A.messages[0])
2776
James E. Blairec056492016-07-22 09:45:56 -07002777 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002778 def test_double_live_reconfiguration_shared_queue(self):
2779 # This was a real-world regression. A change is added to
2780 # gate; a reconfigure happens, a second change which depends
2781 # on the first is added, and a second reconfiguration happens.
2782 # Ensure that both changes merge.
2783
2784 # A failure may indicate incorrect caching or cleaning up of
2785 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002786 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002787
2788 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2789 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2790 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002791 A.addApproval('code-review', 2)
2792 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002793
2794 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002795 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002796 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002797 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002798 self.waitUntilSettled()
2799
2800 # Reconfigure (with only one change in the pipeline).
2801 self.sched.reconfigure(self.config)
2802 self.waitUntilSettled()
2803
2804 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002805 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002806 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002807 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002808 self.waitUntilSettled()
2809
2810 # Reconfigure (with both in the pipeline).
2811 self.sched.reconfigure(self.config)
2812 self.waitUntilSettled()
2813
James E. Blair08d19992016-08-10 15:25:31 -07002814 self.launch_server.hold_jobs_in_build = False
2815 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002816 self.waitUntilSettled()
2817
2818 self.assertEqual(len(self.history), 8)
2819
2820 self.assertEqual(A.data['status'], 'MERGED')
2821 self.assertEqual(A.reported, 2)
2822 self.assertEqual(B.data['status'], 'MERGED')
2823 self.assertEqual(B.reported, 2)
2824
James E. Blairec056492016-07-22 09:45:56 -07002825 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002826 def test_live_reconfiguration_del_project(self):
2827 # Test project deletion from layout
2828 # while changes are enqueued
2829
James E. Blair08d19992016-08-10 15:25:31 -07002830 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002831 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2832 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2833 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2834
2835 # A Depends-On: B
2836 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2837 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002838 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002839
2840 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2841 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2842 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002843 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002844 self.waitUntilSettled()
2845 self.assertEqual(len(self.builds), 5)
2846
2847 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002848 self.updateConfigLayout(
2849 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002850 self.sched.reconfigure(self.config)
2851 self.waitUntilSettled()
2852
2853 # Builds for C aborted, builds for A succeed,
2854 # and have change B applied ahead
2855 job_c = self.getJobFromHistory('project1-test1')
2856 self.assertEqual(job_c.changes, '3,1')
2857 self.assertEqual(job_c.result, 'ABORTED')
2858
James E. Blair08d19992016-08-10 15:25:31 -07002859 self.launch_server.hold_jobs_in_build = False
2860 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002861 self.waitUntilSettled()
2862
2863 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2864 '2,1 1,1')
2865
2866 self.assertEqual(A.data['status'], 'NEW')
2867 self.assertEqual(B.data['status'], 'NEW')
2868 self.assertEqual(C.data['status'], 'NEW')
2869 self.assertEqual(A.reported, 1)
2870 self.assertEqual(B.reported, 0)
2871 self.assertEqual(C.reported, 0)
2872
2873 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2874 self.assertIn('Build succeeded', A.messages[0])
2875
James E. Blairec056492016-07-22 09:45:56 -07002876 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002877 def test_live_reconfiguration_functions(self):
2878 "Test live reconfiguration with a custom function"
2879 self.worker.registerFunction('build:node-project-test1:debian')
2880 self.worker.registerFunction('build:node-project-test1:wheezy')
2881 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002882 A.addApproval('code-review', 2)
2883 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002884 self.waitUntilSettled()
2885
2886 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2887 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2888 'debian')
2889 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2890
James E. Blairf84026c2015-12-08 16:11:46 -08002891 self.updateConfigLayout(
2892 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002893 self.sched.reconfigure(self.config)
2894 self.worker.build_history = []
2895
2896 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002897 B.addApproval('code-review', 2)
2898 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002899 self.waitUntilSettled()
2900
2901 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2902 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2903 'wheezy')
2904 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2905
James E. Blairec056492016-07-22 09:45:56 -07002906 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002907 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002908 self.updateConfigLayout(
2909 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002910 self.sched.reconfigure(self.config)
2911
2912 self.init_repo("org/new-project")
2913 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2914
James E. Blair8b5408c2016-08-08 15:37:46 -07002915 A.addApproval('code-review', 2)
2916 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002917 self.waitUntilSettled()
2918 self.assertEqual(self.getJobFromHistory('project-merge').result,
2919 'SUCCESS')
2920 self.assertEqual(self.getJobFromHistory('project-test1').result,
2921 'SUCCESS')
2922 self.assertEqual(self.getJobFromHistory('project-test2').result,
2923 'SUCCESS')
2924 self.assertEqual(A.data['status'], 'MERGED')
2925 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002926
James E. Blairec056492016-07-22 09:45:56 -07002927 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002928 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002929 self.updateConfigLayout(
2930 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002931 self.sched.reconfigure(self.config)
2932
2933 self.init_repo("org/delete-project")
2934 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2935
James E. Blair8b5408c2016-08-08 15:37:46 -07002936 A.addApproval('code-review', 2)
2937 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002938 self.waitUntilSettled()
2939 self.assertEqual(self.getJobFromHistory('project-merge').result,
2940 'SUCCESS')
2941 self.assertEqual(self.getJobFromHistory('project-test1').result,
2942 'SUCCESS')
2943 self.assertEqual(self.getJobFromHistory('project-test2').result,
2944 'SUCCESS')
2945 self.assertEqual(A.data['status'], 'MERGED')
2946 self.assertEqual(A.reported, 2)
2947
2948 # Delete org/new-project zuul repo. Should be recloned.
2949 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2950
2951 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2952
James E. Blair8b5408c2016-08-08 15:37:46 -07002953 B.addApproval('code-review', 2)
2954 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002955 self.waitUntilSettled()
2956 self.assertEqual(self.getJobFromHistory('project-merge').result,
2957 'SUCCESS')
2958 self.assertEqual(self.getJobFromHistory('project-test1').result,
2959 'SUCCESS')
2960 self.assertEqual(self.getJobFromHistory('project-test2').result,
2961 'SUCCESS')
2962 self.assertEqual(B.data['status'], 'MERGED')
2963 self.assertEqual(B.reported, 2)
2964
James E. Blairec056492016-07-22 09:45:56 -07002965 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002966 def test_tags(self):
2967 "Test job tags"
2968 self.config.set('zuul', 'layout_config',
2969 'tests/fixtures/layout-tags.yaml')
2970 self.sched.reconfigure(self.config)
2971
2972 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2973 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2974 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2975 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2976 self.waitUntilSettled()
2977
2978 results = {'project1-merge': 'extratag merge project1',
2979 'project2-merge': 'merge'}
2980
2981 for build in self.history:
2982 self.assertEqual(results.get(build.name, ''),
2983 build.parameters.get('BUILD_TAGS'))
2984
James E. Blairec056492016-07-22 09:45:56 -07002985 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002986 def test_timer(self):
2987 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002988 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002989 self.updateConfigLayout(
2990 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002991 self.sched.reconfigure(self.config)
2992 self.registerJobs()
2993
Clark Boylan3ee090a2014-04-03 20:55:09 -07002994 # The pipeline triggers every second, so we should have seen
2995 # several by now.
2996 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002997 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002998
2999 self.assertEqual(len(self.builds), 2)
3000
James E. Blair63bb0ef2013-07-29 17:14:51 -07003001 port = self.webapp.server.socket.getsockname()[1]
3002
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003003 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3004 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003005 data = f.read()
3006
James E. Blair08d19992016-08-10 15:25:31 -07003007 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003008 # Stop queuing timer triggered jobs so that the assertions
3009 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003010 self.updateConfigLayout(
3011 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003012 self.sched.reconfigure(self.config)
3013 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003014 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003015 self.waitUntilSettled()
3016
3017 self.assertEqual(self.getJobFromHistory(
3018 'project-bitrot-stable-old').result, 'SUCCESS')
3019 self.assertEqual(self.getJobFromHistory(
3020 'project-bitrot-stable-older').result, 'SUCCESS')
3021
3022 data = json.loads(data)
3023 status_jobs = set()
3024 for p in data['pipelines']:
3025 for q in p['change_queues']:
3026 for head in q['heads']:
3027 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003028 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003029 for job in change['jobs']:
3030 status_jobs.add(job['name'])
3031 self.assertIn('project-bitrot-stable-old', status_jobs)
3032 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003033
James E. Blairec056492016-07-22 09:45:56 -07003034 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003035 def test_idle(self):
3036 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003037 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003038
Clark Boylan3ee090a2014-04-03 20:55:09 -07003039 for x in range(1, 3):
3040 # Test that timer triggers periodic jobs even across
3041 # layout config reloads.
3042 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003043 self.updateConfigLayout(
3044 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003045 self.sched.reconfigure(self.config)
3046 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003047 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003048
Clark Boylan3ee090a2014-04-03 20:55:09 -07003049 # The pipeline triggers every second, so we should have seen
3050 # several by now.
3051 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003052
3053 # Stop queuing timer triggered jobs so that the assertions
3054 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003055 self.updateConfigLayout(
3056 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003057 self.sched.reconfigure(self.config)
3058 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003059 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003060
3061 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003062 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003063 self.waitUntilSettled()
3064 self.assertEqual(len(self.builds), 0)
3065 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003066
James E. Blairec056492016-07-22 09:45:56 -07003067 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003068 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003069 self.updateConfigLayout(
3070 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003071 self.sched.reconfigure(self.config)
3072
3073 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3074 self.waitUntilSettled()
3075
3076 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3077 self.waitUntilSettled()
3078
James E. Blairff80a2f2013-12-27 13:24:06 -08003079 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003080
3081 # A.messages only holds what FakeGerrit places in it. Thus we
3082 # work on the knowledge of what the first message should be as
3083 # it is only configured to go to SMTP.
3084
3085 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003086 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003087 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003088 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003089 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003090 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003091
3092 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003093 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003094 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003095 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003096 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003097 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003098
James E. Blairec056492016-07-22 09:45:56 -07003099 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003100 def test_timer_smtp(self):
3101 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003102 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003103 self.updateConfigLayout(
3104 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003105 self.sched.reconfigure(self.config)
3106 self.registerJobs()
3107
Clark Boylan3ee090a2014-04-03 20:55:09 -07003108 # The pipeline triggers every second, so we should have seen
3109 # several by now.
3110 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003111 self.waitUntilSettled()
3112
Clark Boylan3ee090a2014-04-03 20:55:09 -07003113 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003114 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003115 self.waitUntilSettled()
3116 self.assertEqual(len(self.history), 2)
3117
James E. Blaire5910202013-12-27 09:50:31 -08003118 self.assertEqual(self.getJobFromHistory(
3119 'project-bitrot-stable-old').result, 'SUCCESS')
3120 self.assertEqual(self.getJobFromHistory(
3121 'project-bitrot-stable-older').result, 'SUCCESS')
3122
James E. Blairff80a2f2013-12-27 13:24:06 -08003123 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003124
3125 # A.messages only holds what FakeGerrit places in it. Thus we
3126 # work on the knowledge of what the first message should be as
3127 # it is only configured to go to SMTP.
3128
3129 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003130 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003131 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003132 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003133 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003134 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003135
Clark Boylan3ee090a2014-04-03 20:55:09 -07003136 # Stop queuing timer triggered jobs and let any that may have
3137 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003138 self.updateConfigLayout(
3139 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003140 self.sched.reconfigure(self.config)
3141 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003142 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003143 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003144 self.waitUntilSettled()
3145
James E. Blairec056492016-07-22 09:45:56 -07003146 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003147 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003148 "Test that the RPC client can enqueue a change"
3149 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003150 A.addApproval('code-review', 2)
3151 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003152
3153 client = zuul.rpcclient.RPCClient('127.0.0.1',
3154 self.gearman_server.port)
3155 r = client.enqueue(pipeline='gate',
3156 project='org/project',
3157 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003158 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003159 self.waitUntilSettled()
3160 self.assertEqual(self.getJobFromHistory('project-merge').result,
3161 'SUCCESS')
3162 self.assertEqual(self.getJobFromHistory('project-test1').result,
3163 'SUCCESS')
3164 self.assertEqual(self.getJobFromHistory('project-test2').result,
3165 'SUCCESS')
3166 self.assertEqual(A.data['status'], 'MERGED')
3167 self.assertEqual(A.reported, 2)
3168 self.assertEqual(r, True)
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_ref(self):
3172 "Test that the RPC client can enqueue a ref"
3173
3174 client = zuul.rpcclient.RPCClient('127.0.0.1',
3175 self.gearman_server.port)
3176 r = client.enqueue_ref(
3177 pipeline='post',
3178 project='org/project',
3179 trigger='gerrit',
3180 ref='master',
3181 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3182 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3183 self.waitUntilSettled()
3184 job_names = [x.name for x in self.history]
3185 self.assertEqual(len(self.history), 1)
3186 self.assertIn('project-post', job_names)
3187 self.assertEqual(r, True)
3188
James E. Blairec056492016-07-22 09:45:56 -07003189 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003190 def test_client_enqueue_negative(self):
3191 "Test that the RPC client returns errors"
3192 client = zuul.rpcclient.RPCClient('127.0.0.1',
3193 self.gearman_server.port)
3194 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3195 "Invalid project"):
3196 r = client.enqueue(pipeline='gate',
3197 project='project-does-not-exist',
3198 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003199 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003200 client.shutdown()
3201 self.assertEqual(r, False)
3202
3203 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3204 "Invalid pipeline"):
3205 r = client.enqueue(pipeline='pipeline-does-not-exist',
3206 project='org/project',
3207 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003208 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003209 client.shutdown()
3210 self.assertEqual(r, False)
3211
3212 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3213 "Invalid trigger"):
3214 r = client.enqueue(pipeline='gate',
3215 project='org/project',
3216 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003217 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003218 client.shutdown()
3219 self.assertEqual(r, False)
3220
3221 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3222 "Invalid change"):
3223 r = client.enqueue(pipeline='gate',
3224 project='org/project',
3225 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003226 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003227 client.shutdown()
3228 self.assertEqual(r, False)
3229
3230 self.waitUntilSettled()
3231 self.assertEqual(len(self.history), 0)
3232 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003233
James E. Blairec056492016-07-22 09:45:56 -07003234 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003235 def test_client_promote(self):
3236 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003237 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003238 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3239 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3240 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003241 A.addApproval('code-review', 2)
3242 B.addApproval('code-review', 2)
3243 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003244
James E. Blair8b5408c2016-08-08 15:37:46 -07003245 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3246 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3247 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003248
3249 self.waitUntilSettled()
3250
Sean Daguef39b9ca2014-01-10 21:34:35 -05003251 items = self.sched.layout.pipelines['gate'].getAllItems()
3252 enqueue_times = {}
3253 for item in items:
3254 enqueue_times[str(item.change)] = item.enqueue_time
3255
James E. Blair36658cf2013-12-06 17:53:48 -08003256 client = zuul.rpcclient.RPCClient('127.0.0.1',
3257 self.gearman_server.port)
3258 r = client.promote(pipeline='gate',
3259 change_ids=['2,1', '3,1'])
3260
Sean Daguef39b9ca2014-01-10 21:34:35 -05003261 # ensure that enqueue times are durable
3262 items = self.sched.layout.pipelines['gate'].getAllItems()
3263 for item in items:
3264 self.assertEqual(
3265 enqueue_times[str(item.change)], item.enqueue_time)
3266
James E. Blair78acec92014-02-06 07:11:32 -08003267 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003268 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003269 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003270 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003271 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003272 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003273 self.waitUntilSettled()
3274
3275 self.assertEqual(len(self.builds), 6)
3276 self.assertEqual(self.builds[0].name, 'project-test1')
3277 self.assertEqual(self.builds[1].name, 'project-test2')
3278 self.assertEqual(self.builds[2].name, 'project-test1')
3279 self.assertEqual(self.builds[3].name, 'project-test2')
3280 self.assertEqual(self.builds[4].name, 'project-test1')
3281 self.assertEqual(self.builds[5].name, 'project-test2')
3282
3283 self.assertTrue(self.job_has_changes(self.builds[0], B))
3284 self.assertFalse(self.job_has_changes(self.builds[0], A))
3285 self.assertFalse(self.job_has_changes(self.builds[0], C))
3286
3287 self.assertTrue(self.job_has_changes(self.builds[2], B))
3288 self.assertTrue(self.job_has_changes(self.builds[2], C))
3289 self.assertFalse(self.job_has_changes(self.builds[2], A))
3290
3291 self.assertTrue(self.job_has_changes(self.builds[4], B))
3292 self.assertTrue(self.job_has_changes(self.builds[4], C))
3293 self.assertTrue(self.job_has_changes(self.builds[4], A))
3294
James E. Blair08d19992016-08-10 15:25:31 -07003295 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003296 self.waitUntilSettled()
3297
3298 self.assertEqual(A.data['status'], 'MERGED')
3299 self.assertEqual(A.reported, 2)
3300 self.assertEqual(B.data['status'], 'MERGED')
3301 self.assertEqual(B.reported, 2)
3302 self.assertEqual(C.data['status'], 'MERGED')
3303 self.assertEqual(C.reported, 2)
3304
3305 client.shutdown()
3306 self.assertEqual(r, True)
3307
James E. Blairec056492016-07-22 09:45:56 -07003308 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003309 def test_client_promote_dependent(self):
3310 "Test that the RPC client can promote a dependent change"
3311 # C (depends on B) -> B -> A ; then promote C to get:
3312 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003313 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003314 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3315 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3316 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3317
3318 C.setDependsOn(B, 1)
3319
James E. Blair8b5408c2016-08-08 15:37:46 -07003320 A.addApproval('code-review', 2)
3321 B.addApproval('code-review', 2)
3322 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003323
James E. Blair8b5408c2016-08-08 15:37:46 -07003324 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3325 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3326 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003327
3328 self.waitUntilSettled()
3329
3330 client = zuul.rpcclient.RPCClient('127.0.0.1',
3331 self.gearman_server.port)
3332 r = client.promote(pipeline='gate',
3333 change_ids=['3,1'])
3334
James E. Blair78acec92014-02-06 07:11:32 -08003335 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003336 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003337 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003338 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003339 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003340 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003341 self.waitUntilSettled()
3342
3343 self.assertEqual(len(self.builds), 6)
3344 self.assertEqual(self.builds[0].name, 'project-test1')
3345 self.assertEqual(self.builds[1].name, 'project-test2')
3346 self.assertEqual(self.builds[2].name, 'project-test1')
3347 self.assertEqual(self.builds[3].name, 'project-test2')
3348 self.assertEqual(self.builds[4].name, 'project-test1')
3349 self.assertEqual(self.builds[5].name, 'project-test2')
3350
3351 self.assertTrue(self.job_has_changes(self.builds[0], B))
3352 self.assertFalse(self.job_has_changes(self.builds[0], A))
3353 self.assertFalse(self.job_has_changes(self.builds[0], C))
3354
3355 self.assertTrue(self.job_has_changes(self.builds[2], B))
3356 self.assertTrue(self.job_has_changes(self.builds[2], C))
3357 self.assertFalse(self.job_has_changes(self.builds[2], A))
3358
3359 self.assertTrue(self.job_has_changes(self.builds[4], B))
3360 self.assertTrue(self.job_has_changes(self.builds[4], C))
3361 self.assertTrue(self.job_has_changes(self.builds[4], A))
3362
James E. Blair08d19992016-08-10 15:25:31 -07003363 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003364 self.waitUntilSettled()
3365
3366 self.assertEqual(A.data['status'], 'MERGED')
3367 self.assertEqual(A.reported, 2)
3368 self.assertEqual(B.data['status'], 'MERGED')
3369 self.assertEqual(B.reported, 2)
3370 self.assertEqual(C.data['status'], 'MERGED')
3371 self.assertEqual(C.reported, 2)
3372
3373 client.shutdown()
3374 self.assertEqual(r, True)
3375
James E. Blairec056492016-07-22 09:45:56 -07003376 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003377 def test_client_promote_negative(self):
3378 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003379 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003380 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003381 A.addApproval('code-review', 2)
3382 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003383 self.waitUntilSettled()
3384
3385 client = zuul.rpcclient.RPCClient('127.0.0.1',
3386 self.gearman_server.port)
3387
3388 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3389 r = client.promote(pipeline='nonexistent',
3390 change_ids=['2,1', '3,1'])
3391 client.shutdown()
3392 self.assertEqual(r, False)
3393
3394 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3395 r = client.promote(pipeline='gate',
3396 change_ids=['4,1'])
3397 client.shutdown()
3398 self.assertEqual(r, False)
3399
James E. Blair08d19992016-08-10 15:25:31 -07003400 self.launch_server.hold_jobs_in_build = False
3401 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003402 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003403
James E. Blairec056492016-07-22 09:45:56 -07003404 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003405 def test_queue_rate_limiting(self):
3406 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003407 self.updateConfigLayout(
3408 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003409 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003410 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003411 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3412 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3413 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3414
3415 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003416 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003417
James E. Blair8b5408c2016-08-08 15:37:46 -07003418 A.addApproval('code-review', 2)
3419 B.addApproval('code-review', 2)
3420 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003421
James E. Blair8b5408c2016-08-08 15:37:46 -07003422 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3423 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3424 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003425 self.waitUntilSettled()
3426
3427 # Only A and B will have their merge jobs queued because
3428 # window is 2.
3429 self.assertEqual(len(self.builds), 2)
3430 self.assertEqual(self.builds[0].name, 'project-merge')
3431 self.assertEqual(self.builds[1].name, 'project-merge')
3432
James E. Blair08d19992016-08-10 15:25:31 -07003433 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003434 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003435 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003436 self.waitUntilSettled()
3437
3438 # Only A and B will have their test jobs queued because
3439 # window is 2.
3440 self.assertEqual(len(self.builds), 4)
3441 self.assertEqual(self.builds[0].name, 'project-test1')
3442 self.assertEqual(self.builds[1].name, 'project-test2')
3443 self.assertEqual(self.builds[2].name, 'project-test1')
3444 self.assertEqual(self.builds[3].name, 'project-test2')
3445
James E. Blair08d19992016-08-10 15:25:31 -07003446 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003447 self.waitUntilSettled()
3448
3449 queue = self.sched.layout.pipelines['gate'].queues[0]
3450 # A failed so window is reduced by 1 to 1.
3451 self.assertEqual(queue.window, 1)
3452 self.assertEqual(queue.window_floor, 1)
3453 self.assertEqual(A.data['status'], 'NEW')
3454
3455 # Gate is reset and only B's merge job is queued because
3456 # window shrunk to 1.
3457 self.assertEqual(len(self.builds), 1)
3458 self.assertEqual(self.builds[0].name, 'project-merge')
3459
James E. Blair08d19992016-08-10 15:25:31 -07003460 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003461 self.waitUntilSettled()
3462
3463 # Only B's test jobs are queued because window is still 1.
3464 self.assertEqual(len(self.builds), 2)
3465 self.assertEqual(self.builds[0].name, 'project-test1')
3466 self.assertEqual(self.builds[1].name, 'project-test2')
3467
James E. Blair08d19992016-08-10 15:25:31 -07003468 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003469 self.waitUntilSettled()
3470
3471 # B was successfully merged so window is increased to 2.
3472 self.assertEqual(queue.window, 2)
3473 self.assertEqual(queue.window_floor, 1)
3474 self.assertEqual(B.data['status'], 'MERGED')
3475
3476 # Only C is left and its merge job is queued.
3477 self.assertEqual(len(self.builds), 1)
3478 self.assertEqual(self.builds[0].name, 'project-merge')
3479
James E. Blair08d19992016-08-10 15:25:31 -07003480 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003481 self.waitUntilSettled()
3482
3483 # After successful merge job the test jobs for C are queued.
3484 self.assertEqual(len(self.builds), 2)
3485 self.assertEqual(self.builds[0].name, 'project-test1')
3486 self.assertEqual(self.builds[1].name, 'project-test2')
3487
James E. Blair08d19992016-08-10 15:25:31 -07003488 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003489 self.waitUntilSettled()
3490
3491 # C successfully merged so window is bumped to 3.
3492 self.assertEqual(queue.window, 3)
3493 self.assertEqual(queue.window_floor, 1)
3494 self.assertEqual(C.data['status'], 'MERGED')
3495
James E. Blairec056492016-07-22 09:45:56 -07003496 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003497 def test_queue_rate_limiting_dependent(self):
3498 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003499 self.updateConfigLayout(
3500 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003501 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003502 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003503 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3504 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3505 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3506
3507 B.setDependsOn(A, 1)
3508
James E. Blair08d19992016-08-10 15:25:31 -07003509 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003510
James E. Blair8b5408c2016-08-08 15:37:46 -07003511 A.addApproval('code-review', 2)
3512 B.addApproval('code-review', 2)
3513 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003514
James E. Blair8b5408c2016-08-08 15:37:46 -07003515 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3516 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3517 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003518 self.waitUntilSettled()
3519
3520 # Only A and B will have their merge jobs queued because
3521 # window is 2.
3522 self.assertEqual(len(self.builds), 2)
3523 self.assertEqual(self.builds[0].name, 'project-merge')
3524 self.assertEqual(self.builds[1].name, 'project-merge')
3525
James E. Blair08d19992016-08-10 15:25:31 -07003526 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003527 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003528 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003529 self.waitUntilSettled()
3530
3531 # Only A and B will have their test jobs queued because
3532 # window is 2.
3533 self.assertEqual(len(self.builds), 4)
3534 self.assertEqual(self.builds[0].name, 'project-test1')
3535 self.assertEqual(self.builds[1].name, 'project-test2')
3536 self.assertEqual(self.builds[2].name, 'project-test1')
3537 self.assertEqual(self.builds[3].name, 'project-test2')
3538
James E. Blair08d19992016-08-10 15:25:31 -07003539 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003540 self.waitUntilSettled()
3541
3542 queue = self.sched.layout.pipelines['gate'].queues[0]
3543 # A failed so window is reduced by 1 to 1.
3544 self.assertEqual(queue.window, 1)
3545 self.assertEqual(queue.window_floor, 1)
3546 self.assertEqual(A.data['status'], 'NEW')
3547 self.assertEqual(B.data['status'], 'NEW')
3548
3549 # Gate is reset and only C's merge job is queued because
3550 # window shrunk to 1 and A and B were dequeued.
3551 self.assertEqual(len(self.builds), 1)
3552 self.assertEqual(self.builds[0].name, 'project-merge')
3553
James E. Blair08d19992016-08-10 15:25:31 -07003554 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003555 self.waitUntilSettled()
3556
3557 # Only C's test jobs are queued because window is still 1.
3558 self.assertEqual(len(self.builds), 2)
3559 self.assertEqual(self.builds[0].name, 'project-test1')
3560 self.assertEqual(self.builds[1].name, 'project-test2')
3561
James E. Blair08d19992016-08-10 15:25:31 -07003562 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003563 self.waitUntilSettled()
3564
3565 # C was successfully merged so window is increased to 2.
3566 self.assertEqual(queue.window, 2)
3567 self.assertEqual(queue.window_floor, 1)
3568 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003569
James E. Blairec056492016-07-22 09:45:56 -07003570 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003571 def test_worker_update_metadata(self):
3572 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003573 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003574
3575 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003576 A.addApproval('code-review', 2)
3577 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003578 self.waitUntilSettled()
3579
3580 self.assertEqual(len(self.launcher.builds), 1)
3581
3582 self.log.debug('Current builds:')
3583 self.log.debug(self.launcher.builds)
3584
3585 start = time.time()
3586 while True:
3587 if time.time() - start > 10:
3588 raise Exception("Timeout waiting for gearman server to report "
3589 + "back to the client")
3590 build = self.launcher.builds.values()[0]
3591 if build.worker.name == "My Worker":
3592 break
3593 else:
3594 time.sleep(0)
3595
3596 self.log.debug(build)
3597 self.assertEqual("My Worker", build.worker.name)
3598 self.assertEqual("localhost", build.worker.hostname)
3599 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3600 self.assertEqual("zuul.example.org", build.worker.fqdn)
3601 self.assertEqual("FakeBuilder", build.worker.program)
3602 self.assertEqual("v1.1", build.worker.version)
3603 self.assertEqual({'something': 'else'}, build.worker.extra)
3604
James E. Blair08d19992016-08-10 15:25:31 -07003605 self.launch_server.hold_jobs_in_build = False
3606 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003607 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003608
James E. Blairec056492016-07-22 09:45:56 -07003609 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003610 def test_footer_message(self):
3611 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003612 self.updateConfigLayout(
3613 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003614 self.sched.reconfigure(self.config)
3615 self.registerJobs()
3616
3617 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003618 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003619 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003620 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003621 self.waitUntilSettled()
3622
3623 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003624 B.addApproval('code-review', 2)
3625 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003626 self.waitUntilSettled()
3627
3628 self.assertEqual(2, len(self.smtp_messages))
3629
3630 failure_body = """\
3631Build failed. For information on how to proceed, see \
3632http://wiki.example.org/Test_Failures
3633
3634- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3635- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3636
3637For CI problems and help debugging, contact ci@example.org"""
3638
3639 success_body = """\
3640Build succeeded.
3641
3642- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3643- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3644
3645For CI problems and help debugging, contact ci@example.org"""
3646
3647 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3648 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003649
James E. Blairec056492016-07-22 09:45:56 -07003650 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003651 def test_merge_failure_reporters(self):
3652 """Check that the config is set up correctly"""
3653
James E. Blairf84026c2015-12-08 16:11:46 -08003654 self.updateConfigLayout(
3655 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003656 self.sched.reconfigure(self.config)
3657 self.registerJobs()
3658
3659 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003660 "Merge Failed.\n\nThis change or one of its cross-repo "
3661 "dependencies was unable to be automatically merged with the "
3662 "current state of its repository. Please rebase the change and "
3663 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003664 self.sched.layout.pipelines['check'].merge_failure_message)
3665 self.assertEqual(
3666 "The merge failed! For more information...",
3667 self.sched.layout.pipelines['gate'].merge_failure_message)
3668
3669 self.assertEqual(
3670 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3671 self.assertEqual(
3672 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3673
3674 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003675 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3676 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003677
3678 self.assertTrue(
3679 (
3680 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003681 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003682 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003683 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003684 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003685 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003686 ) or (
3687 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003688 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003689 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003690 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003691 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003692 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003693 )
3694 )
3695
James E. Blairec056492016-07-22 09:45:56 -07003696 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003697 def test_merge_failure_reports(self):
3698 """Check that when a change fails to merge the correct message is sent
3699 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003700 self.updateConfigLayout(
3701 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003702 self.sched.reconfigure(self.config)
3703 self.registerJobs()
3704
3705 # Check a test failure isn't reported to SMTP
3706 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003707 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003708 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003709 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003710 self.waitUntilSettled()
3711
3712 self.assertEqual(3, len(self.history)) # 3 jobs
3713 self.assertEqual(0, len(self.smtp_messages))
3714
3715 # Check a merge failure is reported to SMTP
3716 # B should be merged, but C will conflict with B
3717 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3718 B.addPatchset(['conflict'])
3719 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3720 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003721 B.addApproval('code-review', 2)
3722 C.addApproval('code-review', 2)
3723 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3724 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003725 self.waitUntilSettled()
3726
3727 self.assertEqual(6, len(self.history)) # A and B jobs
3728 self.assertEqual(1, len(self.smtp_messages))
3729 self.assertEqual('The merge failed! For more information...',
3730 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003731
James E. Blairec056492016-07-22 09:45:56 -07003732 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003733 def test_default_merge_failure_reports(self):
3734 """Check that the default merge failure reports are correct."""
3735
3736 # A should report success, B should report merge failure.
3737 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3738 A.addPatchset(['conflict'])
3739 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3740 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003741 A.addApproval('code-review', 2)
3742 B.addApproval('code-review', 2)
3743 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3744 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003745 self.waitUntilSettled()
3746
3747 self.assertEqual(3, len(self.history)) # A jobs
3748 self.assertEqual(A.reported, 2)
3749 self.assertEqual(B.reported, 2)
3750 self.assertEqual(A.data['status'], 'MERGED')
3751 self.assertEqual(B.data['status'], 'NEW')
3752 self.assertIn('Build succeeded', A.messages[1])
3753 self.assertIn('Merge Failed', B.messages[1])
3754 self.assertIn('automatically merged', B.messages[1])
3755 self.assertNotIn('logs.example.com', B.messages[1])
3756 self.assertNotIn('SKIPPED', B.messages[1])
3757
James E. Blairec056492016-07-22 09:45:56 -07003758 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003759 def test_swift_instructions(self):
3760 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003761 self.updateConfigLayout(
3762 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003763 self.sched.reconfigure(self.config)
3764 self.registerJobs()
3765
James E. Blair08d19992016-08-10 15:25:31 -07003766 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003767 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3768
James E. Blair8b5408c2016-08-08 15:37:46 -07003769 A.addApproval('code-review', 2)
3770 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003771 self.waitUntilSettled()
3772
3773 self.assertEqual(
3774 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3775 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003776 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003777 self.assertEqual(5,
3778 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3779 split('\n')))
3780 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3781
3782 self.assertEqual(
3783 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3784 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003785 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003786 self.assertEqual(5,
3787 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3788 split('\n')))
3789 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3790
3791 self.assertEqual(
3792 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3793 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003794 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003795 self.assertEqual(5,
3796 len(self.builds[1].
3797 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3798 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3799
James E. Blair08d19992016-08-10 15:25:31 -07003800 self.launch_server.hold_jobs_in_build = False
3801 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003802 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003803
James E. Blairec056492016-07-22 09:45:56 -07003804 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003805 def test_client_get_running_jobs(self):
3806 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003807 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003808 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003809 A.addApproval('code-review', 2)
3810 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003811 self.waitUntilSettled()
3812
3813 client = zuul.rpcclient.RPCClient('127.0.0.1',
3814 self.gearman_server.port)
3815
3816 # Wait for gearman server to send the initial workData back to zuul
3817 start = time.time()
3818 while True:
3819 if time.time() - start > 10:
3820 raise Exception("Timeout waiting for gearman server to report "
3821 + "back to the client")
3822 build = self.launcher.builds.values()[0]
3823 if build.worker.name == "My Worker":
3824 break
3825 else:
3826 time.sleep(0)
3827
3828 running_items = client.get_running_jobs()
3829
3830 self.assertEqual(1, len(running_items))
3831 running_item = running_items[0]
3832 self.assertEqual([], running_item['failing_reasons'])
3833 self.assertEqual([], running_item['items_behind'])
3834 self.assertEqual('https://hostname/1', running_item['url'])
3835 self.assertEqual(None, running_item['item_ahead'])
3836 self.assertEqual('org/project', running_item['project'])
3837 self.assertEqual(None, running_item['remaining_time'])
3838 self.assertEqual(True, running_item['active'])
3839 self.assertEqual('1,1', running_item['id'])
3840
3841 self.assertEqual(3, len(running_item['jobs']))
3842 for job in running_item['jobs']:
3843 if job['name'] == 'project-merge':
3844 self.assertEqual('project-merge', job['name'])
3845 self.assertEqual('gate', job['pipeline'])
3846 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003847 self.assertEqual('https://server/job/project-merge/0/',
3848 job['url'])
3849 self.assertEqual(7, len(job['worker']))
3850 self.assertEqual(False, job['canceled'])
3851 self.assertEqual(True, job['voting'])
3852 self.assertEqual(None, job['result'])
3853 self.assertEqual('gate', job['pipeline'])
3854 break
3855
James E. Blair08d19992016-08-10 15:25:31 -07003856 self.launch_server.hold_jobs_in_build = False
3857 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003858 self.waitUntilSettled()
3859
3860 running_items = client.get_running_jobs()
3861 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003862
3863 def test_nonvoting_pipeline(self):
3864 "Test that a nonvoting pipeline (experimental) can still report"
3865
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003866 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3867 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003868 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3869 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003870
3871 self.assertEqual(self.getJobFromHistory('project-merge').result,
3872 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003873 self.assertEqual(
3874 self.getJobFromHistory('experimental-project-test').result,
3875 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003876 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003877
James E. Blairec056492016-07-22 09:45:56 -07003878 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003879 def test_crd_gate(self):
3880 "Test cross-repo dependencies"
3881 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3882 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003883 A.addApproval('code-review', 2)
3884 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003885
3886 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3887 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3888 AM2.setMerged()
3889 AM1.setMerged()
3890
3891 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3892 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3893 BM2.setMerged()
3894 BM1.setMerged()
3895
3896 # A -> AM1 -> AM2
3897 # B -> BM1 -> BM2
3898 # A Depends-On: B
3899 # M2 is here to make sure it is never queried. If it is, it
3900 # means zuul is walking down the entire history of merged
3901 # changes.
3902
3903 B.setDependsOn(BM1, 1)
3904 BM1.setDependsOn(BM2, 1)
3905
3906 A.setDependsOn(AM1, 1)
3907 AM1.setDependsOn(AM2, 1)
3908
3909 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3910 A.subject, B.data['id'])
3911
James E. Blair8b5408c2016-08-08 15:37:46 -07003912 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003913 self.waitUntilSettled()
3914
3915 self.assertEqual(A.data['status'], 'NEW')
3916 self.assertEqual(B.data['status'], 'NEW')
3917
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003918 for connection in self.connections.values():
3919 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003920
James E. Blair08d19992016-08-10 15:25:31 -07003921 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003922 B.addApproval('approved', 1)
3923 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003924 self.waitUntilSettled()
3925
James E. Blair08d19992016-08-10 15:25:31 -07003926 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003927 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003928 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003929 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003930 self.launch_server.hold_jobs_in_build = False
3931 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003932 self.waitUntilSettled()
3933
3934 self.assertEqual(AM2.queried, 0)
3935 self.assertEqual(BM2.queried, 0)
3936 self.assertEqual(A.data['status'], 'MERGED')
3937 self.assertEqual(B.data['status'], 'MERGED')
3938 self.assertEqual(A.reported, 2)
3939 self.assertEqual(B.reported, 2)
3940
James E. Blair8f78d882015-02-05 08:51:37 -08003941 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3942 '2,1 1,1')
3943
James E. Blairec056492016-07-22 09:45:56 -07003944 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003945 def test_crd_branch(self):
3946 "Test cross-repo dependencies in multiple branches"
3947 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3948 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3949 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3950 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003951 A.addApproval('code-review', 2)
3952 B.addApproval('code-review', 2)
3953 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003954
3955 # A Depends-On: B+C
3956 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3957 A.subject, B.data['id'])
3958
James E. Blair08d19992016-08-10 15:25:31 -07003959 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003960 B.addApproval('approved', 1)
3961 C.addApproval('approved', 1)
3962 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003963 self.waitUntilSettled()
3964
James E. Blair08d19992016-08-10 15:25:31 -07003965 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003966 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003967 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003968 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003969 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003970 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003971 self.launch_server.hold_jobs_in_build = False
3972 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003973 self.waitUntilSettled()
3974
3975 self.assertEqual(A.data['status'], 'MERGED')
3976 self.assertEqual(B.data['status'], 'MERGED')
3977 self.assertEqual(C.data['status'], 'MERGED')
3978 self.assertEqual(A.reported, 2)
3979 self.assertEqual(B.reported, 2)
3980 self.assertEqual(C.reported, 2)
3981
3982 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3983 '2,1 3,1 1,1')
3984
James E. Blairec056492016-07-22 09:45:56 -07003985 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003986 def test_crd_multiline(self):
3987 "Test multiple depends-on lines in commit"
3988 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3989 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3990 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003991 A.addApproval('code-review', 2)
3992 B.addApproval('code-review', 2)
3993 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003994
3995 # A Depends-On: B+C
3996 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
3997 A.subject, B.data['id'], C.data['id'])
3998
James E. Blair08d19992016-08-10 15:25:31 -07003999 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004000 B.addApproval('approved', 1)
4001 C.addApproval('approved', 1)
4002 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004003 self.waitUntilSettled()
4004
James E. Blair08d19992016-08-10 15:25:31 -07004005 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004006 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004007 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004008 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004009 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004010 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004011 self.launch_server.hold_jobs_in_build = False
4012 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004013 self.waitUntilSettled()
4014
4015 self.assertEqual(A.data['status'], 'MERGED')
4016 self.assertEqual(B.data['status'], 'MERGED')
4017 self.assertEqual(C.data['status'], 'MERGED')
4018 self.assertEqual(A.reported, 2)
4019 self.assertEqual(B.reported, 2)
4020 self.assertEqual(C.reported, 2)
4021
4022 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4023 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004024
James E. Blairec056492016-07-22 09:45:56 -07004025 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004026 def test_crd_unshared_gate(self):
4027 "Test cross-repo dependencies in unshared gate queues"
4028 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4029 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004030 A.addApproval('code-review', 2)
4031 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004032
4033 # A Depends-On: B
4034 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4035 A.subject, B.data['id'])
4036
4037 # A and B do not share a queue, make sure that A is unable to
4038 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004039 B.addApproval('approved', 1)
4040 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004041 self.waitUntilSettled()
4042
4043 self.assertEqual(A.data['status'], 'NEW')
4044 self.assertEqual(B.data['status'], 'NEW')
4045 self.assertEqual(A.reported, 0)
4046 self.assertEqual(B.reported, 0)
4047 self.assertEqual(len(self.history), 0)
4048
4049 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004050 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004051 self.waitUntilSettled()
4052
4053 self.assertEqual(B.data['status'], 'MERGED')
4054 self.assertEqual(B.reported, 2)
4055
4056 # Now that B is merged, A should be able to be enqueued and
4057 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004058 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004059 self.waitUntilSettled()
4060
4061 self.assertEqual(A.data['status'], 'MERGED')
4062 self.assertEqual(A.reported, 2)
4063
James E. Blairec056492016-07-22 09:45:56 -07004064 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004065 def test_crd_gate_reverse(self):
4066 "Test reverse cross-repo dependencies"
4067 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4068 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004069 A.addApproval('code-review', 2)
4070 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004071
4072 # A Depends-On: B
4073
4074 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4075 A.subject, B.data['id'])
4076
James E. Blair8b5408c2016-08-08 15:37:46 -07004077 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004078 self.waitUntilSettled()
4079
4080 self.assertEqual(A.data['status'], 'NEW')
4081 self.assertEqual(B.data['status'], 'NEW')
4082
James E. Blair08d19992016-08-10 15:25:31 -07004083 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004084 A.addApproval('approved', 1)
4085 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004086 self.waitUntilSettled()
4087
James E. Blair08d19992016-08-10 15:25:31 -07004088 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004089 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004090 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004091 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004092 self.launch_server.hold_jobs_in_build = False
4093 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004094 self.waitUntilSettled()
4095
4096 self.assertEqual(A.data['status'], 'MERGED')
4097 self.assertEqual(B.data['status'], 'MERGED')
4098 self.assertEqual(A.reported, 2)
4099 self.assertEqual(B.reported, 2)
4100
4101 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4102 '2,1 1,1')
4103
James E. Blairec056492016-07-22 09:45:56 -07004104 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004105 def test_crd_cycle(self):
4106 "Test cross-repo dependency cycles"
4107 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4108 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004109 A.addApproval('code-review', 2)
4110 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004111
4112 # A -> B -> A (via commit-depends)
4113
4114 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4115 A.subject, B.data['id'])
4116 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4117 B.subject, A.data['id'])
4118
James E. Blair8b5408c2016-08-08 15:37:46 -07004119 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004120 self.waitUntilSettled()
4121
4122 self.assertEqual(A.reported, 0)
4123 self.assertEqual(B.reported, 0)
4124 self.assertEqual(A.data['status'], 'NEW')
4125 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004126
James E. Blairec056492016-07-22 09:45:56 -07004127 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004128 def test_crd_gate_unknown(self):
4129 "Test unknown projects in dependent pipeline"
4130 self.init_repo("org/unknown")
4131 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4132 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004133 A.addApproval('code-review', 2)
4134 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004135
4136 # A Depends-On: B
4137 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4138 A.subject, B.data['id'])
4139
James E. Blair8b5408c2016-08-08 15:37:46 -07004140 B.addApproval('approved', 1)
4141 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004142 self.waitUntilSettled()
4143
4144 # Unknown projects cannot share a queue with any other
4145 # since they don't have common jobs with any other (they have no jobs).
4146 # Changes which depend on unknown project changes
4147 # should not be processed in dependent pipeline
4148 self.assertEqual(A.data['status'], 'NEW')
4149 self.assertEqual(B.data['status'], 'NEW')
4150 self.assertEqual(A.reported, 0)
4151 self.assertEqual(B.reported, 0)
4152 self.assertEqual(len(self.history), 0)
4153
4154 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004155 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004156 B.setMerged()
4157 self.waitUntilSettled()
4158 self.assertEqual(len(self.history), 0)
4159
4160 # Now that B is merged, A should be able to be enqueued and
4161 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004162 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004163 self.waitUntilSettled()
4164
4165 self.assertEqual(A.data['status'], 'MERGED')
4166 self.assertEqual(A.reported, 2)
4167 self.assertEqual(B.data['status'], 'MERGED')
4168 self.assertEqual(B.reported, 0)
4169
James E. Blairec056492016-07-22 09:45:56 -07004170 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004171 def test_crd_check(self):
4172 "Test cross-repo dependencies in independent pipelines"
4173
4174 self.gearman_server.hold_jobs_in_queue = True
4175 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4176 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4177
4178 # A Depends-On: B
4179 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4180 A.subject, B.data['id'])
4181
4182 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4183 self.waitUntilSettled()
4184
4185 queue = self.gearman_server.getQueue()
4186 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4187 self.gearman_server.hold_jobs_in_queue = False
4188 self.gearman_server.release()
4189 self.waitUntilSettled()
4190
4191 path = os.path.join(self.git_root, "org/project1")
4192 repo = git.Repo(path)
4193 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4194 repo_messages.reverse()
4195 correct_messages = ['initial commit', 'A-1']
4196 self.assertEqual(repo_messages, correct_messages)
4197
4198 path = os.path.join(self.git_root, "org/project2")
4199 repo = git.Repo(path)
4200 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4201 repo_messages.reverse()
4202 correct_messages = ['initial commit', 'B-1']
4203 self.assertEqual(repo_messages, correct_messages)
4204
4205 self.assertEqual(A.data['status'], 'NEW')
4206 self.assertEqual(B.data['status'], 'NEW')
4207 self.assertEqual(A.reported, 1)
4208 self.assertEqual(B.reported, 0)
4209
4210 self.assertEqual(self.history[0].changes, '2,1 1,1')
4211 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004212
James E. Blairec056492016-07-22 09:45:56 -07004213 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004214 def test_crd_check_git_depends(self):
4215 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004216 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004217 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4218 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4219
4220 # Add two git-dependent changes and make sure they both report
4221 # success.
4222 B.setDependsOn(A, 1)
4223 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4224 self.waitUntilSettled()
4225 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4226 self.waitUntilSettled()
4227
James E. Blairb8c16472015-05-05 14:55:26 -07004228 self.orderedRelease()
4229 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004230 self.waitUntilSettled()
4231
4232 self.assertEqual(A.data['status'], 'NEW')
4233 self.assertEqual(B.data['status'], 'NEW')
4234 self.assertEqual(A.reported, 1)
4235 self.assertEqual(B.reported, 1)
4236
4237 self.assertEqual(self.history[0].changes, '1,1')
4238 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4239 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4240
4241 self.assertIn('Build succeeded', A.messages[0])
4242 self.assertIn('Build succeeded', B.messages[0])
4243
James E. Blairec056492016-07-22 09:45:56 -07004244 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004245 def test_crd_check_duplicate(self):
4246 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004247 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004248 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4249 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4250 check_pipeline = self.sched.layout.pipelines['check']
4251
4252 # Add two git-dependent changes...
4253 B.setDependsOn(A, 1)
4254 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4255 self.waitUntilSettled()
4256 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4257
4258 # ...make sure the live one is not duplicated...
4259 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4260 self.waitUntilSettled()
4261 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4262
4263 # ...but the non-live one is able to be.
4264 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4265 self.waitUntilSettled()
4266 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4267
Clark Boylandd849822015-03-02 12:38:14 -08004268 # Release jobs in order to avoid races with change A jobs
4269 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004270 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004271 self.launch_server.hold_jobs_in_build = False
4272 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004273 self.waitUntilSettled()
4274
4275 self.assertEqual(A.data['status'], 'NEW')
4276 self.assertEqual(B.data['status'], 'NEW')
4277 self.assertEqual(A.reported, 1)
4278 self.assertEqual(B.reported, 1)
4279
4280 self.assertEqual(self.history[0].changes, '1,1 2,1')
4281 self.assertEqual(self.history[1].changes, '1,1')
4282 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4283
4284 self.assertIn('Build succeeded', A.messages[0])
4285 self.assertIn('Build succeeded', B.messages[0])
4286
James E. Blairec056492016-07-22 09:45:56 -07004287 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004288 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004289 "Test cross-repo dependencies re-enqueued in independent pipelines"
4290
4291 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004292 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4293 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004294
4295 # A Depends-On: B
4296 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4297 A.subject, B.data['id'])
4298
4299 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4300 self.waitUntilSettled()
4301
4302 self.sched.reconfigure(self.config)
4303
4304 # Make sure the items still share a change queue, and the
4305 # first one is not live.
4306 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4307 queue = self.sched.layout.pipelines['check'].queues[0]
4308 first_item = queue.queue[0]
4309 for item in queue.queue:
4310 self.assertEqual(item.queue, first_item.queue)
4311 self.assertFalse(first_item.live)
4312 self.assertTrue(queue.queue[1].live)
4313
4314 self.gearman_server.hold_jobs_in_queue = False
4315 self.gearman_server.release()
4316 self.waitUntilSettled()
4317
4318 self.assertEqual(A.data['status'], 'NEW')
4319 self.assertEqual(B.data['status'], 'NEW')
4320 self.assertEqual(A.reported, 1)
4321 self.assertEqual(B.reported, 0)
4322
4323 self.assertEqual(self.history[0].changes, '2,1 1,1')
4324 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004325
James E. Blairec056492016-07-22 09:45:56 -07004326 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004327 def test_crd_check_reconfiguration(self):
4328 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4329
James E. Blairec056492016-07-22 09:45:56 -07004330 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004331 def test_crd_undefined_project(self):
4332 """Test that undefined projects in dependencies are handled for
4333 independent pipelines"""
4334 # It's a hack for fake gerrit,
4335 # as it implies repo creation upon the creation of any change
4336 self.init_repo("org/unknown")
4337 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4338
James E. Blairec056492016-07-22 09:45:56 -07004339 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004340 def test_crd_check_ignore_dependencies(self):
4341 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004342 self.updateConfigLayout(
4343 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004344 self.sched.reconfigure(self.config)
4345 self.registerJobs()
4346
4347 self.gearman_server.hold_jobs_in_queue = True
4348 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4349 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4350 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4351
4352 # A Depends-On: B
4353 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4354 A.subject, B.data['id'])
4355 # C git-depends on B
4356 C.setDependsOn(B, 1)
4357 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4358 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4359 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4360 self.waitUntilSettled()
4361
4362 # Make sure none of the items share a change queue, and all
4363 # are live.
4364 check_pipeline = self.sched.layout.pipelines['check']
4365 self.assertEqual(len(check_pipeline.queues), 3)
4366 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4367 for item in check_pipeline.getAllItems():
4368 self.assertTrue(item.live)
4369
4370 self.gearman_server.hold_jobs_in_queue = False
4371 self.gearman_server.release()
4372 self.waitUntilSettled()
4373
4374 self.assertEqual(A.data['status'], 'NEW')
4375 self.assertEqual(B.data['status'], 'NEW')
4376 self.assertEqual(C.data['status'], 'NEW')
4377 self.assertEqual(A.reported, 1)
4378 self.assertEqual(B.reported, 1)
4379 self.assertEqual(C.reported, 1)
4380
4381 # Each job should have tested exactly one change
4382 for job in self.history:
4383 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004384
James E. Blairec056492016-07-22 09:45:56 -07004385 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004386 def test_crd_check_transitive(self):
4387 "Test transitive cross-repo dependencies"
4388 # Specifically, if A -> B -> C, and C gets a new patchset and
4389 # A gets a new patchset, ensure the test of A,2 includes B,1
4390 # and C,2 (not C,1 which would indicate stale data in the
4391 # cache for B).
4392 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4393 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4394 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4395
4396 # A Depends-On: B
4397 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4398 A.subject, B.data['id'])
4399
4400 # B Depends-On: C
4401 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4402 B.subject, C.data['id'])
4403
4404 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4405 self.waitUntilSettled()
4406 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4407
4408 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4409 self.waitUntilSettled()
4410 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4411
4412 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4413 self.waitUntilSettled()
4414 self.assertEqual(self.history[-1].changes, '3,1')
4415
4416 C.addPatchset()
4417 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4418 self.waitUntilSettled()
4419 self.assertEqual(self.history[-1].changes, '3,2')
4420
4421 A.addPatchset()
4422 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4423 self.waitUntilSettled()
4424 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004425
James E. Blairec056492016-07-22 09:45:56 -07004426 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004427 def test_crd_check_unknown(self):
4428 "Test unknown projects in independent pipeline"
4429 self.init_repo("org/unknown")
4430 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4431 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4432 # A Depends-On: B
4433 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4434 A.subject, B.data['id'])
4435
4436 # Make sure zuul has seen an event on B.
4437 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4438 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4439 self.waitUntilSettled()
4440
4441 self.assertEqual(A.data['status'], 'NEW')
4442 self.assertEqual(A.reported, 1)
4443 self.assertEqual(B.data['status'], 'NEW')
4444 self.assertEqual(B.reported, 0)
4445
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004446 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004447 def test_crd_cycle_join(self):
4448 "Test an updated change creates a cycle"
4449 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4450
4451 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4452 self.waitUntilSettled()
4453
4454 # Create B->A
4455 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4456 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4457 B.subject, A.data['id'])
4458 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4459 self.waitUntilSettled()
4460
4461 # Update A to add A->B (a cycle).
4462 A.addPatchset()
4463 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4464 A.subject, B.data['id'])
4465 # Normally we would submit the patchset-created event for
4466 # processing here, however, we have no way of noting whether
4467 # the dependency cycle detection correctly raised an
4468 # exception, so instead, we reach into the source driver and
4469 # call the method that would ultimately be called by the event
4470 # processing.
4471
4472 source = self.sched.layout.pipelines['gate'].source
4473 with testtools.ExpectedException(
4474 Exception, "Dependency cycle detected"):
4475 source._getChange(u'1', u'2', True)
4476 self.log.debug("Got expected dependency cycle exception")
4477
4478 # Now if we update B to remove the depends-on, everything
4479 # should be okay. B; A->B
4480
4481 B.addPatchset()
4482 B.data['commitMessage'] = '%s\n' % (B.subject,)
4483 source._getChange(u'1', u'2', True)
4484 source._getChange(u'2', u'2', True)
4485
James E. Blairec056492016-07-22 09:45:56 -07004486 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004487 def test_disable_at(self):
4488 "Test a pipeline will only report to the disabled trigger when failing"
4489
James E. Blairf84026c2015-12-08 16:11:46 -08004490 self.updateConfigLayout(
4491 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004492 self.sched.reconfigure(self.config)
4493
4494 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4495 self.assertEqual(
4496 0, self.sched.layout.pipelines['check']._consecutive_failures)
4497 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4498
4499 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4500 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4501 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4502 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4503 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4504 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4505 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4506 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4507 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4508 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4509 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4510
James E. Blair08d19992016-08-10 15:25:31 -07004511 self.launch_server.failJob('project-test1', A)
4512 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004513 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004514 self.launch_server.failJob('project-test1', D)
4515 self.launch_server.failJob('project-test1', E)
4516 self.launch_server.failJob('project-test1', F)
4517 self.launch_server.failJob('project-test1', G)
4518 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004519 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004520 self.launch_server.failJob('project-test1', J)
4521 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004522
4523 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4524 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4525 self.waitUntilSettled()
4526
4527 self.assertEqual(
4528 2, self.sched.layout.pipelines['check']._consecutive_failures)
4529 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4530
4531 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4532 self.waitUntilSettled()
4533
4534 self.assertEqual(
4535 0, self.sched.layout.pipelines['check']._consecutive_failures)
4536 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4537
4538 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4539 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4540 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4541 self.waitUntilSettled()
4542
4543 # We should be disabled now
4544 self.assertEqual(
4545 3, self.sched.layout.pipelines['check']._consecutive_failures)
4546 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4547
4548 # We need to wait between each of these patches to make sure the
4549 # smtp messages come back in an expected order
4550 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4551 self.waitUntilSettled()
4552 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4553 self.waitUntilSettled()
4554 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4555 self.waitUntilSettled()
4556
4557 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4558 # leaving a message on each change
4559 self.assertEqual(1, len(A.messages))
4560 self.assertIn('Build failed.', A.messages[0])
4561 self.assertEqual(1, len(B.messages))
4562 self.assertIn('Build failed.', B.messages[0])
4563 self.assertEqual(1, len(C.messages))
4564 self.assertIn('Build succeeded.', C.messages[0])
4565 self.assertEqual(1, len(D.messages))
4566 self.assertIn('Build failed.', D.messages[0])
4567 self.assertEqual(1, len(E.messages))
4568 self.assertIn('Build failed.', E.messages[0])
4569 self.assertEqual(1, len(F.messages))
4570 self.assertIn('Build failed.', F.messages[0])
4571
4572 # The last 3 (GHI) would have only reported via smtp.
4573 self.assertEqual(3, len(self.smtp_messages))
4574 self.assertEqual(0, len(G.messages))
4575 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4576 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4577 self.assertEqual(0, len(H.messages))
4578 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4579 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4580 self.assertEqual(0, len(I.messages))
4581 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4582 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4583
4584 # Now reload the configuration (simulate a HUP) to check the pipeline
4585 # comes out of disabled
4586 self.sched.reconfigure(self.config)
4587
4588 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4589 self.assertEqual(
4590 0, self.sched.layout.pipelines['check']._consecutive_failures)
4591 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4592
4593 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4594 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4595 self.waitUntilSettled()
4596
4597 self.assertEqual(
4598 2, self.sched.layout.pipelines['check']._consecutive_failures)
4599 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4600
4601 # J and K went back to gerrit
4602 self.assertEqual(1, len(J.messages))
4603 self.assertIn('Build failed.', J.messages[0])
4604 self.assertEqual(1, len(K.messages))
4605 self.assertIn('Build failed.', K.messages[0])
4606 # No more messages reported via smtp
4607 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004608
James E. Blairec056492016-07-22 09:45:56 -07004609 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004610 def test_success_pattern(self):
4611 "Ensure bad build params are ignored"
4612
4613 # Use SMTP reporter to grab the result message easier
4614 self.init_repo("org/docs")
4615 self.config.set('zuul', 'layout_config',
4616 'tests/fixtures/layout-success-pattern.yaml')
4617 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004618 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004619 self.registerJobs()
4620
4621 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4622 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4623 self.waitUntilSettled()
4624
4625 # Grab build id
4626 self.assertEqual(len(self.builds), 1)
4627 uuid = self.builds[0].unique[:7]
4628
James E. Blair08d19992016-08-10 15:25:31 -07004629 self.launch_server.hold_jobs_in_build = False
4630 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004631 self.waitUntilSettled()
4632
4633 self.assertEqual(len(self.smtp_messages), 1)
4634 body = self.smtp_messages[0]['body'].splitlines()
4635 self.assertEqual('Build succeeded.', body[0])
4636
4637 self.assertIn(
4638 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4639 'docs-draft-test/%s/publish-docs/' % uuid,
4640 body[2])
4641 self.assertIn(
4642 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4643 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004644
4645
4646class TestDuplicatePipeline(ZuulTestCase):
4647 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4648
4649 def test_duplicate_pipelines(self):
4650 "Test that a change matching multiple pipelines works"
4651
4652 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4653 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4654 self.waitUntilSettled()
4655
4656 self.assertHistory([
4657 dict(name='project-test1', result='SUCCESS', changes='1,1',
4658 pipeline='dup1'),
4659 dict(name='project-test1', result='SUCCESS', changes='1,1',
4660 pipeline='dup2'),
4661 ])
4662
4663 self.assertEqual(len(A.messages), 2)
4664
4665 self.assertIn('dup1', A.messages[0])
4666 self.assertNotIn('dup2', A.messages[0])
4667 self.assertIn('project-test1', A.messages[0])
4668
4669 self.assertIn('dup2', A.messages[1])
4670 self.assertNotIn('dup1', A.messages[1])
4671 self.assertIn('project-test1', A.messages[1])