blob: 134763835de9aba48ecca3b3036dd3437e3cd7cb [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
Paul Belanger9bba4902016-11-02 16:07:33 -040035import zuul.model
James E. Blairb0fcae42012-07-17 11:12:10 -070036
Maru Newby3fe5f852015-01-13 04:22:14 +000037from tests.base import (
Maru Newby3fe5f852015-01-13 04:22:14 +000038 ZuulTestCase,
39 repack_repo,
40)
James E. Blairb0fcae42012-07-17 11:12:10 -070041
James E. Blair1f4c2bb2013-04-26 08:40:46 -070042logging.basicConfig(level=logging.DEBUG,
43 format='%(asctime)s %(name)-32s '
44 '%(levelname)-8s %(message)s')
James E. Blairb0fcae42012-07-17 11:12:10 -070045
46
Clark Boylanb640e052014-04-03 16:41:46 -070047class TestScheduler(ZuulTestCase):
James E. Blair552b54f2016-07-22 13:55:32 -070048 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobd86a312014-01-08 14:51:33 +010049
James E. Blairb0fcae42012-07-17 11:12:10 -070050 def test_jobs_launched(self):
51 "Test that jobs are launched and a change is merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -070052
James E. Blairb0fcae42012-07-17 11:12:10 -070053 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -070054 A.addApproval('code-review', 2)
55 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -070056 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -040057 self.assertEqual(self.getJobFromHistory('project-merge').result,
58 'SUCCESS')
59 self.assertEqual(self.getJobFromHistory('project-test1').result,
60 'SUCCESS')
61 self.assertEqual(self.getJobFromHistory('project-test2').result,
62 'SUCCESS')
63 self.assertEqual(A.data['status'], 'MERGED')
64 self.assertEqual(A.reported, 2)
James E. Blair34776ee2016-08-25 13:53:54 -070065 self.assertEqual(self.getJobFromHistory('project-test1').node,
66 'image1')
James E. Blairb0fcae42012-07-17 11:12:10 -070067
James E. Blair552b54f2016-07-22 13:55:32 -070068 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070069 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
70 self.assertReportedStat('zuul.pipeline.gate.current_changes',
71 value='1|g')
72 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
73 kind='ms')
74 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
75 value='1|c')
76 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
77 self.assertReportedStat('zuul.pipeline.gate.total_changes',
78 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070079 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070080 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
James E. Blair412e5582013-04-22 15:50:12 -070081 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070082 'zuul.pipeline.gate.org.project.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070083
James E. Blair5821bd92015-09-16 08:48:15 -070084 for build in self.builds:
85 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
86
James E. Blair3cb10702013-08-24 08:56:03 -070087 def test_initial_pipeline_gauges(self):
88 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070089 self.assertReportedStat('zuul.pipeline.gate.current_changes',
90 value='0|g')
91 self.assertReportedStat('zuul.pipeline.check.current_changes',
92 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070093
James E. Blair34776ee2016-08-25 13:53:54 -070094 def test_job_branch(self):
95 "Test the correct variant of a job runs on a branch"
96 self.create_branch('org/project', 'stable')
97 A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A')
98 A.addApproval('code-review', 2)
99 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
100 self.waitUntilSettled()
101 self.assertEqual(self.getJobFromHistory('project-test1').result,
102 'SUCCESS')
103 self.assertEqual(self.getJobFromHistory('project-test2').result,
104 'SUCCESS')
105 self.assertEqual(A.data['status'], 'MERGED')
106 self.assertEqual(A.reported, 2,
107 "A should report start and success")
108 self.assertIn('gate', A.messages[1],
109 "A should transit gate")
110 self.assertEqual(self.getJobFromHistory('project-test1').node,
111 'image2')
112
James E. Blairb0fcae42012-07-17 11:12:10 -0700113 def test_parallel_changes(self):
114 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700115
James E. Blair791b5392016-08-03 11:25:56 -0700116 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700117 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
118 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
119 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700120 A.addApproval('code-review', 2)
121 B.addApproval('code-review', 2)
122 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700123
James E. Blair8b5408c2016-08-08 15:37:46 -0700124 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
125 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
126 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700127
128 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400129 self.assertEqual(len(self.builds), 1)
130 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700131 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700132
James E. Blair791b5392016-08-03 11:25:56 -0700133 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700134 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400135 self.assertEqual(len(self.builds), 3)
136 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700137 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400138 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700139 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400140 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700141 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700142
James E. Blair791b5392016-08-03 11:25:56 -0700143 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700144 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400145 self.assertEqual(len(self.builds), 5)
146 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700147 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400148 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700149 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700150
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400151 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700152 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400153 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700154 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700155
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400156 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700157 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700158
James E. Blair791b5392016-08-03 11:25:56 -0700159 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700160 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400161 self.assertEqual(len(self.builds), 6)
162 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700163 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400164 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700165 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700166
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400167 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700168 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400169 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700170 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700171
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400172 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700173 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400174 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700175 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700176
James E. Blair791b5392016-08-03 11:25:56 -0700177 self.launch_server.hold_jobs_in_build = False
178 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700179 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400180 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700181
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400182 self.assertEqual(len(self.history), 9)
183 self.assertEqual(A.data['status'], 'MERGED')
184 self.assertEqual(B.data['status'], 'MERGED')
185 self.assertEqual(C.data['status'], 'MERGED')
186 self.assertEqual(A.reported, 2)
187 self.assertEqual(B.reported, 2)
188 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700189
190 def test_failed_changes(self):
191 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700192 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700193
James E. Blairb02a3bb2012-07-30 17:49:55 -0700194 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
195 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700196 A.addApproval('code-review', 2)
197 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700198
James E. Blair08d19992016-08-10 15:25:31 -0700199 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700200
James E. Blair8b5408c2016-08-08 15:37:46 -0700201 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
202 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700203 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700204 self.assertBuilds([dict(name='project-merge', changes='1,1')])
James E. Blaire2819012013-06-28 17:17:26 -0400205
James E. Blair08d19992016-08-10 15:25:31 -0700206 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400207 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700208 # A/project-merge is complete
209 self.assertBuilds([
210 dict(name='project-test1', changes='1,1'),
211 dict(name='project-test2', changes='1,1'),
212 dict(name='project-merge', changes='1,1 2,1'),
213 ])
James E. Blaire2819012013-06-28 17:17:26 -0400214
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700215 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400216 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700217 # A/project-merge is complete
218 # B/project-merge is complete
219 self.assertBuilds([
220 dict(name='project-test1', changes='1,1'),
221 dict(name='project-test2', changes='1,1'),
222 dict(name='project-test1', changes='1,1 2,1'),
223 dict(name='project-test2', changes='1,1 2,1'),
224 ])
225
226 # Release project-test1 for A which will fail. This will
227 # abort both running B jobs and relaunch project-merge for B.
228 self.builds[0].release()
229 self.waitUntilSettled()
230
231 self.orderedRelease()
232 self.assertHistory([
233 dict(name='project-merge', result='SUCCESS', changes='1,1'),
234 dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'),
235 dict(name='project-test1', result='FAILURE', changes='1,1'),
236 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
237 dict(name='project-test2', result='ABORTED', changes='1,1 2,1'),
238 dict(name='project-test2', result='SUCCESS', changes='1,1'),
239 dict(name='project-merge', result='SUCCESS', changes='2,1'),
240 dict(name='project-test1', result='SUCCESS', changes='2,1'),
241 dict(name='project-test2', result='SUCCESS', changes='2,1'),
James E. Blairb536ecc2016-08-31 10:11:42 -0700242 ], ordered=False)
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700243
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400244 self.assertEqual(A.data['status'], 'NEW')
245 self.assertEqual(B.data['status'], 'MERGED')
246 self.assertEqual(A.reported, 2)
247 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700248
249 def test_independent_queues(self):
250 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700251
James E. Blair08d19992016-08-10 15:25:31 -0700252 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900253 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700254 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
255 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700256 A.addApproval('code-review', 2)
257 B.addApproval('code-review', 2)
258 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700259
James E. Blair8b5408c2016-08-08 15:37:46 -0700260 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
261 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
262 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700263
James E. Blairb02a3bb2012-07-30 17:49:55 -0700264 self.waitUntilSettled()
265
266 # There should be one merge job at the head of each queue running
James E. Blair5f0d49e2016-08-19 09:36:50 -0700267 self.assertBuilds([
268 dict(name='project-merge', changes='1,1'),
269 dict(name='project-merge', changes='2,1'),
270 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700271
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700272 # Release the current merge builds
James E. Blair5f0d49e2016-08-19 09:36:50 -0700273 self.builds[0].release()
274 self.waitUntilSettled()
275 self.builds[0].release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700276 self.waitUntilSettled()
277 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700278 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700279 self.waitUntilSettled()
280
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700281 # All the test builds should be running:
James E. Blair5f0d49e2016-08-19 09:36:50 -0700282 self.assertBuilds([
283 dict(name='project-test1', changes='1,1'),
284 dict(name='project-test2', changes='1,1'),
285 dict(name='project-test1', changes='2,1'),
286 dict(name='project-test2', changes='2,1'),
287 dict(name='project-test1', changes='2,1 3,1'),
288 dict(name='project-test2', changes='2,1 3,1'),
289 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700290
James E. Blair5f0d49e2016-08-19 09:36:50 -0700291 self.orderedRelease()
292 self.assertHistory([
293 dict(name='project-merge', result='SUCCESS', changes='1,1'),
294 dict(name='project-merge', result='SUCCESS', changes='2,1'),
295 dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'),
296 dict(name='project-test1', result='SUCCESS', changes='1,1'),
297 dict(name='project-test2', result='SUCCESS', changes='1,1'),
298 dict(name='project-test1', result='SUCCESS', changes='2,1'),
299 dict(name='project-test2', result='SUCCESS', changes='2,1'),
300 dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'),
301 dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'),
302 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700303
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400304 self.assertEqual(A.data['status'], 'MERGED')
305 self.assertEqual(B.data['status'], 'MERGED')
306 self.assertEqual(C.data['status'], 'MERGED')
307 self.assertEqual(A.reported, 2)
308 self.assertEqual(B.reported, 2)
309 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700310
311 def test_failed_change_at_head(self):
312 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700313
James E. Blair08d19992016-08-10 15:25:31 -0700314 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700315 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
316 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
317 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700318 A.addApproval('code-review', 2)
319 B.addApproval('code-review', 2)
320 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700321
James E. Blair08d19992016-08-10 15:25:31 -0700322 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700323
James E. Blair8b5408c2016-08-08 15:37:46 -0700324 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
325 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
326 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700327
328 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700329
James E. Blairb536ecc2016-08-31 10:11:42 -0700330 self.assertBuilds([
331 dict(name='project-merge', changes='1,1'),
332 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700333
James E. Blair08d19992016-08-10 15:25:31 -0700334 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700335 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700336 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700337 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700338 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700339 self.waitUntilSettled()
340
James E. Blairb536ecc2016-08-31 10:11:42 -0700341 self.assertBuilds([
342 dict(name='project-test1', changes='1,1'),
343 dict(name='project-test2', changes='1,1'),
344 dict(name='project-test1', changes='1,1 2,1'),
345 dict(name='project-test2', changes='1,1 2,1'),
346 dict(name='project-test1', changes='1,1 2,1 3,1'),
347 dict(name='project-test2', changes='1,1 2,1 3,1'),
348 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700349
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400350 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700351 self.waitUntilSettled()
352
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400353 # project-test2, project-merge for B
James E. Blairb536ecc2016-08-31 10:11:42 -0700354 self.assertBuilds([
355 dict(name='project-test2', changes='1,1'),
356 dict(name='project-merge', changes='2,1'),
357 ])
358 # Unordered history comparison because the aborts can finish
359 # in any order.
360 self.assertHistory([
361 dict(name='project-merge', result='SUCCESS',
362 changes='1,1'),
363 dict(name='project-merge', result='SUCCESS',
364 changes='1,1 2,1'),
365 dict(name='project-merge', result='SUCCESS',
366 changes='1,1 2,1 3,1'),
367 dict(name='project-test1', result='FAILURE',
368 changes='1,1'),
369 dict(name='project-test1', result='ABORTED',
370 changes='1,1 2,1'),
371 dict(name='project-test2', result='ABORTED',
372 changes='1,1 2,1'),
373 dict(name='project-test1', result='ABORTED',
374 changes='1,1 2,1 3,1'),
375 dict(name='project-test2', result='ABORTED',
376 changes='1,1 2,1 3,1'),
377 ], ordered=False)
James E. Blaird466dc42012-07-31 10:42:56 -0700378
James E. Blairb536ecc2016-08-31 10:11:42 -0700379 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700380 self.waitUntilSettled()
James E. Blairb536ecc2016-08-31 10:11:42 -0700381 self.launch_server.release('.*-merge')
382 self.waitUntilSettled()
383 self.orderedRelease()
James E. Blaird466dc42012-07-31 10:42:56 -0700384
James E. Blairb536ecc2016-08-31 10:11:42 -0700385 self.assertBuilds([])
386 self.assertHistory([
387 dict(name='project-merge', result='SUCCESS',
388 changes='1,1'),
389 dict(name='project-merge', result='SUCCESS',
390 changes='1,1 2,1'),
391 dict(name='project-merge', result='SUCCESS',
392 changes='1,1 2,1 3,1'),
393 dict(name='project-test1', result='FAILURE',
394 changes='1,1'),
395 dict(name='project-test1', result='ABORTED',
396 changes='1,1 2,1'),
397 dict(name='project-test2', result='ABORTED',
398 changes='1,1 2,1'),
399 dict(name='project-test1', result='ABORTED',
400 changes='1,1 2,1 3,1'),
401 dict(name='project-test2', result='ABORTED',
402 changes='1,1 2,1 3,1'),
403 dict(name='project-merge', result='SUCCESS',
404 changes='2,1'),
405 dict(name='project-merge', result='SUCCESS',
406 changes='2,1 3,1'),
407 dict(name='project-test2', result='SUCCESS',
408 changes='1,1'),
409 dict(name='project-test1', result='SUCCESS',
410 changes='2,1'),
411 dict(name='project-test2', result='SUCCESS',
412 changes='2,1'),
413 dict(name='project-test1', result='SUCCESS',
414 changes='2,1 3,1'),
415 dict(name='project-test2', result='SUCCESS',
416 changes='2,1 3,1'),
417 ], ordered=False)
418
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400419 self.assertEqual(A.data['status'], 'NEW')
420 self.assertEqual(B.data['status'], 'MERGED')
421 self.assertEqual(C.data['status'], 'MERGED')
422 self.assertEqual(A.reported, 2)
423 self.assertEqual(B.reported, 2)
424 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700425
James E. Blair0aac4872013-08-23 14:02:38 -0700426 def test_failed_change_in_middle(self):
427 "Test a failed change in the middle of the queue"
428
James E. Blair08d19992016-08-10 15:25:31 -0700429 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700430 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
431 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
432 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700433 A.addApproval('code-review', 2)
434 B.addApproval('code-review', 2)
435 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700436
James E. Blair08d19992016-08-10 15:25:31 -0700437 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700438
James E. Blair8b5408c2016-08-08 15:37:46 -0700439 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
440 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
441 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700442
443 self.waitUntilSettled()
444
James E. Blair08d19992016-08-10 15:25:31 -0700445 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700446 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700447 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700448 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700449 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700450 self.waitUntilSettled()
451
452 self.assertEqual(len(self.builds), 6)
453 self.assertEqual(self.builds[0].name, 'project-test1')
454 self.assertEqual(self.builds[1].name, 'project-test2')
455 self.assertEqual(self.builds[2].name, 'project-test1')
456 self.assertEqual(self.builds[3].name, 'project-test2')
457 self.assertEqual(self.builds[4].name, 'project-test1')
458 self.assertEqual(self.builds[5].name, 'project-test2')
459
460 self.release(self.builds[2])
461 self.waitUntilSettled()
462
James E. Blair972e3c72013-08-29 12:04:55 -0700463 # project-test1 and project-test2 for A
464 # project-test2 for B
465 # project-merge for C (without B)
466 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700467 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
468
James E. Blair08d19992016-08-10 15:25:31 -0700469 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700470 self.waitUntilSettled()
471
472 # project-test1 and project-test2 for A
473 # project-test2 for B
474 # project-test1 and project-test2 for C
475 self.assertEqual(len(self.builds), 5)
476
Paul Belanger2e2a0492016-10-30 18:33:37 -0400477 tenant = self.sched.abide.tenants.get('tenant-one')
478 items = tenant.layout.pipelines['gate'].getAllItems()
James E. Blair0aac4872013-08-23 14:02:38 -0700479 builds = items[0].current_build_set.getBuilds()
480 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
481 self.assertEqual(self.countJobResults(builds, None), 2)
482 builds = items[1].current_build_set.getBuilds()
483 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
484 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
485 self.assertEqual(self.countJobResults(builds, None), 1)
486 builds = items[2].current_build_set.getBuilds()
487 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700488 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700489
James E. Blair08d19992016-08-10 15:25:31 -0700490 self.launch_server.hold_jobs_in_build = False
491 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700492 self.waitUntilSettled()
493
494 self.assertEqual(len(self.builds), 0)
495 self.assertEqual(len(self.history), 12)
496 self.assertEqual(A.data['status'], 'MERGED')
497 self.assertEqual(B.data['status'], 'NEW')
498 self.assertEqual(C.data['status'], 'MERGED')
499 self.assertEqual(A.reported, 2)
500 self.assertEqual(B.reported, 2)
501 self.assertEqual(C.reported, 2)
502
James E. Blairec056492016-07-22 09:45:56 -0700503 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700504 def test_failed_change_at_head_with_queue(self):
505 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700506
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700507 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700508 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
509 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
510 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700511 A.addApproval('code-review', 2)
512 B.addApproval('code-review', 2)
513 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700514
James E. Blair08d19992016-08-10 15:25:31 -0700515 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700516
James E. Blair8b5408c2016-08-08 15:37:46 -0700517 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
518 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
519 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700520
521 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700522 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400523 self.assertEqual(len(self.builds), 0)
524 self.assertEqual(len(queue), 1)
525 self.assertEqual(queue[0].name, 'build:project-merge')
526 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700527
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700528 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700529 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700530 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700531 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700532 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700533 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700534 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700535
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400536 self.assertEqual(len(self.builds), 0)
537 self.assertEqual(len(queue), 6)
538 self.assertEqual(queue[0].name, 'build:project-test1')
539 self.assertEqual(queue[1].name, 'build:project-test2')
540 self.assertEqual(queue[2].name, 'build:project-test1')
541 self.assertEqual(queue[3].name, 'build:project-test2')
542 self.assertEqual(queue[4].name, 'build:project-test1')
543 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700544
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700545 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700546 self.waitUntilSettled()
547
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400548 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700549 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400550 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
551 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700552
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700553 self.gearman_server.hold_jobs_in_queue = False
554 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700555 self.waitUntilSettled()
556
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400557 self.assertEqual(len(self.builds), 0)
558 self.assertEqual(len(self.history), 11)
559 self.assertEqual(A.data['status'], 'NEW')
560 self.assertEqual(B.data['status'], 'MERGED')
561 self.assertEqual(C.data['status'], 'MERGED')
562 self.assertEqual(A.reported, 2)
563 self.assertEqual(B.reported, 2)
564 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700565
James E. Blairec056492016-07-22 09:45:56 -0700566 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700567 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700568 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700569 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700570 A.addApproval('code-review', 2)
571 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700572 self.waitUntilSettled()
573 time.sleep(2)
574
575 data = json.loads(self.sched.formatStatusJSON())
576 found_job = None
577 for pipeline in data['pipelines']:
578 if pipeline['name'] != 'gate':
579 continue
580 for queue in pipeline['change_queues']:
581 for head in queue['heads']:
582 for item in head:
583 for job in item['jobs']:
584 if job['name'] == 'project-merge':
585 found_job = job
586 break
587
588 self.assertIsNotNone(found_job)
589 if iteration == 1:
590 self.assertIsNotNone(found_job['estimated_time'])
591 self.assertIsNone(found_job['remaining_time'])
592 else:
593 self.assertIsNotNone(found_job['estimated_time'])
594 self.assertTrue(found_job['estimated_time'] >= 2)
595 self.assertIsNotNone(found_job['remaining_time'])
596
James E. Blair08d19992016-08-10 15:25:31 -0700597 self.launch_server.hold_jobs_in_build = False
598 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700599 self.waitUntilSettled()
600
James E. Blairec056492016-07-22 09:45:56 -0700601 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700602 def test_time_database(self):
603 "Test the time database"
604
605 self._test_time_database(1)
606 self._test_time_database(2)
607
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
Paul Belanger71dd2fc2016-11-04 19:05:55 -0400642 self.assertTrue(self.builds[0].hasChanges(A))
643 self.assertTrue(self.builds[2].hasChanges(A))
644 self.assertTrue(self.builds[2].hasChanges(B))
645 self.assertTrue(self.builds[4].hasChanges(A))
646 self.assertTrue(self.builds[4].hasChanges(B))
647 self.assertTrue(self.builds[4].hasChanges(C))
James E. Blairfef71632013-09-23 11:15:47 -0700648
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
Paul Belanger71dd2fc2016-11-04 19:05:55 -0400664 self.assertTrue(self.builds[1].hasChanges(A))
665 self.assertTrue(self.builds[2].hasChanges(A))
666 self.assertTrue(self.builds[2].hasChanges(B))
667 self.assertTrue(self.builds[4].hasChanges(A))
668 self.assertFalse(self.builds[4].hasChanges(B))
669 self.assertTrue(self.builds[4].hasChanges(C))
James E. Blairfef71632013-09-23 11:15:47 -0700670
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
Paul Belanger71dd2fc2016-11-04 19:05:55 -0400690 self.assertFalse(self.builds[1].hasChanges(A))
691 self.assertTrue(self.builds[1].hasChanges(B))
692 self.assertFalse(self.builds[1].hasChanges(C))
James E. Blairfef71632013-09-23 11:15:47 -0700693
Paul Belanger71dd2fc2016-11-04 19:05:55 -0400694 self.assertFalse(self.builds[2].hasChanges(A))
James E. Blairfef71632013-09-23 11:15:47 -0700695 # After A failed and B and C restarted, B should be back in
696 # C's tests because it has not failed yet.
Paul Belanger71dd2fc2016-11-04 19:05:55 -0400697 self.assertTrue(self.builds[2].hasChanges(B))
698 self.assertTrue(self.builds[2].hasChanges(C))
James E. Blairfef71632013-09-23 11:15:47 -0700699
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. Blair063672f2015-01-29 13:09:12 -0800788 def test_needed_changes_enqueue(self):
789 "Test that a needed change is enqueued ahead"
790 # A Given a git tree like this, if we enqueue
791 # / \ change C, we should walk up and down the tree
792 # B G and enqueue changes in the order ABCDEFG.
793 # /|\ This is also the order that you would get if
794 # *C E F you enqueued changes in the order ABCDEFG, so
795 # / the ordering is stable across re-enqueue events.
796 # D
797
798 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
799 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
800 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
801 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
802 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
803 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
804 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
805 B.setDependsOn(A, 1)
806 C.setDependsOn(B, 1)
807 D.setDependsOn(C, 1)
808 E.setDependsOn(B, 1)
809 F.setDependsOn(B, 1)
810 G.setDependsOn(A, 1)
811
James E. Blair8b5408c2016-08-08 15:37:46 -0700812 A.addApproval('code-review', 2)
813 B.addApproval('code-review', 2)
814 C.addApproval('code-review', 2)
815 D.addApproval('code-review', 2)
816 E.addApproval('code-review', 2)
817 F.addApproval('code-review', 2)
818 G.addApproval('code-review', 2)
819 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800820
821 self.waitUntilSettled()
822
823 self.assertEqual(A.data['status'], 'NEW')
824 self.assertEqual(B.data['status'], 'NEW')
825 self.assertEqual(C.data['status'], 'NEW')
826 self.assertEqual(D.data['status'], 'NEW')
827 self.assertEqual(E.data['status'], 'NEW')
828 self.assertEqual(F.data['status'], 'NEW')
829 self.assertEqual(G.data['status'], 'NEW')
830
831 # We're about to add approvals to changes without adding the
832 # triggering events to Zuul, so that we can be sure that it is
833 # enqueing the changes based on dependencies, not because of
834 # triggering events. Since it will have the changes cached
835 # already (without approvals), we need to clear the cache
836 # first.
Paul Belanger593480a2016-11-02 19:06:28 -0400837 for connection in self.connections.connections.values():
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100838 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800839
James E. Blair08d19992016-08-10 15:25:31 -0700840 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700841 A.addApproval('approved', 1)
842 B.addApproval('approved', 1)
843 D.addApproval('approved', 1)
844 E.addApproval('approved', 1)
845 F.addApproval('approved', 1)
846 G.addApproval('approved', 1)
847 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800848
849 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700850 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800851 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700852 self.launch_server.hold_jobs_in_build = False
853 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800854 self.waitUntilSettled()
855
856 self.assertEqual(A.data['status'], 'MERGED')
857 self.assertEqual(B.data['status'], 'MERGED')
858 self.assertEqual(C.data['status'], 'MERGED')
859 self.assertEqual(D.data['status'], 'MERGED')
860 self.assertEqual(E.data['status'], 'MERGED')
861 self.assertEqual(F.data['status'], 'MERGED')
862 self.assertEqual(G.data['status'], 'MERGED')
863 self.assertEqual(A.reported, 2)
864 self.assertEqual(B.reported, 2)
865 self.assertEqual(C.reported, 2)
866 self.assertEqual(D.reported, 2)
867 self.assertEqual(E.reported, 2)
868 self.assertEqual(F.reported, 2)
869 self.assertEqual(G.reported, 2)
870 self.assertEqual(self.history[6].changes,
871 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
872
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100873 def test_source_cache(self):
874 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700875 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700876
877 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
878 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
879 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700880 A.addApproval('code-review', 2)
881 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700882
883 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
884 M1.setMerged()
885
886 B.setDependsOn(A, 1)
887 A.setDependsOn(M1, 1)
888
James E. Blair8b5408c2016-08-08 15:37:46 -0700889 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700890 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
891
892 self.waitUntilSettled()
893
894 for build in self.builds:
895 if build.parameters['ZUUL_PIPELINE'] == 'check':
896 build.release()
897 self.waitUntilSettled()
898 for build in self.builds:
899 if build.parameters['ZUUL_PIPELINE'] == 'check':
900 build.release()
901 self.waitUntilSettled()
902
James E. Blair8b5408c2016-08-08 15:37:46 -0700903 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700904 self.waitUntilSettled()
905
Joshua Hesketh352264b2015-08-11 23:42:08 +1000906 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700907 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000908 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700909
James E. Blair08d19992016-08-10 15:25:31 -0700910 self.launch_server.hold_jobs_in_build = False
911 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700912 self.waitUntilSettled()
913
914 self.assertEqual(A.data['status'], 'MERGED')
915 self.assertEqual(B.data['status'], 'MERGED')
916 self.assertEqual(A.queried, 2) # Initial and isMerged
917 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
918
James E. Blair8c803f82012-07-31 16:25:42 -0700919 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700920 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700921 # TODO: move to test_gerrit (this is a unit test!)
922 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Paul Belanger9bba4902016-11-02 16:07:33 -0400923 tenant = self.sched.abide.tenants.get('tenant-one')
924 source = tenant.layout.pipelines['gate'].source
925
926 # TODO(pabelanger): As we add more source / trigger APIs we should make
927 # it easier for users to create events for testing.
928 event = zuul.model.TriggerEvent()
929 event.trigger_name = 'gerrit'
930 event.change_number = '1'
931 event.patch_number = '2'
932
933 a = source.getChange(event)
934 mgr = tenant.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700935 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700936
James E. Blair8b5408c2016-08-08 15:37:46 -0700937 A.addApproval('code-review', 2)
Paul Belanger9bba4902016-11-02 16:07:33 -0400938 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700939 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700940
James E. Blair8b5408c2016-08-08 15:37:46 -0700941 A.addApproval('approved', 1)
Paul Belanger9bba4902016-11-02 16:07:33 -0400942 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700943 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700944
James E. Blairec056492016-07-22 09:45:56 -0700945 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700946 def test_build_configuration(self):
947 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700948
949 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700950 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
951 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
952 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700953 A.addApproval('code-review', 2)
954 B.addApproval('code-review', 2)
955 C.addApproval('code-review', 2)
956 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
957 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
958 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700959 self.waitUntilSettled()
960
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700961 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700962 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700963 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700964 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700965 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700966 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700967 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700968 ref = self.getParameter(queue[-1], 'ZUUL_REF')
969 self.gearman_server.hold_jobs_in_queue = False
970 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700971 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700972
Monty Taylorbc758832013-06-17 17:22:42 -0400973 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700974 repo = git.Repo(path)
975 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
976 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700977 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400978 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700979
James E. Blairec056492016-07-22 09:45:56 -0700980 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700981 def test_build_configuration_conflict(self):
982 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700983
984 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700985 A = self.fake_gerrit.addFakeChange('org/conflict-project',
986 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700987 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700988 B = self.fake_gerrit.addFakeChange('org/conflict-project',
989 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700990 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700991 C = self.fake_gerrit.addFakeChange('org/conflict-project',
992 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700993 A.addApproval('code-review', 2)
994 B.addApproval('code-review', 2)
995 C.addApproval('code-review', 2)
996 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
997 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
998 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -0700999 self.waitUntilSettled()
1000
James E. Blair6736beb2013-07-11 15:18:15 -07001001 self.assertEqual(A.reported, 1)
1002 self.assertEqual(B.reported, 1)
1003 self.assertEqual(C.reported, 1)
1004
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001005 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001006 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001007 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001008 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001009 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001010 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001011
1012 self.assertEqual(len(self.history), 2) # A and C merge jobs
1013
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001014 self.gearman_server.hold_jobs_in_queue = False
1015 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001016 self.waitUntilSettled()
1017
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001018 self.assertEqual(A.data['status'], 'MERGED')
1019 self.assertEqual(B.data['status'], 'NEW')
1020 self.assertEqual(C.data['status'], 'MERGED')
1021 self.assertEqual(A.reported, 2)
1022 self.assertEqual(B.reported, 2)
1023 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001024 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001025
James E. Blairec056492016-07-22 09:45:56 -07001026 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001027 def test_post(self):
1028 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001029
Zhongyue Luo5d556072012-09-21 02:00:47 +09001030 e = {
1031 "type": "ref-updated",
1032 "submitter": {
1033 "name": "User Name",
1034 },
1035 "refUpdate": {
1036 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1037 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1038 "refName": "master",
1039 "project": "org/project",
1040 }
1041 }
James E. Blairdaabed22012-08-15 15:38:57 -07001042 self.fake_gerrit.addEvent(e)
1043 self.waitUntilSettled()
1044
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001045 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001046 self.assertEqual(len(self.history), 1)
1047 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001048
James E. Blairec056492016-07-22 09:45:56 -07001049 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001050 def test_post_ignore_deletes(self):
1051 "Test that deleting refs does not trigger post jobs"
1052
1053 e = {
1054 "type": "ref-updated",
1055 "submitter": {
1056 "name": "User Name",
1057 },
1058 "refUpdate": {
1059 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1060 "newRev": "0000000000000000000000000000000000000000",
1061 "refName": "master",
1062 "project": "org/project",
1063 }
1064 }
1065 self.fake_gerrit.addEvent(e)
1066 self.waitUntilSettled()
1067
1068 job_names = [x.name for x in self.history]
1069 self.assertEqual(len(self.history), 0)
1070 self.assertNotIn('project-post', job_names)
1071
James E. Blairec056492016-07-22 09:45:56 -07001072 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001073 def test_post_ignore_deletes_negative(self):
1074 "Test that deleting refs does trigger post jobs"
1075
James E. Blairf84026c2015-12-08 16:11:46 -08001076 self.updateConfigLayout(
1077 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001078 self.sched.reconfigure(self.config)
1079
1080 e = {
1081 "type": "ref-updated",
1082 "submitter": {
1083 "name": "User Name",
1084 },
1085 "refUpdate": {
1086 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1087 "newRev": "0000000000000000000000000000000000000000",
1088 "refName": "master",
1089 "project": "org/project",
1090 }
1091 }
1092 self.fake_gerrit.addEvent(e)
1093 self.waitUntilSettled()
1094
1095 job_names = [x.name for x in self.history]
1096 self.assertEqual(len(self.history), 1)
1097 self.assertIn('project-post', job_names)
1098
James E. Blairec056492016-07-22 09:45:56 -07001099 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001100 def test_build_configuration_branch(self):
1101 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001102
1103 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001104 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1105 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1106 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001107 A.addApproval('code-review', 2)
1108 B.addApproval('code-review', 2)
1109 C.addApproval('code-review', 2)
1110 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1111 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1112 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001113 self.waitUntilSettled()
1114
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001115 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001116 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001117 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001118 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001119 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001120 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001121 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001122 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1123 self.gearman_server.hold_jobs_in_queue = False
1124 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001125 self.waitUntilSettled()
1126
Monty Taylorbc758832013-06-17 17:22:42 -04001127 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001128 repo = git.Repo(path)
1129 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1130 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001131 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001132 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001133
James E. Blairec056492016-07-22 09:45:56 -07001134 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001135 def test_build_configuration_branch_interaction(self):
1136 "Test that switching between branches works"
1137 self.test_build_configuration()
1138 self.test_build_configuration_branch()
1139 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001140 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001141 repo = git.Repo(path)
1142 repo.heads.master.commit = repo.commit('init')
1143 self.test_build_configuration()
1144
James E. Blairec056492016-07-22 09:45:56 -07001145 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001146 def test_build_configuration_multi_branch(self):
1147 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001148
1149 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001150 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1151 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1152 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001153 A.addApproval('code-review', 2)
1154 B.addApproval('code-review', 2)
1155 C.addApproval('code-review', 2)
1156 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1157 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1158 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001159 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001160 queue = self.gearman_server.getQueue()
1161 job_A = None
1162 for job in queue:
1163 if 'project-merge' in job.name:
1164 job_A = job
1165 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1166 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1167 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1168 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001169
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001170 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001171 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001172 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001173 job_B = None
1174 for job in queue:
1175 if 'project-merge' in job.name:
1176 job_B = job
1177 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001178 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001179 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001180 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1181
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001182 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001183 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001184 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001185 for job in queue:
1186 if 'project-merge' in job.name:
1187 job_C = job
1188 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001189 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001190 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001191 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001192 self.gearman_server.hold_jobs_in_queue = False
1193 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001194 self.waitUntilSettled()
1195
Monty Taylorbc758832013-06-17 17:22:42 -04001196 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001197 repo = git.Repo(path)
1198
1199 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001200 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001201 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001202 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001203 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001204 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001205 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001206 # Ensure ZUUL_REF -> ZUUL_COMMIT
1207 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001208
1209 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001210 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001211 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001212 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001213 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001214 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001215 self.assertEqual(repo_shas[0], commit_B)
1216
1217 repo_messages = [c.message.strip()
1218 for c in repo.iter_commits(ref_A)]
1219 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1220 repo_messages.reverse()
1221 correct_messages = ['initial commit', 'A-1']
1222 self.assertEqual(repo_messages, correct_messages)
1223 self.assertEqual(repo_shas[0], commit_A)
1224
1225 self.assertNotEqual(ref_A, ref_B, ref_C)
1226 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001227
James E. Blaircaec0c52012-08-22 14:52:22 -07001228 def test_dependent_changes_dequeue(self):
1229 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001230
James E. Blaircaec0c52012-08-22 14:52:22 -07001231 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1232 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1233 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001234 A.addApproval('code-review', 2)
1235 B.addApproval('code-review', 2)
1236 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001237
1238 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1239 M1.setMerged()
1240
1241 # C -> B -> A -> M1
1242
1243 C.setDependsOn(B, 1)
1244 B.setDependsOn(A, 1)
1245 A.setDependsOn(M1, 1)
1246
James E. Blair08d19992016-08-10 15:25:31 -07001247 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001248
James E. Blair8b5408c2016-08-08 15:37:46 -07001249 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1250 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1251 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001252
1253 self.waitUntilSettled()
1254
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001255 self.assertEqual(A.data['status'], 'NEW')
1256 self.assertEqual(A.reported, 2)
1257 self.assertEqual(B.data['status'], 'NEW')
1258 self.assertEqual(B.reported, 2)
1259 self.assertEqual(C.data['status'], 'NEW')
1260 self.assertEqual(C.reported, 2)
1261 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001262
James E. Blair972e3c72013-08-29 12:04:55 -07001263 def test_failing_dependent_changes(self):
1264 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001265 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001266 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1267 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1268 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1269 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1270 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001271 A.addApproval('code-review', 2)
1272 B.addApproval('code-review', 2)
1273 C.addApproval('code-review', 2)
1274 D.addApproval('code-review', 2)
1275 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001276
1277 # E, D -> C -> B, A
1278
1279 D.setDependsOn(C, 1)
1280 C.setDependsOn(B, 1)
1281
James E. Blair08d19992016-08-10 15:25:31 -07001282 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001283
James E. Blair8b5408c2016-08-08 15:37:46 -07001284 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1285 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1286 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1287 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1288 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001289
1290 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001291 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001292 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001293 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001294 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001295 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001296 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001297 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001298 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001299 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001300 self.waitUntilSettled()
1301
James E. Blair08d19992016-08-10 15:25:31 -07001302 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001303 for build in self.builds:
1304 if build.parameters['ZUUL_CHANGE'] != '1':
1305 build.release()
1306 self.waitUntilSettled()
1307
James E. Blair08d19992016-08-10 15:25:31 -07001308 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001309 self.waitUntilSettled()
1310
1311 self.assertEqual(A.data['status'], 'MERGED')
1312 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001313 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001314 self.assertEqual(B.data['status'], 'NEW')
1315 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001316 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001317 self.assertEqual(C.data['status'], 'NEW')
1318 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001319 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001320 self.assertEqual(D.data['status'], 'NEW')
1321 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001322 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001323 self.assertEqual(E.data['status'], 'MERGED')
1324 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001325 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001326 self.assertEqual(len(self.history), 18)
1327
James E. Blairec056492016-07-22 09:45:56 -07001328 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001329 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001330 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001331 # If it's dequeued more than once, we should see extra
1332 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001333
James E. Blair08d19992016-08-10 15:25:31 -07001334 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001335 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1336 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1337 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001338 A.addApproval('code-review', 2)
1339 B.addApproval('code-review', 2)
1340 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001341
James E. Blair08d19992016-08-10 15:25:31 -07001342 self.launch_server.failJob('project1-test1', A)
1343 self.launch_server.failJob('project1-test2', A)
1344 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001345
James E. Blair8b5408c2016-08-08 15:37:46 -07001346 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1347 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1348 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001349
1350 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001351
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001352 self.assertEqual(len(self.builds), 1)
1353 self.assertEqual(self.builds[0].name, 'project1-merge')
1354 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001355
James E. Blair08d19992016-08-10 15:25:31 -07001356 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001357 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001358 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001359 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001360 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001361 self.waitUntilSettled()
1362
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001363 self.assertEqual(len(self.builds), 9)
1364 self.assertEqual(self.builds[0].name, 'project1-test1')
1365 self.assertEqual(self.builds[1].name, 'project1-test2')
1366 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1367 self.assertEqual(self.builds[3].name, 'project1-test1')
1368 self.assertEqual(self.builds[4].name, 'project1-test2')
1369 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1370 self.assertEqual(self.builds[6].name, 'project1-test1')
1371 self.assertEqual(self.builds[7].name, 'project1-test2')
1372 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001373
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001374 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001375 self.waitUntilSettled()
1376
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001377 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1378 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001379
James E. Blair08d19992016-08-10 15:25:31 -07001380 self.launch_server.hold_jobs_in_build = False
1381 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001382 self.waitUntilSettled()
1383
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001384 self.assertEqual(len(self.builds), 0)
1385 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001386
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001387 self.assertEqual(A.data['status'], 'NEW')
1388 self.assertEqual(B.data['status'], 'MERGED')
1389 self.assertEqual(C.data['status'], 'MERGED')
1390 self.assertEqual(A.reported, 2)
1391 self.assertEqual(B.reported, 2)
1392 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001393
James E. Blairec056492016-07-22 09:45:56 -07001394 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001395 def test_nonvoting_job(self):
1396 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001397
James E. Blair4ec821f2012-08-23 15:28:28 -07001398 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1399 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001400 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001401 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001402 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001403
1404 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001405
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001406 self.assertEqual(A.data['status'], 'MERGED')
1407 self.assertEqual(A.reported, 2)
1408 self.assertEqual(
1409 self.getJobFromHistory('nonvoting-project-merge').result,
1410 'SUCCESS')
1411 self.assertEqual(
1412 self.getJobFromHistory('nonvoting-project-test1').result,
1413 'SUCCESS')
1414 self.assertEqual(
1415 self.getJobFromHistory('nonvoting-project-test2').result,
1416 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001417
James E. Blair5821bd92015-09-16 08:48:15 -07001418 for build in self.builds:
1419 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1420
James E. Blaire0487072012-08-29 17:38:31 -07001421 def test_check_queue_success(self):
1422 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001423
James E. Blaire0487072012-08-29 17:38:31 -07001424 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1425 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1426
1427 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001428
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001429 self.assertEqual(A.data['status'], 'NEW')
1430 self.assertEqual(A.reported, 1)
1431 self.assertEqual(self.getJobFromHistory('project-merge').result,
1432 'SUCCESS')
1433 self.assertEqual(self.getJobFromHistory('project-test1').result,
1434 'SUCCESS')
1435 self.assertEqual(self.getJobFromHistory('project-test2').result,
1436 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001437
1438 def test_check_queue_failure(self):
1439 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001440
James E. Blaire0487072012-08-29 17:38:31 -07001441 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001442 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001443 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1444
1445 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001446
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001447 self.assertEqual(A.data['status'], 'NEW')
1448 self.assertEqual(A.reported, 1)
1449 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001450 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001451 self.assertEqual(self.getJobFromHistory('project-test1').result,
1452 'SUCCESS')
1453 self.assertEqual(self.getJobFromHistory('project-test2').result,
1454 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001455
James E. Blairec056492016-07-22 09:45:56 -07001456 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001457 def test_dependent_behind_dequeue(self):
1458 "test that dependent changes behind dequeued changes work"
1459 # This complicated test is a reproduction of a real life bug
1460 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001461
James E. Blair08d19992016-08-10 15:25:31 -07001462 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001463 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1464 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1465 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1466 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1467 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1468 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1469 D.setDependsOn(C, 1)
1470 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001471 A.addApproval('code-review', 2)
1472 B.addApproval('code-review', 2)
1473 C.addApproval('code-review', 2)
1474 D.addApproval('code-review', 2)
1475 E.addApproval('code-review', 2)
1476 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001477
1478 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001479
1480 # Change object re-use in the gerrit trigger is hidden if
1481 # changes are added in quick succession; waiting makes it more
1482 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001483 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001484 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001485 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001486 self.waitUntilSettled()
1487
James E. Blair08d19992016-08-10 15:25:31 -07001488 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001489 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001490 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001491 self.waitUntilSettled()
1492
James E. Blair8b5408c2016-08-08 15:37:46 -07001493 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001494 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001495 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001496 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001497 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001498 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001499 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001500 self.waitUntilSettled()
1501
James E. Blair08d19992016-08-10 15:25:31 -07001502 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001503 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001504 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001505 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001506 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001507 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001508 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001509 self.waitUntilSettled()
1510
1511 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001512
1513 # Grab pointers to the jobs we want to release before
1514 # releasing any, because list indexes may change as
1515 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001516 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001517 a.release()
1518 b.release()
1519 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001520 self.waitUntilSettled()
1521
James E. Blair08d19992016-08-10 15:25:31 -07001522 self.launch_server.hold_jobs_in_build = False
1523 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001524 self.waitUntilSettled()
1525
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001526 self.assertEqual(A.data['status'], 'NEW')
1527 self.assertEqual(B.data['status'], 'MERGED')
1528 self.assertEqual(C.data['status'], 'MERGED')
1529 self.assertEqual(D.data['status'], 'MERGED')
1530 self.assertEqual(E.data['status'], 'MERGED')
1531 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001532
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001533 self.assertEqual(A.reported, 2)
1534 self.assertEqual(B.reported, 2)
1535 self.assertEqual(C.reported, 2)
1536 self.assertEqual(D.reported, 2)
1537 self.assertEqual(E.reported, 2)
1538 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001539
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001540 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1541 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001542
James E. Blairec056492016-07-22 09:45:56 -07001543 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001544 def test_merger_repack(self):
1545 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001546
James E. Blair05fed602012-09-07 12:45:24 -07001547 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001548 A.addApproval('code-review', 2)
1549 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001550 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001551 self.assertEqual(self.getJobFromHistory('project-merge').result,
1552 'SUCCESS')
1553 self.assertEqual(self.getJobFromHistory('project-test1').result,
1554 'SUCCESS')
1555 self.assertEqual(self.getJobFromHistory('project-test2').result,
1556 'SUCCESS')
1557 self.assertEqual(A.data['status'], 'MERGED')
1558 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001559 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001560 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001561
Monty Taylorbc758832013-06-17 17:22:42 -04001562 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001563 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001564
1565 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001566 A.addApproval('code-review', 2)
1567 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001568 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001569 self.assertEqual(self.getJobFromHistory('project-merge').result,
1570 'SUCCESS')
1571 self.assertEqual(self.getJobFromHistory('project-test1').result,
1572 'SUCCESS')
1573 self.assertEqual(self.getJobFromHistory('project-test2').result,
1574 'SUCCESS')
1575 self.assertEqual(A.data['status'], 'MERGED')
1576 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001577
James E. Blairec056492016-07-22 09:45:56 -07001578 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001579 def test_merger_repack_large_change(self):
1580 "Test that the merger works with large changes after a repack"
1581 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001582 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001583 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001584 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001585 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001586 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1587 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001588 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001589 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001590 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001591 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001592
James E. Blair8b5408c2016-08-08 15:37:46 -07001593 A.addApproval('code-review', 2)
1594 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001595 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001596 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1597 'SUCCESS')
1598 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1599 'SUCCESS')
1600 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1601 'SUCCESS')
1602 self.assertEqual(A.data['status'], 'MERGED')
1603 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001604
James E. Blairec056492016-07-22 09:45:56 -07001605 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001606 def test_nonexistent_job(self):
1607 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001608 # Set to the state immediately after a restart
1609 self.resetGearmanServer()
1610 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001611
1612 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001613 A.addApproval('code-review', 2)
1614 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001615 # There may be a thread about to report a lost change
1616 while A.reported < 2:
1617 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001618 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001619 self.assertFalse(job_names)
1620 self.assertEqual(A.data['status'], 'NEW')
1621 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001622 self.assertEmptyQueues()
1623
1624 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001625 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001626 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001627 A.addApproval('code-review', 2)
1628 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001629 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001630 self.assertEqual(self.getJobFromHistory('project-merge').result,
1631 'SUCCESS')
1632 self.assertEqual(self.getJobFromHistory('project-test1').result,
1633 'SUCCESS')
1634 self.assertEqual(self.getJobFromHistory('project-test2').result,
1635 'SUCCESS')
1636 self.assertEqual(A.data['status'], 'MERGED')
1637 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001638
James E. Blair2fa50962013-01-30 21:50:41 -08001639 def test_new_patchset_dequeues_old(self):
1640 "Test that a new patchset causes the old to be dequeued"
1641 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001642 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001643 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1644 M.setMerged()
1645
1646 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1647 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1648 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1649 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001650 A.addApproval('code-review', 2)
1651 B.addApproval('code-review', 2)
1652 C.addApproval('code-review', 2)
1653 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001654
1655 C.setDependsOn(B, 1)
1656 B.setDependsOn(A, 1)
1657 A.setDependsOn(M, 1)
1658
James E. Blair8b5408c2016-08-08 15:37:46 -07001659 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1660 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1661 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1662 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001663 self.waitUntilSettled()
1664
1665 B.addPatchset()
1666 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1667 self.waitUntilSettled()
1668
James E. Blair08d19992016-08-10 15:25:31 -07001669 self.launch_server.hold_jobs_in_build = False
1670 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001671 self.waitUntilSettled()
1672
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001673 self.assertEqual(A.data['status'], 'MERGED')
1674 self.assertEqual(A.reported, 2)
1675 self.assertEqual(B.data['status'], 'NEW')
1676 self.assertEqual(B.reported, 2)
1677 self.assertEqual(C.data['status'], 'NEW')
1678 self.assertEqual(C.reported, 2)
1679 self.assertEqual(D.data['status'], 'MERGED')
1680 self.assertEqual(D.reported, 2)
1681 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001682
James E. Blairba437362015-02-07 11:41:52 -08001683 def test_new_patchset_check(self):
1684 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001685
James E. Blair08d19992016-08-10 15:25:31 -07001686 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001687
1688 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001689 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Paul Belanger18e5f632016-11-03 15:24:16 -04001690 tenant = self.sched.abide.tenants.get('tenant-one')
1691 check_pipeline = tenant.layout.pipelines['check']
James E. Blairba437362015-02-07 11:41:52 -08001692
1693 # Add two git-dependent changes
1694 B.setDependsOn(A, 1)
1695 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1696 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001697 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1698 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001699
1700 # A live item, and a non-live/live pair
1701 items = check_pipeline.getAllItems()
1702 self.assertEqual(len(items), 3)
1703
1704 self.assertEqual(items[0].change.number, '1')
1705 self.assertEqual(items[0].change.patchset, '1')
1706 self.assertFalse(items[0].live)
1707
1708 self.assertEqual(items[1].change.number, '2')
1709 self.assertEqual(items[1].change.patchset, '1')
1710 self.assertTrue(items[1].live)
1711
1712 self.assertEqual(items[2].change.number, '1')
1713 self.assertEqual(items[2].change.patchset, '1')
1714 self.assertTrue(items[2].live)
1715
1716 # Add a new patchset to A
1717 A.addPatchset()
1718 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1719 self.waitUntilSettled()
1720
1721 # The live copy of A,1 should be gone, but the non-live and B
1722 # should continue, and we should have a new A,2
1723 items = check_pipeline.getAllItems()
1724 self.assertEqual(len(items), 3)
1725
1726 self.assertEqual(items[0].change.number, '1')
1727 self.assertEqual(items[0].change.patchset, '1')
1728 self.assertFalse(items[0].live)
1729
1730 self.assertEqual(items[1].change.number, '2')
1731 self.assertEqual(items[1].change.patchset, '1')
1732 self.assertTrue(items[1].live)
1733
1734 self.assertEqual(items[2].change.number, '1')
1735 self.assertEqual(items[2].change.patchset, '2')
1736 self.assertTrue(items[2].live)
1737
1738 # Add a new patchset to B
1739 B.addPatchset()
1740 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1741 self.waitUntilSettled()
1742
1743 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1744 # but we should have a new B,2 (still based on A,1)
1745 items = check_pipeline.getAllItems()
1746 self.assertEqual(len(items), 3)
1747
1748 self.assertEqual(items[0].change.number, '1')
1749 self.assertEqual(items[0].change.patchset, '2')
1750 self.assertTrue(items[0].live)
1751
1752 self.assertEqual(items[1].change.number, '1')
1753 self.assertEqual(items[1].change.patchset, '1')
1754 self.assertFalse(items[1].live)
1755
1756 self.assertEqual(items[2].change.number, '2')
1757 self.assertEqual(items[2].change.patchset, '2')
1758 self.assertTrue(items[2].live)
1759
1760 self.builds[0].release()
1761 self.waitUntilSettled()
1762 self.builds[0].release()
1763 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001764 self.launch_server.hold_jobs_in_build = False
1765 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001766 self.waitUntilSettled()
1767
1768 self.assertEqual(A.reported, 1)
1769 self.assertEqual(B.reported, 1)
1770 self.assertEqual(self.history[0].result, 'ABORTED')
1771 self.assertEqual(self.history[0].changes, '1,1')
1772 self.assertEqual(self.history[1].result, 'ABORTED')
1773 self.assertEqual(self.history[1].changes, '1,1 2,1')
1774 self.assertEqual(self.history[2].result, 'SUCCESS')
1775 self.assertEqual(self.history[2].changes, '1,2')
1776 self.assertEqual(self.history[3].result, 'SUCCESS')
1777 self.assertEqual(self.history[3].changes, '1,1 2,2')
1778
1779 def test_abandoned_gate(self):
1780 "Test that an abandoned change is dequeued from gate"
1781
James E. Blair08d19992016-08-10 15:25:31 -07001782 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001783
1784 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001785 A.addApproval('code-review', 2)
1786 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001787 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001788 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1789 self.assertEqual(self.builds[0].name, 'project-merge')
1790
1791 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1792 self.waitUntilSettled()
1793
James E. Blair08d19992016-08-10 15:25:31 -07001794 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001795 self.waitUntilSettled()
1796
Arie5b4048c2016-10-05 16:12:06 +03001797 self.assertBuilds([])
1798 self.assertHistory([
1799 dict(name='project-merge', result='ABORTED', changes='1,1')],
1800 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001801 self.assertEqual(A.reported, 1,
1802 "Abandoned gate change should report only start")
1803
1804 def test_abandoned_check(self):
1805 "Test that an abandoned change is dequeued from check"
1806
James E. Blair08d19992016-08-10 15:25:31 -07001807 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001808
1809 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1810 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Paul Belanger18e5f632016-11-03 15:24:16 -04001811 tenant = self.sched.abide.tenants.get('tenant-one')
1812 check_pipeline = tenant.layout.pipelines['check']
James E. Blairba437362015-02-07 11:41:52 -08001813
1814 # Add two git-dependent changes
1815 B.setDependsOn(A, 1)
1816 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1817 self.waitUntilSettled()
1818 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1819 self.waitUntilSettled()
1820 # A live item, and a non-live/live pair
1821 items = check_pipeline.getAllItems()
1822 self.assertEqual(len(items), 3)
1823
1824 self.assertEqual(items[0].change.number, '1')
1825 self.assertFalse(items[0].live)
1826
1827 self.assertEqual(items[1].change.number, '2')
1828 self.assertTrue(items[1].live)
1829
1830 self.assertEqual(items[2].change.number, '1')
1831 self.assertTrue(items[2].live)
1832
1833 # Abandon A
1834 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1835 self.waitUntilSettled()
1836
1837 # The live copy of A should be gone, but the non-live and B
1838 # should continue
1839 items = check_pipeline.getAllItems()
1840 self.assertEqual(len(items), 2)
1841
1842 self.assertEqual(items[0].change.number, '1')
1843 self.assertFalse(items[0].live)
1844
1845 self.assertEqual(items[1].change.number, '2')
1846 self.assertTrue(items[1].live)
1847
James E. Blair08d19992016-08-10 15:25:31 -07001848 self.launch_server.hold_jobs_in_build = False
1849 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001850 self.waitUntilSettled()
1851
1852 self.assertEqual(len(self.history), 4)
1853 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001854 'Build should have been aborted')
1855 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001856 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001857
James E. Blairec056492016-07-22 09:45:56 -07001858 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001859 def test_abandoned_not_timer(self):
1860 "Test that an abandoned change does not cancel timer jobs"
1861
James E. Blair08d19992016-08-10 15:25:31 -07001862 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001863
1864 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001865 self.updateConfigLayout(
1866 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001867 self.sched.reconfigure(self.config)
1868 self.registerJobs()
1869 # The pipeline triggers every second, so we should have seen
1870 # several by now.
1871 time.sleep(5)
1872 self.waitUntilSettled()
1873 # Stop queuing timer triggered jobs so that the assertions
1874 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001875 self.updateConfigLayout(
1876 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001877 self.sched.reconfigure(self.config)
1878 self.registerJobs()
1879 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1880
1881 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1882 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1883 self.waitUntilSettled()
1884 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1885
1886 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1887 self.waitUntilSettled()
1888
1889 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1890
James E. Blair08d19992016-08-10 15:25:31 -07001891 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001892 self.waitUntilSettled()
1893
Arx Cruzb1b010d2013-10-28 19:49:59 -02001894 def test_zuul_url_return(self):
1895 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001896 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001897 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001898
1899 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001900 A.addApproval('code-review', 2)
1901 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001902 self.waitUntilSettled()
1903
1904 self.assertEqual(len(self.builds), 1)
1905 for build in self.builds:
1906 self.assertTrue('ZUUL_URL' in build.parameters)
1907
James E. Blair08d19992016-08-10 15:25:31 -07001908 self.launch_server.hold_jobs_in_build = False
1909 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001910 self.waitUntilSettled()
1911
James E. Blair2fa50962013-01-30 21:50:41 -08001912 def test_new_patchset_dequeues_old_on_head(self):
1913 "Test that a new patchset causes the old to be dequeued (at head)"
1914 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001915 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001916 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1917 M.setMerged()
1918 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1919 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1920 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1921 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001922 A.addApproval('code-review', 2)
1923 B.addApproval('code-review', 2)
1924 C.addApproval('code-review', 2)
1925 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001926
1927 C.setDependsOn(B, 1)
1928 B.setDependsOn(A, 1)
1929 A.setDependsOn(M, 1)
1930
James E. Blair8b5408c2016-08-08 15:37:46 -07001931 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1932 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1933 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1934 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001935 self.waitUntilSettled()
1936
1937 A.addPatchset()
1938 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1939 self.waitUntilSettled()
1940
James E. Blair08d19992016-08-10 15:25:31 -07001941 self.launch_server.hold_jobs_in_build = False
1942 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001943 self.waitUntilSettled()
1944
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001945 self.assertEqual(A.data['status'], 'NEW')
1946 self.assertEqual(A.reported, 2)
1947 self.assertEqual(B.data['status'], 'NEW')
1948 self.assertEqual(B.reported, 2)
1949 self.assertEqual(C.data['status'], 'NEW')
1950 self.assertEqual(C.reported, 2)
1951 self.assertEqual(D.data['status'], 'MERGED')
1952 self.assertEqual(D.reported, 2)
1953 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08001954
1955 def test_new_patchset_dequeues_old_without_dependents(self):
1956 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07001957 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001958 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1959 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1960 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001961 A.addApproval('code-review', 2)
1962 B.addApproval('code-review', 2)
1963 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001964
James E. Blair8b5408c2016-08-08 15:37:46 -07001965 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1966 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1967 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001968 self.waitUntilSettled()
1969
1970 B.addPatchset()
1971 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1972 self.waitUntilSettled()
1973
James E. Blair08d19992016-08-10 15:25:31 -07001974 self.launch_server.hold_jobs_in_build = False
1975 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001976 self.waitUntilSettled()
1977
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001978 self.assertEqual(A.data['status'], 'MERGED')
1979 self.assertEqual(A.reported, 2)
1980 self.assertEqual(B.data['status'], 'NEW')
1981 self.assertEqual(B.reported, 2)
1982 self.assertEqual(C.data['status'], 'MERGED')
1983 self.assertEqual(C.reported, 2)
1984 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08001985
1986 def test_new_patchset_dequeues_old_independent_queue(self):
1987 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07001988 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001989 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1990 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1991 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1992 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1993 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1994 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
1995 self.waitUntilSettled()
1996
1997 B.addPatchset()
1998 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1999 self.waitUntilSettled()
2000
James E. Blair08d19992016-08-10 15:25:31 -07002001 self.launch_server.hold_jobs_in_build = False
2002 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002003 self.waitUntilSettled()
2004
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002005 self.assertEqual(A.data['status'], 'NEW')
2006 self.assertEqual(A.reported, 1)
2007 self.assertEqual(B.data['status'], 'NEW')
2008 self.assertEqual(B.reported, 1)
2009 self.assertEqual(C.data['status'], 'NEW')
2010 self.assertEqual(C.reported, 1)
2011 self.assertEqual(len(self.history), 10)
2012 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002013
James E. Blairec056492016-07-22 09:45:56 -07002014 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002015 def test_noop_job(self):
2016 "Test that the internal noop job works"
2017 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002018 A.addApproval('code-review', 2)
2019 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002020 self.waitUntilSettled()
2021
2022 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2023 self.assertTrue(self.sched._areAllBuildsComplete())
2024 self.assertEqual(len(self.history), 0)
2025 self.assertEqual(A.data['status'], 'MERGED')
2026 self.assertEqual(A.reported, 2)
2027
James E. Blairec056492016-07-22 09:45:56 -07002028 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002029 def test_no_job_project(self):
2030 "Test that reports with no jobs don't get sent"
2031 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2032 'master', 'A')
2033 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2034 self.waitUntilSettled()
2035
2036 # Change wasn't reported to
2037 self.assertEqual(A.reported, False)
2038
2039 # Check queue is empty afterwards
2040 check_pipeline = self.sched.layout.pipelines['check']
2041 items = check_pipeline.getAllItems()
2042 self.assertEqual(len(items), 0)
2043
2044 self.assertEqual(len(self.history), 0)
2045
James E. Blairec056492016-07-22 09:45:56 -07002046 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002047 def test_zuul_refs(self):
2048 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002049 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002050 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2051 M1.setMerged()
2052 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2053 M2.setMerged()
2054
2055 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2056 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2057 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2058 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002059 A.addApproval('code-review', 2)
2060 B.addApproval('code-review', 2)
2061 C.addApproval('code-review', 2)
2062 D.addApproval('code-review', 2)
2063 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2064 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2065 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2066 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002067
2068 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002069 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002070 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002071 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002072 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002073 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002074 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002075 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002076 self.waitUntilSettled()
2077
James E. Blair7d0dedc2013-02-21 17:26:09 -08002078 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002079 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002080 if x.parameters['ZUUL_CHANGE'] == '3':
2081 a_zref = x.parameters['ZUUL_REF']
2082 if x.parameters['ZUUL_CHANGE'] == '4':
2083 b_zref = x.parameters['ZUUL_REF']
2084 if x.parameters['ZUUL_CHANGE'] == '5':
2085 c_zref = x.parameters['ZUUL_REF']
2086 if x.parameters['ZUUL_CHANGE'] == '6':
2087 d_zref = x.parameters['ZUUL_REF']
2088
2089 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002090 self.assertIsNotNone(a_zref)
2091 self.assertIsNotNone(b_zref)
2092 self.assertIsNotNone(c_zref)
2093 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002094
2095 # And they should all be different
2096 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002097 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002098
2099 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002100 self.assertTrue(self.ref_has_change(a_zref, A))
2101 self.assertFalse(self.ref_has_change(a_zref, B))
2102 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002103
2104 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002105 self.assertTrue(self.ref_has_change(b_zref, A))
2106 self.assertTrue(self.ref_has_change(b_zref, B))
2107 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002108
2109 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002110 self.assertTrue(self.ref_has_change(c_zref, A))
2111 self.assertTrue(self.ref_has_change(c_zref, B))
2112 self.assertTrue(self.ref_has_change(c_zref, C))
2113 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002114
2115 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002116 self.assertTrue(self.ref_has_change(d_zref, A))
2117 self.assertTrue(self.ref_has_change(d_zref, B))
2118 self.assertTrue(self.ref_has_change(d_zref, C))
2119 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002120
James E. Blair08d19992016-08-10 15:25:31 -07002121 self.launch_server.hold_jobs_in_build = False
2122 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002123 self.waitUntilSettled()
2124
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002125 self.assertEqual(A.data['status'], 'MERGED')
2126 self.assertEqual(A.reported, 2)
2127 self.assertEqual(B.data['status'], 'MERGED')
2128 self.assertEqual(B.reported, 2)
2129 self.assertEqual(C.data['status'], 'MERGED')
2130 self.assertEqual(C.reported, 2)
2131 self.assertEqual(D.data['status'], 'MERGED')
2132 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002133
James E. Blairec056492016-07-22 09:45:56 -07002134 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002135 def test_rerun_on_error(self):
2136 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002137 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002138 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002139 A.addApproval('code-review', 2)
2140 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002141 self.waitUntilSettled()
2142
2143 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002144 self.launch_server.hold_jobs_in_build = False
2145 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002146 self.waitUntilSettled()
2147 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2148 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2149
James E. Blair412e5582013-04-22 15:50:12 -07002150 def test_statsd(self):
2151 "Test each of the statsd methods used in the scheduler"
2152 import extras
2153 statsd = extras.try_import('statsd.statsd')
2154 statsd.incr('test-incr')
2155 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002156 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002157 self.assertReportedStat('test-incr', '1|c')
2158 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002159 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002160
James E. Blairec056492016-07-22 09:45:56 -07002161 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002162 def test_stuck_job_cleanup(self):
2163 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002164 # This job won't be registered at startup because it is not in
2165 # the standard layout, but we need it to already be registerd
2166 # for when we reconfigure, as that is when Zuul will attempt
2167 # to run the new job.
2168 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002169 self.gearman_server.hold_jobs_in_queue = True
2170 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002171 A.addApproval('code-review', 2)
2172 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002173 self.waitUntilSettled()
2174 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2175
James E. Blairf84026c2015-12-08 16:11:46 -08002176 self.updateConfigLayout(
2177 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002178 self.sched.reconfigure(self.config)
2179 self.waitUntilSettled()
2180
James E. Blair18c64442014-03-18 10:14:45 -07002181 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002182 self.waitUntilSettled()
2183 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2184 self.assertTrue(self.sched._areAllBuildsComplete())
2185
2186 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002187 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002188 self.assertEqual(self.history[0].result, 'SUCCESS')
2189
James E. Blairec056492016-07-22 09:45:56 -07002190 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002191 def test_file_head(self):
2192 # This is a regression test for an observed bug. A change
2193 # with a file named "HEAD" in the root directory of the repo
2194 # was processed by a merger. It then was unable to reset the
2195 # repo because of:
2196 # GitCommandError: 'git reset --hard HEAD' returned
2197 # with exit code 128
2198 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2199 # and filename
2200 # Use '--' to separate filenames from revisions'
2201
2202 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2203 A.addPatchset(['HEAD'])
2204 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2205
2206 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2207 self.waitUntilSettled()
2208
2209 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2210 self.waitUntilSettled()
2211
2212 self.assertIn('Build succeeded', A.messages[0])
2213 self.assertIn('Build succeeded', B.messages[0])
2214
James E. Blairec056492016-07-22 09:45:56 -07002215 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002216 def test_file_jobs(self):
2217 "Test that file jobs run only when appropriate"
2218 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2219 A.addPatchset(['pip-requires'])
2220 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002221 A.addApproval('code-review', 2)
2222 B.addApproval('code-review', 2)
2223 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2224 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002225 self.waitUntilSettled()
2226
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002227 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002228 if x.name == 'project-testfile']
2229
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002230 self.assertEqual(len(testfile_jobs), 1)
2231 self.assertEqual(testfile_jobs[0].changes, '1,2')
2232 self.assertEqual(A.data['status'], 'MERGED')
2233 self.assertEqual(A.reported, 2)
2234 self.assertEqual(B.data['status'], 'MERGED')
2235 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002236
James E. Blairec056492016-07-22 09:45:56 -07002237 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002238 def _test_skip_if_jobs(self, branch, should_skip):
2239 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002240 self.updateConfigLayout(
2241 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002242 self.sched.reconfigure(self.config)
2243 self.registerJobs()
2244
2245 change = self.fake_gerrit.addFakeChange('org/project',
2246 branch,
2247 'test skip-if')
2248 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2249 self.waitUntilSettled()
2250
2251 tested_change_ids = [x.changes[0] for x in self.history
2252 if x.name == 'project-test-skip-if']
2253
2254 if should_skip:
2255 self.assertEqual([], tested_change_ids)
2256 else:
2257 self.assertIn(change.data['number'], tested_change_ids)
2258
James E. Blairec056492016-07-22 09:45:56 -07002259 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002260 def test_skip_if_match_skips_job(self):
2261 self._test_skip_if_jobs(branch='master', should_skip=True)
2262
James E. Blairec056492016-07-22 09:45:56 -07002263 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002264 def test_skip_if_no_match_runs_job(self):
2265 self._test_skip_if_jobs(branch='mp', should_skip=False)
2266
James E. Blairec056492016-07-22 09:45:56 -07002267 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002268 def test_test_config(self):
2269 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002270 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002271 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002272
James E. Blairec056492016-07-22 09:45:56 -07002273 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002274 def test_queue_names(self):
2275 "Test shared change queue names"
2276 project1 = self.sched.layout.projects['org/project1']
2277 project2 = self.sched.layout.projects['org/project2']
2278 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2279 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2280 self.assertEqual(q1.name, 'integration')
2281 self.assertEqual(q2.name, 'integration')
2282
James E. Blairf84026c2015-12-08 16:11:46 -08002283 self.updateConfigLayout(
2284 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002285 with testtools.ExpectedException(
2286 Exception, "More than one name assigned to change queue"):
2287 self.sched.reconfigure(self.config)
2288
James E. Blairec056492016-07-22 09:45:56 -07002289 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002290 def test_queue_precedence(self):
2291 "Test that queue precedence works"
2292
2293 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002294 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002295 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2296 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002297 A.addApproval('code-review', 2)
2298 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002299
2300 self.waitUntilSettled()
2301 self.gearman_server.hold_jobs_in_queue = False
2302 self.gearman_server.release()
2303 self.waitUntilSettled()
2304
James E. Blair8de58bd2013-07-18 16:23:33 -07002305 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002306 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002307 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002308 self.waitUntilSettled()
2309
James E. Blair64ed6f22013-07-10 14:07:23 -07002310 self.log.debug(self.history)
2311 self.assertEqual(self.history[0].pipeline, 'gate')
2312 self.assertEqual(self.history[1].pipeline, 'check')
2313 self.assertEqual(self.history[2].pipeline, 'gate')
2314 self.assertEqual(self.history[3].pipeline, 'gate')
2315 self.assertEqual(self.history[4].pipeline, 'check')
2316 self.assertEqual(self.history[5].pipeline, 'check')
2317
James E. Blairec056492016-07-22 09:45:56 -07002318 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002319 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002320 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002321 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002322 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002323 A.addApproval('code-review', 2)
2324 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002325 self.waitUntilSettled()
2326
James E. Blair08d19992016-08-10 15:25:31 -07002327 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002328 self.waitUntilSettled()
2329
James E. Blair1843a552013-07-03 14:19:52 -07002330 port = self.webapp.server.socket.getsockname()[1]
2331
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002332 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2333 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002334 headers = f.info()
2335 self.assertIn('Content-Length', headers)
2336 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002337 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2338 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002339 self.assertIn('Access-Control-Allow-Origin', headers)
2340 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002341 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002342 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002343 data = f.read()
2344
James E. Blair08d19992016-08-10 15:25:31 -07002345 self.launch_server.hold_jobs_in_build = False
2346 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002347 self.waitUntilSettled()
2348
2349 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002350 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002351 for p in data['pipelines']:
2352 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002353 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002354 self.assertEqual(q['window'], 20)
2355 else:
2356 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002357 for head in q['heads']:
2358 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002359 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002360 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002361 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002362 status_jobs.append(job)
2363 self.assertEqual('project-merge', status_jobs[0]['name'])
2364 self.assertEqual('https://server/job/project-merge/0/',
2365 status_jobs[0]['url'])
2366 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2367 status_jobs[0]['report_url'])
2368
2369 self.assertEqual('project-test1', status_jobs[1]['name'])
2370 self.assertEqual('https://server/job/project-test1/1/',
2371 status_jobs[1]['url'])
2372 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2373 status_jobs[1]['report_url'])
2374
2375 self.assertEqual('project-test2', status_jobs[2]['name'])
2376 self.assertEqual('https://server/job/project-test2/2/',
2377 status_jobs[2]['url'])
2378 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2379 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002380
James E. Blairec056492016-07-22 09:45:56 -07002381 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002382 def test_merging_queues(self):
2383 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002384 self.updateConfigLayout(
2385 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002386 self.sched.reconfigure(self.config)
2387 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2388
James E. Blairec056492016-07-22 09:45:56 -07002389 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002390 def test_mutex(self):
2391 "Test job mutexes"
2392 self.config.set('zuul', 'layout_config',
2393 'tests/fixtures/layout-mutex.yaml')
2394 self.sched.reconfigure(self.config)
2395
James E. Blair08d19992016-08-10 15:25:31 -07002396 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002397 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2398 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2399 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2400
2401 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2402 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2403 self.waitUntilSettled()
2404 self.assertEqual(len(self.builds), 3)
2405 self.assertEqual(self.builds[0].name, 'project-test1')
2406 self.assertEqual(self.builds[1].name, 'mutex-one')
2407 self.assertEqual(self.builds[2].name, 'project-test1')
2408
James E. Blair08d19992016-08-10 15:25:31 -07002409 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002410 self.waitUntilSettled()
2411
2412 self.assertEqual(len(self.builds), 3)
2413 self.assertEqual(self.builds[0].name, 'project-test1')
2414 self.assertEqual(self.builds[1].name, 'project-test1')
2415 self.assertEqual(self.builds[2].name, 'mutex-two')
2416 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2417
James E. Blair08d19992016-08-10 15:25:31 -07002418 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002419 self.waitUntilSettled()
2420
2421 self.assertEqual(len(self.builds), 3)
2422 self.assertEqual(self.builds[0].name, 'project-test1')
2423 self.assertEqual(self.builds[1].name, 'project-test1')
2424 self.assertEqual(self.builds[2].name, 'mutex-one')
2425 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2426
James E. Blair08d19992016-08-10 15:25:31 -07002427 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002428 self.waitUntilSettled()
2429
2430 self.assertEqual(len(self.builds), 3)
2431 self.assertEqual(self.builds[0].name, 'project-test1')
2432 self.assertEqual(self.builds[1].name, 'project-test1')
2433 self.assertEqual(self.builds[2].name, 'mutex-two')
2434 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2435
James E. Blair08d19992016-08-10 15:25:31 -07002436 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002437 self.waitUntilSettled()
2438
2439 self.assertEqual(len(self.builds), 2)
2440 self.assertEqual(self.builds[0].name, 'project-test1')
2441 self.assertEqual(self.builds[1].name, 'project-test1')
2442 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2443
James E. Blair08d19992016-08-10 15:25:31 -07002444 self.launch_server.hold_jobs_in_build = False
2445 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002446
2447 self.waitUntilSettled()
2448 self.assertEqual(len(self.builds), 0)
2449
2450 self.assertEqual(A.reported, 1)
2451 self.assertEqual(B.reported, 1)
2452 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2453
James E. Blairec056492016-07-22 09:45:56 -07002454 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002455 def test_node_label(self):
2456 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002457 self.worker.registerFunction('build:node-project-test1:debian')
2458
2459 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002460 A.addApproval('code-review', 2)
2461 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002462 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002463
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002464 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2465 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2466 'debian')
2467 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002468
James E. Blairec056492016-07-22 09:45:56 -07002469 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002470 def test_live_reconfiguration(self):
2471 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002472 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002473 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002474 A.addApproval('code-review', 2)
2475 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002476 self.waitUntilSettled()
2477
2478 self.sched.reconfigure(self.config)
2479
James E. Blair08d19992016-08-10 15:25:31 -07002480 self.launch_server.hold_jobs_in_build = False
2481 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002482 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002483 self.assertEqual(self.getJobFromHistory('project-merge').result,
2484 'SUCCESS')
2485 self.assertEqual(self.getJobFromHistory('project-test1').result,
2486 'SUCCESS')
2487 self.assertEqual(self.getJobFromHistory('project-test2').result,
2488 'SUCCESS')
2489 self.assertEqual(A.data['status'], 'MERGED')
2490 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002491
James E. Blairec056492016-07-22 09:45:56 -07002492 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002493 def test_live_reconfiguration_merge_conflict(self):
2494 # A real-world bug: a change in a gate queue has a merge
2495 # conflict and a job is added to its project while it's
2496 # sitting in the queue. The job gets added to the change and
2497 # enqueued and the change gets stuck.
2498 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002499 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002500
2501 # This change is fine. It's here to stop the queue long
2502 # enough for the next change to be subject to the
2503 # reconfiguration, as well as to provide a conflict for the
2504 # next change. This change will succeed and merge.
2505 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2506 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002507 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002508
2509 # This change will be in merge conflict. During the
2510 # reconfiguration, we will add a job. We want to make sure
2511 # that doesn't cause it to get stuck.
2512 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2513 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002514 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002515
James E. Blair8b5408c2016-08-08 15:37:46 -07002516 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2517 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002518
2519 self.waitUntilSettled()
2520
2521 # No jobs have run yet
2522 self.assertEqual(A.data['status'], 'NEW')
2523 self.assertEqual(A.reported, 1)
2524 self.assertEqual(B.data['status'], 'NEW')
2525 self.assertEqual(B.reported, 1)
2526 self.assertEqual(len(self.history), 0)
2527
2528 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002529 self.updateConfigLayout(
2530 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002531 self.sched.reconfigure(self.config)
2532 self.waitUntilSettled()
2533
James E. Blair08d19992016-08-10 15:25:31 -07002534 self.launch_server.hold_jobs_in_build = False
2535 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002536 self.waitUntilSettled()
2537
2538 self.assertEqual(A.data['status'], 'MERGED')
2539 self.assertEqual(A.reported, 2)
2540 self.assertEqual(B.data['status'], 'NEW')
2541 self.assertEqual(B.reported, 2)
2542 self.assertEqual(self.getJobFromHistory('project-merge').result,
2543 'SUCCESS')
2544 self.assertEqual(self.getJobFromHistory('project-test1').result,
2545 'SUCCESS')
2546 self.assertEqual(self.getJobFromHistory('project-test2').result,
2547 'SUCCESS')
2548 self.assertEqual(self.getJobFromHistory('project-test3').result,
2549 'SUCCESS')
2550 self.assertEqual(len(self.history), 4)
2551
James E. Blairec056492016-07-22 09:45:56 -07002552 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002553 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002554 # An extrapolation of test_live_reconfiguration_merge_conflict
2555 # that tests a job added to a job tree with a failed root does
2556 # not run.
2557 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002558 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002559
2560 # This change is fine. It's here to stop the queue long
2561 # enough for the next change to be subject to the
2562 # reconfiguration. This change will succeed and merge.
2563 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2564 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002565 A.addApproval('code-review', 2)
2566 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002567 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002568 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002569 self.waitUntilSettled()
2570
2571 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002572 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002573 B.addApproval('code-review', 2)
2574 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002575 self.waitUntilSettled()
2576
James E. Blair08d19992016-08-10 15:25:31 -07002577 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002578 self.waitUntilSettled()
2579
2580 # Both -merge jobs have run, but no others.
2581 self.assertEqual(A.data['status'], 'NEW')
2582 self.assertEqual(A.reported, 1)
2583 self.assertEqual(B.data['status'], 'NEW')
2584 self.assertEqual(B.reported, 1)
2585 self.assertEqual(self.history[0].result, 'SUCCESS')
2586 self.assertEqual(self.history[0].name, 'project-merge')
2587 self.assertEqual(self.history[1].result, 'FAILURE')
2588 self.assertEqual(self.history[1].name, 'project-merge')
2589 self.assertEqual(len(self.history), 2)
2590
2591 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002592 self.updateConfigLayout(
2593 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002594 self.sched.reconfigure(self.config)
2595 self.waitUntilSettled()
2596
James E. Blair08d19992016-08-10 15:25:31 -07002597 self.launch_server.hold_jobs_in_build = False
2598 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002599 self.waitUntilSettled()
2600
2601 self.assertEqual(A.data['status'], 'MERGED')
2602 self.assertEqual(A.reported, 2)
2603 self.assertEqual(B.data['status'], 'NEW')
2604 self.assertEqual(B.reported, 2)
2605 self.assertEqual(self.history[0].result, 'SUCCESS')
2606 self.assertEqual(self.history[0].name, 'project-merge')
2607 self.assertEqual(self.history[1].result, 'FAILURE')
2608 self.assertEqual(self.history[1].name, 'project-merge')
2609 self.assertEqual(self.history[2].result, 'SUCCESS')
2610 self.assertEqual(self.history[3].result, 'SUCCESS')
2611 self.assertEqual(self.history[4].result, 'SUCCESS')
2612 self.assertEqual(len(self.history), 5)
2613
James E. Blairec056492016-07-22 09:45:56 -07002614 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002615 def test_live_reconfiguration_failed_job(self):
2616 # Test that a change with a removed failing job does not
2617 # disrupt reconfiguration. If a change has a failed job and
2618 # that job is removed during a reconfiguration, we observed a
2619 # bug where the code to re-set build statuses would run on
2620 # that build and raise an exception because the job no longer
2621 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002622 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002623
2624 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2625
2626 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002627 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002628
2629 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2630 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002631 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002632 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002633 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002634 self.waitUntilSettled()
2635
2636 self.assertEqual(A.data['status'], 'NEW')
2637 self.assertEqual(A.reported, 0)
2638
2639 self.assertEqual(self.getJobFromHistory('project-merge').result,
2640 'SUCCESS')
2641 self.assertEqual(self.getJobFromHistory('project-test1').result,
2642 'FAILURE')
2643 self.assertEqual(len(self.history), 2)
2644
2645 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002646 self.updateConfigLayout(
2647 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002648 self.sched.reconfigure(self.config)
2649 self.waitUntilSettled()
2650
James E. Blair08d19992016-08-10 15:25:31 -07002651 self.launch_server.hold_jobs_in_build = False
2652 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002653 self.waitUntilSettled()
2654
2655 self.assertEqual(self.getJobFromHistory('project-test2').result,
2656 'SUCCESS')
2657 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2658 'SUCCESS')
2659 self.assertEqual(len(self.history), 4)
2660
2661 self.assertEqual(A.data['status'], 'NEW')
2662 self.assertEqual(A.reported, 1)
2663 self.assertIn('Build succeeded', A.messages[0])
2664 # Ensure the removed job was not included in the report.
2665 self.assertNotIn('project-test1', A.messages[0])
2666
James E. Blairec056492016-07-22 09:45:56 -07002667 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002668 def test_live_reconfiguration_shared_queue(self):
2669 # Test that a change with a failing job which was removed from
2670 # this project but otherwise still exists in the system does
2671 # not disrupt reconfiguration.
2672
James E. Blair08d19992016-08-10 15:25:31 -07002673 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002674
2675 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2676
James E. Blair08d19992016-08-10 15:25:31 -07002677 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002678
2679 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2680 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002681 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002682 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002683 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002684 self.waitUntilSettled()
2685
2686 self.assertEqual(A.data['status'], 'NEW')
2687 self.assertEqual(A.reported, 0)
2688
2689 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2690 'SUCCESS')
2691 self.assertEqual(self.getJobFromHistory(
2692 'project1-project2-integration').result, 'FAILURE')
2693 self.assertEqual(len(self.history), 2)
2694
2695 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002696 self.updateConfigLayout(
2697 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002698 self.sched.reconfigure(self.config)
2699 self.waitUntilSettled()
2700
James E. Blair08d19992016-08-10 15:25:31 -07002701 self.launch_server.hold_jobs_in_build = False
2702 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002703 self.waitUntilSettled()
2704
2705 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2706 'SUCCESS')
2707 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2708 'SUCCESS')
2709 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2710 'SUCCESS')
2711 self.assertEqual(self.getJobFromHistory(
2712 'project1-project2-integration').result, 'FAILURE')
2713 self.assertEqual(len(self.history), 4)
2714
2715 self.assertEqual(A.data['status'], 'NEW')
2716 self.assertEqual(A.reported, 1)
2717 self.assertIn('Build succeeded', A.messages[0])
2718 # Ensure the removed job was not included in the report.
2719 self.assertNotIn('project1-project2-integration', A.messages[0])
2720
James E. Blairec056492016-07-22 09:45:56 -07002721 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002722 def test_double_live_reconfiguration_shared_queue(self):
2723 # This was a real-world regression. A change is added to
2724 # gate; a reconfigure happens, a second change which depends
2725 # on the first is added, and a second reconfiguration happens.
2726 # Ensure that both changes merge.
2727
2728 # A failure may indicate incorrect caching or cleaning up of
2729 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002730 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002731
2732 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2733 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2734 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002735 A.addApproval('code-review', 2)
2736 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002737
2738 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002739 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002740 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002741 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002742 self.waitUntilSettled()
2743
2744 # Reconfigure (with only one change in the pipeline).
2745 self.sched.reconfigure(self.config)
2746 self.waitUntilSettled()
2747
2748 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002749 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002750 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002751 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002752 self.waitUntilSettled()
2753
2754 # Reconfigure (with both in the pipeline).
2755 self.sched.reconfigure(self.config)
2756 self.waitUntilSettled()
2757
James E. Blair08d19992016-08-10 15:25:31 -07002758 self.launch_server.hold_jobs_in_build = False
2759 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002760 self.waitUntilSettled()
2761
2762 self.assertEqual(len(self.history), 8)
2763
2764 self.assertEqual(A.data['status'], 'MERGED')
2765 self.assertEqual(A.reported, 2)
2766 self.assertEqual(B.data['status'], 'MERGED')
2767 self.assertEqual(B.reported, 2)
2768
James E. Blairec056492016-07-22 09:45:56 -07002769 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002770 def test_live_reconfiguration_del_project(self):
2771 # Test project deletion from layout
2772 # while changes are enqueued
2773
James E. Blair08d19992016-08-10 15:25:31 -07002774 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002775 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2776 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2777 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2778
2779 # A Depends-On: B
2780 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2781 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002782 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002783
2784 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2785 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2786 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002787 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002788 self.waitUntilSettled()
2789 self.assertEqual(len(self.builds), 5)
2790
2791 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002792 self.updateConfigLayout(
2793 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002794 self.sched.reconfigure(self.config)
2795 self.waitUntilSettled()
2796
2797 # Builds for C aborted, builds for A succeed,
2798 # and have change B applied ahead
2799 job_c = self.getJobFromHistory('project1-test1')
2800 self.assertEqual(job_c.changes, '3,1')
2801 self.assertEqual(job_c.result, 'ABORTED')
2802
James E. Blair08d19992016-08-10 15:25:31 -07002803 self.launch_server.hold_jobs_in_build = False
2804 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002805 self.waitUntilSettled()
2806
2807 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2808 '2,1 1,1')
2809
2810 self.assertEqual(A.data['status'], 'NEW')
2811 self.assertEqual(B.data['status'], 'NEW')
2812 self.assertEqual(C.data['status'], 'NEW')
2813 self.assertEqual(A.reported, 1)
2814 self.assertEqual(B.reported, 0)
2815 self.assertEqual(C.reported, 0)
2816
2817 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2818 self.assertIn('Build succeeded', A.messages[0])
2819
James E. Blairec056492016-07-22 09:45:56 -07002820 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002821 def test_live_reconfiguration_functions(self):
2822 "Test live reconfiguration with a custom function"
2823 self.worker.registerFunction('build:node-project-test1:debian')
2824 self.worker.registerFunction('build:node-project-test1:wheezy')
2825 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002826 A.addApproval('code-review', 2)
2827 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002828 self.waitUntilSettled()
2829
2830 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2831 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2832 'debian')
2833 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2834
James E. Blairf84026c2015-12-08 16:11:46 -08002835 self.updateConfigLayout(
2836 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002837 self.sched.reconfigure(self.config)
2838 self.worker.build_history = []
2839
2840 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002841 B.addApproval('code-review', 2)
2842 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002843 self.waitUntilSettled()
2844
2845 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2846 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2847 'wheezy')
2848 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2849
James E. Blairec056492016-07-22 09:45:56 -07002850 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002851 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002852 self.updateConfigLayout(
2853 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002854 self.sched.reconfigure(self.config)
2855
2856 self.init_repo("org/new-project")
2857 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2858
James E. Blair8b5408c2016-08-08 15:37:46 -07002859 A.addApproval('code-review', 2)
2860 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002861 self.waitUntilSettled()
2862 self.assertEqual(self.getJobFromHistory('project-merge').result,
2863 'SUCCESS')
2864 self.assertEqual(self.getJobFromHistory('project-test1').result,
2865 'SUCCESS')
2866 self.assertEqual(self.getJobFromHistory('project-test2').result,
2867 'SUCCESS')
2868 self.assertEqual(A.data['status'], 'MERGED')
2869 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002870
James E. Blairec056492016-07-22 09:45:56 -07002871 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002872 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002873 self.updateConfigLayout(
2874 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002875 self.sched.reconfigure(self.config)
2876
2877 self.init_repo("org/delete-project")
2878 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2879
James E. Blair8b5408c2016-08-08 15:37:46 -07002880 A.addApproval('code-review', 2)
2881 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002882 self.waitUntilSettled()
2883 self.assertEqual(self.getJobFromHistory('project-merge').result,
2884 'SUCCESS')
2885 self.assertEqual(self.getJobFromHistory('project-test1').result,
2886 'SUCCESS')
2887 self.assertEqual(self.getJobFromHistory('project-test2').result,
2888 'SUCCESS')
2889 self.assertEqual(A.data['status'], 'MERGED')
2890 self.assertEqual(A.reported, 2)
2891
2892 # Delete org/new-project zuul repo. Should be recloned.
2893 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2894
2895 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2896
James E. Blair8b5408c2016-08-08 15:37:46 -07002897 B.addApproval('code-review', 2)
2898 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002899 self.waitUntilSettled()
2900 self.assertEqual(self.getJobFromHistory('project-merge').result,
2901 'SUCCESS')
2902 self.assertEqual(self.getJobFromHistory('project-test1').result,
2903 'SUCCESS')
2904 self.assertEqual(self.getJobFromHistory('project-test2').result,
2905 'SUCCESS')
2906 self.assertEqual(B.data['status'], 'MERGED')
2907 self.assertEqual(B.reported, 2)
2908
James E. Blairec056492016-07-22 09:45:56 -07002909 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002910 def test_tags(self):
2911 "Test job tags"
2912 self.config.set('zuul', 'layout_config',
2913 'tests/fixtures/layout-tags.yaml')
2914 self.sched.reconfigure(self.config)
2915
2916 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2917 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2918 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2919 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2920 self.waitUntilSettled()
2921
2922 results = {'project1-merge': 'extratag merge project1',
2923 'project2-merge': 'merge'}
2924
2925 for build in self.history:
2926 self.assertEqual(results.get(build.name, ''),
2927 build.parameters.get('BUILD_TAGS'))
2928
James E. Blairec056492016-07-22 09:45:56 -07002929 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002930 def test_timer(self):
2931 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002932 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002933 self.updateConfigLayout(
2934 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002935 self.sched.reconfigure(self.config)
2936 self.registerJobs()
2937
Clark Boylan3ee090a2014-04-03 20:55:09 -07002938 # The pipeline triggers every second, so we should have seen
2939 # several by now.
2940 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002941 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002942
2943 self.assertEqual(len(self.builds), 2)
2944
James E. Blair63bb0ef2013-07-29 17:14:51 -07002945 port = self.webapp.server.socket.getsockname()[1]
2946
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002947 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2948 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002949 data = f.read()
2950
James E. Blair08d19992016-08-10 15:25:31 -07002951 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07002952 # Stop queuing timer triggered jobs so that the assertions
2953 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002954 self.updateConfigLayout(
2955 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002956 self.sched.reconfigure(self.config)
2957 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07002958 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07002959 self.waitUntilSettled()
2960
2961 self.assertEqual(self.getJobFromHistory(
2962 'project-bitrot-stable-old').result, 'SUCCESS')
2963 self.assertEqual(self.getJobFromHistory(
2964 'project-bitrot-stable-older').result, 'SUCCESS')
2965
2966 data = json.loads(data)
2967 status_jobs = set()
2968 for p in data['pipelines']:
2969 for q in p['change_queues']:
2970 for head in q['heads']:
2971 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07002972 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002973 for job in change['jobs']:
2974 status_jobs.add(job['name'])
2975 self.assertIn('project-bitrot-stable-old', status_jobs)
2976 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10002977
James E. Blairec056492016-07-22 09:45:56 -07002978 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07002979 def test_idle(self):
2980 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07002981 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07002982
Clark Boylan3ee090a2014-04-03 20:55:09 -07002983 for x in range(1, 3):
2984 # Test that timer triggers periodic jobs even across
2985 # layout config reloads.
2986 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08002987 self.updateConfigLayout(
2988 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002989 self.sched.reconfigure(self.config)
2990 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08002991 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07002992
Clark Boylan3ee090a2014-04-03 20:55:09 -07002993 # The pipeline triggers every second, so we should have seen
2994 # several by now.
2995 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07002996
2997 # Stop queuing timer triggered jobs so that the assertions
2998 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002999 self.updateConfigLayout(
3000 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003001 self.sched.reconfigure(self.config)
3002 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003003 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003004
3005 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003006 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003007 self.waitUntilSettled()
3008 self.assertEqual(len(self.builds), 0)
3009 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003010
James E. Blairec056492016-07-22 09:45:56 -07003011 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003012 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003013 self.updateConfigLayout(
3014 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003015 self.sched.reconfigure(self.config)
3016
3017 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3018 self.waitUntilSettled()
3019
3020 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3021 self.waitUntilSettled()
3022
James E. Blairff80a2f2013-12-27 13:24:06 -08003023 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003024
3025 # A.messages only holds what FakeGerrit places in it. Thus we
3026 # work on the knowledge of what the first message should be as
3027 # it is only configured to go to SMTP.
3028
3029 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003030 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003031 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003032 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003033 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003034 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003035
3036 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003037 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003038 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003039 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003040 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003041 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003042
James E. Blairec056492016-07-22 09:45:56 -07003043 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003044 def test_timer_smtp(self):
3045 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003046 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003047 self.updateConfigLayout(
3048 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003049 self.sched.reconfigure(self.config)
3050 self.registerJobs()
3051
Clark Boylan3ee090a2014-04-03 20:55:09 -07003052 # The pipeline triggers every second, so we should have seen
3053 # several by now.
3054 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003055 self.waitUntilSettled()
3056
Clark Boylan3ee090a2014-04-03 20:55:09 -07003057 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003058 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003059 self.waitUntilSettled()
3060 self.assertEqual(len(self.history), 2)
3061
James E. Blaire5910202013-12-27 09:50:31 -08003062 self.assertEqual(self.getJobFromHistory(
3063 'project-bitrot-stable-old').result, 'SUCCESS')
3064 self.assertEqual(self.getJobFromHistory(
3065 'project-bitrot-stable-older').result, 'SUCCESS')
3066
James E. Blairff80a2f2013-12-27 13:24:06 -08003067 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003068
3069 # A.messages only holds what FakeGerrit places in it. Thus we
3070 # work on the knowledge of what the first message should be as
3071 # it is only configured to go to SMTP.
3072
3073 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003074 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003075 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003076 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003077 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003078 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003079
Clark Boylan3ee090a2014-04-03 20:55:09 -07003080 # Stop queuing timer triggered jobs and let any that may have
3081 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003082 self.updateConfigLayout(
3083 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003084 self.sched.reconfigure(self.config)
3085 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003086 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003087 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003088 self.waitUntilSettled()
3089
James E. Blairec056492016-07-22 09:45:56 -07003090 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003091 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003092 "Test that the RPC client can enqueue a change"
3093 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003094 A.addApproval('code-review', 2)
3095 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003096
3097 client = zuul.rpcclient.RPCClient('127.0.0.1',
3098 self.gearman_server.port)
3099 r = client.enqueue(pipeline='gate',
3100 project='org/project',
3101 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003102 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003103 self.waitUntilSettled()
3104 self.assertEqual(self.getJobFromHistory('project-merge').result,
3105 'SUCCESS')
3106 self.assertEqual(self.getJobFromHistory('project-test1').result,
3107 'SUCCESS')
3108 self.assertEqual(self.getJobFromHistory('project-test2').result,
3109 'SUCCESS')
3110 self.assertEqual(A.data['status'], 'MERGED')
3111 self.assertEqual(A.reported, 2)
3112 self.assertEqual(r, True)
3113
James E. Blairec056492016-07-22 09:45:56 -07003114 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003115 def test_client_enqueue_ref(self):
3116 "Test that the RPC client can enqueue a ref"
3117
3118 client = zuul.rpcclient.RPCClient('127.0.0.1',
3119 self.gearman_server.port)
3120 r = client.enqueue_ref(
3121 pipeline='post',
3122 project='org/project',
3123 trigger='gerrit',
3124 ref='master',
3125 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3126 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3127 self.waitUntilSettled()
3128 job_names = [x.name for x in self.history]
3129 self.assertEqual(len(self.history), 1)
3130 self.assertIn('project-post', job_names)
3131 self.assertEqual(r, True)
3132
James E. Blairec056492016-07-22 09:45:56 -07003133 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003134 def test_client_enqueue_negative(self):
3135 "Test that the RPC client returns errors"
3136 client = zuul.rpcclient.RPCClient('127.0.0.1',
3137 self.gearman_server.port)
3138 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3139 "Invalid project"):
3140 r = client.enqueue(pipeline='gate',
3141 project='project-does-not-exist',
3142 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003143 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003144 client.shutdown()
3145 self.assertEqual(r, False)
3146
3147 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3148 "Invalid pipeline"):
3149 r = client.enqueue(pipeline='pipeline-does-not-exist',
3150 project='org/project',
3151 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003152 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003153 client.shutdown()
3154 self.assertEqual(r, False)
3155
3156 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3157 "Invalid trigger"):
3158 r = client.enqueue(pipeline='gate',
3159 project='org/project',
3160 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003161 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003162 client.shutdown()
3163 self.assertEqual(r, False)
3164
3165 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3166 "Invalid change"):
3167 r = client.enqueue(pipeline='gate',
3168 project='org/project',
3169 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003170 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003171 client.shutdown()
3172 self.assertEqual(r, False)
3173
3174 self.waitUntilSettled()
3175 self.assertEqual(len(self.history), 0)
3176 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003177
James E. Blairec056492016-07-22 09:45:56 -07003178 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003179 def test_client_promote(self):
3180 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003181 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003182 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3183 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3184 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003185 A.addApproval('code-review', 2)
3186 B.addApproval('code-review', 2)
3187 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003188
James E. Blair8b5408c2016-08-08 15:37:46 -07003189 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3190 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3191 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003192
3193 self.waitUntilSettled()
3194
Sean Daguef39b9ca2014-01-10 21:34:35 -05003195 items = self.sched.layout.pipelines['gate'].getAllItems()
3196 enqueue_times = {}
3197 for item in items:
3198 enqueue_times[str(item.change)] = item.enqueue_time
3199
James E. Blair36658cf2013-12-06 17:53:48 -08003200 client = zuul.rpcclient.RPCClient('127.0.0.1',
3201 self.gearman_server.port)
3202 r = client.promote(pipeline='gate',
3203 change_ids=['2,1', '3,1'])
3204
Sean Daguef39b9ca2014-01-10 21:34:35 -05003205 # ensure that enqueue times are durable
3206 items = self.sched.layout.pipelines['gate'].getAllItems()
3207 for item in items:
3208 self.assertEqual(
3209 enqueue_times[str(item.change)], item.enqueue_time)
3210
James E. Blair78acec92014-02-06 07:11:32 -08003211 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003212 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003213 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003214 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003215 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003216 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003217 self.waitUntilSettled()
3218
3219 self.assertEqual(len(self.builds), 6)
3220 self.assertEqual(self.builds[0].name, 'project-test1')
3221 self.assertEqual(self.builds[1].name, 'project-test2')
3222 self.assertEqual(self.builds[2].name, 'project-test1')
3223 self.assertEqual(self.builds[3].name, 'project-test2')
3224 self.assertEqual(self.builds[4].name, 'project-test1')
3225 self.assertEqual(self.builds[5].name, 'project-test2')
3226
3227 self.assertTrue(self.job_has_changes(self.builds[0], B))
3228 self.assertFalse(self.job_has_changes(self.builds[0], A))
3229 self.assertFalse(self.job_has_changes(self.builds[0], C))
3230
3231 self.assertTrue(self.job_has_changes(self.builds[2], B))
3232 self.assertTrue(self.job_has_changes(self.builds[2], C))
3233 self.assertFalse(self.job_has_changes(self.builds[2], A))
3234
3235 self.assertTrue(self.job_has_changes(self.builds[4], B))
3236 self.assertTrue(self.job_has_changes(self.builds[4], C))
3237 self.assertTrue(self.job_has_changes(self.builds[4], A))
3238
James E. Blair08d19992016-08-10 15:25:31 -07003239 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003240 self.waitUntilSettled()
3241
3242 self.assertEqual(A.data['status'], 'MERGED')
3243 self.assertEqual(A.reported, 2)
3244 self.assertEqual(B.data['status'], 'MERGED')
3245 self.assertEqual(B.reported, 2)
3246 self.assertEqual(C.data['status'], 'MERGED')
3247 self.assertEqual(C.reported, 2)
3248
3249 client.shutdown()
3250 self.assertEqual(r, True)
3251
James E. Blairec056492016-07-22 09:45:56 -07003252 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003253 def test_client_promote_dependent(self):
3254 "Test that the RPC client can promote a dependent change"
3255 # C (depends on B) -> B -> A ; then promote C to get:
3256 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003257 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003258 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3259 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3260 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3261
3262 C.setDependsOn(B, 1)
3263
James E. Blair8b5408c2016-08-08 15:37:46 -07003264 A.addApproval('code-review', 2)
3265 B.addApproval('code-review', 2)
3266 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003267
James E. Blair8b5408c2016-08-08 15:37:46 -07003268 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3269 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3270 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003271
3272 self.waitUntilSettled()
3273
3274 client = zuul.rpcclient.RPCClient('127.0.0.1',
3275 self.gearman_server.port)
3276 r = client.promote(pipeline='gate',
3277 change_ids=['3,1'])
3278
James E. Blair78acec92014-02-06 07:11:32 -08003279 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003280 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003281 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003282 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003283 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003284 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003285 self.waitUntilSettled()
3286
3287 self.assertEqual(len(self.builds), 6)
3288 self.assertEqual(self.builds[0].name, 'project-test1')
3289 self.assertEqual(self.builds[1].name, 'project-test2')
3290 self.assertEqual(self.builds[2].name, 'project-test1')
3291 self.assertEqual(self.builds[3].name, 'project-test2')
3292 self.assertEqual(self.builds[4].name, 'project-test1')
3293 self.assertEqual(self.builds[5].name, 'project-test2')
3294
3295 self.assertTrue(self.job_has_changes(self.builds[0], B))
3296 self.assertFalse(self.job_has_changes(self.builds[0], A))
3297 self.assertFalse(self.job_has_changes(self.builds[0], C))
3298
3299 self.assertTrue(self.job_has_changes(self.builds[2], B))
3300 self.assertTrue(self.job_has_changes(self.builds[2], C))
3301 self.assertFalse(self.job_has_changes(self.builds[2], A))
3302
3303 self.assertTrue(self.job_has_changes(self.builds[4], B))
3304 self.assertTrue(self.job_has_changes(self.builds[4], C))
3305 self.assertTrue(self.job_has_changes(self.builds[4], A))
3306
James E. Blair08d19992016-08-10 15:25:31 -07003307 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003308 self.waitUntilSettled()
3309
3310 self.assertEqual(A.data['status'], 'MERGED')
3311 self.assertEqual(A.reported, 2)
3312 self.assertEqual(B.data['status'], 'MERGED')
3313 self.assertEqual(B.reported, 2)
3314 self.assertEqual(C.data['status'], 'MERGED')
3315 self.assertEqual(C.reported, 2)
3316
3317 client.shutdown()
3318 self.assertEqual(r, True)
3319
James E. Blairec056492016-07-22 09:45:56 -07003320 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003321 def test_client_promote_negative(self):
3322 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003323 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003324 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003325 A.addApproval('code-review', 2)
3326 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003327 self.waitUntilSettled()
3328
3329 client = zuul.rpcclient.RPCClient('127.0.0.1',
3330 self.gearman_server.port)
3331
3332 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3333 r = client.promote(pipeline='nonexistent',
3334 change_ids=['2,1', '3,1'])
3335 client.shutdown()
3336 self.assertEqual(r, False)
3337
3338 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3339 r = client.promote(pipeline='gate',
3340 change_ids=['4,1'])
3341 client.shutdown()
3342 self.assertEqual(r, False)
3343
James E. Blair08d19992016-08-10 15:25:31 -07003344 self.launch_server.hold_jobs_in_build = False
3345 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003346 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003347
James E. Blairec056492016-07-22 09:45:56 -07003348 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003349 def test_queue_rate_limiting(self):
3350 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003351 self.updateConfigLayout(
3352 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003353 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003354 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003355 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3356 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3357 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3358
3359 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003360 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003361
James E. Blair8b5408c2016-08-08 15:37:46 -07003362 A.addApproval('code-review', 2)
3363 B.addApproval('code-review', 2)
3364 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003365
James E. Blair8b5408c2016-08-08 15:37:46 -07003366 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3367 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3368 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003369 self.waitUntilSettled()
3370
3371 # Only A and B will have their merge jobs queued because
3372 # window is 2.
3373 self.assertEqual(len(self.builds), 2)
3374 self.assertEqual(self.builds[0].name, 'project-merge')
3375 self.assertEqual(self.builds[1].name, 'project-merge')
3376
James E. Blair08d19992016-08-10 15:25:31 -07003377 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003378 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003379 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003380 self.waitUntilSettled()
3381
3382 # Only A and B will have their test jobs queued because
3383 # window is 2.
3384 self.assertEqual(len(self.builds), 4)
3385 self.assertEqual(self.builds[0].name, 'project-test1')
3386 self.assertEqual(self.builds[1].name, 'project-test2')
3387 self.assertEqual(self.builds[2].name, 'project-test1')
3388 self.assertEqual(self.builds[3].name, 'project-test2')
3389
James E. Blair08d19992016-08-10 15:25:31 -07003390 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003391 self.waitUntilSettled()
3392
3393 queue = self.sched.layout.pipelines['gate'].queues[0]
3394 # A failed so window is reduced by 1 to 1.
3395 self.assertEqual(queue.window, 1)
3396 self.assertEqual(queue.window_floor, 1)
3397 self.assertEqual(A.data['status'], 'NEW')
3398
3399 # Gate is reset and only B's merge job is queued because
3400 # window shrunk to 1.
3401 self.assertEqual(len(self.builds), 1)
3402 self.assertEqual(self.builds[0].name, 'project-merge')
3403
James E. Blair08d19992016-08-10 15:25:31 -07003404 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003405 self.waitUntilSettled()
3406
3407 # Only B's test jobs are queued because window is still 1.
3408 self.assertEqual(len(self.builds), 2)
3409 self.assertEqual(self.builds[0].name, 'project-test1')
3410 self.assertEqual(self.builds[1].name, 'project-test2')
3411
James E. Blair08d19992016-08-10 15:25:31 -07003412 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003413 self.waitUntilSettled()
3414
3415 # B was successfully merged so window is increased to 2.
3416 self.assertEqual(queue.window, 2)
3417 self.assertEqual(queue.window_floor, 1)
3418 self.assertEqual(B.data['status'], 'MERGED')
3419
3420 # Only C is left and its merge job is queued.
3421 self.assertEqual(len(self.builds), 1)
3422 self.assertEqual(self.builds[0].name, 'project-merge')
3423
James E. Blair08d19992016-08-10 15:25:31 -07003424 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003425 self.waitUntilSettled()
3426
3427 # After successful merge job the test jobs for C are queued.
3428 self.assertEqual(len(self.builds), 2)
3429 self.assertEqual(self.builds[0].name, 'project-test1')
3430 self.assertEqual(self.builds[1].name, 'project-test2')
3431
James E. Blair08d19992016-08-10 15:25:31 -07003432 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003433 self.waitUntilSettled()
3434
3435 # C successfully merged so window is bumped to 3.
3436 self.assertEqual(queue.window, 3)
3437 self.assertEqual(queue.window_floor, 1)
3438 self.assertEqual(C.data['status'], 'MERGED')
3439
James E. Blairec056492016-07-22 09:45:56 -07003440 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003441 def test_queue_rate_limiting_dependent(self):
3442 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003443 self.updateConfigLayout(
3444 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003445 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003446 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003447 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3448 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3449 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3450
3451 B.setDependsOn(A, 1)
3452
James E. Blair08d19992016-08-10 15:25:31 -07003453 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003454
James E. Blair8b5408c2016-08-08 15:37:46 -07003455 A.addApproval('code-review', 2)
3456 B.addApproval('code-review', 2)
3457 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003458
James E. Blair8b5408c2016-08-08 15:37:46 -07003459 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3460 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3461 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003462 self.waitUntilSettled()
3463
3464 # Only A and B will have their merge jobs queued because
3465 # window is 2.
3466 self.assertEqual(len(self.builds), 2)
3467 self.assertEqual(self.builds[0].name, 'project-merge')
3468 self.assertEqual(self.builds[1].name, 'project-merge')
3469
James E. Blair08d19992016-08-10 15:25:31 -07003470 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003471 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003472 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003473 self.waitUntilSettled()
3474
3475 # Only A and B will have their test jobs queued because
3476 # window is 2.
3477 self.assertEqual(len(self.builds), 4)
3478 self.assertEqual(self.builds[0].name, 'project-test1')
3479 self.assertEqual(self.builds[1].name, 'project-test2')
3480 self.assertEqual(self.builds[2].name, 'project-test1')
3481 self.assertEqual(self.builds[3].name, 'project-test2')
3482
James E. Blair08d19992016-08-10 15:25:31 -07003483 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003484 self.waitUntilSettled()
3485
3486 queue = self.sched.layout.pipelines['gate'].queues[0]
3487 # A failed so window is reduced by 1 to 1.
3488 self.assertEqual(queue.window, 1)
3489 self.assertEqual(queue.window_floor, 1)
3490 self.assertEqual(A.data['status'], 'NEW')
3491 self.assertEqual(B.data['status'], 'NEW')
3492
3493 # Gate is reset and only C's merge job is queued because
3494 # window shrunk to 1 and A and B were dequeued.
3495 self.assertEqual(len(self.builds), 1)
3496 self.assertEqual(self.builds[0].name, 'project-merge')
3497
James E. Blair08d19992016-08-10 15:25:31 -07003498 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003499 self.waitUntilSettled()
3500
3501 # Only C's test jobs are queued because window is still 1.
3502 self.assertEqual(len(self.builds), 2)
3503 self.assertEqual(self.builds[0].name, 'project-test1')
3504 self.assertEqual(self.builds[1].name, 'project-test2')
3505
James E. Blair08d19992016-08-10 15:25:31 -07003506 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003507 self.waitUntilSettled()
3508
3509 # C was successfully merged so window is increased to 2.
3510 self.assertEqual(queue.window, 2)
3511 self.assertEqual(queue.window_floor, 1)
3512 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003513
James E. Blairec056492016-07-22 09:45:56 -07003514 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003515 def test_worker_update_metadata(self):
3516 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003517 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003518
3519 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003520 A.addApproval('code-review', 2)
3521 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003522 self.waitUntilSettled()
3523
3524 self.assertEqual(len(self.launcher.builds), 1)
3525
3526 self.log.debug('Current builds:')
3527 self.log.debug(self.launcher.builds)
3528
3529 start = time.time()
3530 while True:
3531 if time.time() - start > 10:
3532 raise Exception("Timeout waiting for gearman server to report "
3533 + "back to the client")
3534 build = self.launcher.builds.values()[0]
3535 if build.worker.name == "My Worker":
3536 break
3537 else:
3538 time.sleep(0)
3539
3540 self.log.debug(build)
3541 self.assertEqual("My Worker", build.worker.name)
3542 self.assertEqual("localhost", build.worker.hostname)
3543 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3544 self.assertEqual("zuul.example.org", build.worker.fqdn)
3545 self.assertEqual("FakeBuilder", build.worker.program)
3546 self.assertEqual("v1.1", build.worker.version)
3547 self.assertEqual({'something': 'else'}, build.worker.extra)
3548
James E. Blair08d19992016-08-10 15:25:31 -07003549 self.launch_server.hold_jobs_in_build = False
3550 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003551 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003552
James E. Blairec056492016-07-22 09:45:56 -07003553 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003554 def test_footer_message(self):
3555 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003556 self.updateConfigLayout(
3557 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003558 self.sched.reconfigure(self.config)
3559 self.registerJobs()
3560
3561 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003562 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003563 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003564 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003565 self.waitUntilSettled()
3566
3567 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003568 B.addApproval('code-review', 2)
3569 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003570 self.waitUntilSettled()
3571
3572 self.assertEqual(2, len(self.smtp_messages))
3573
3574 failure_body = """\
3575Build failed. For information on how to proceed, see \
3576http://wiki.example.org/Test_Failures
3577
3578- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3579- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3580
3581For CI problems and help debugging, contact ci@example.org"""
3582
3583 success_body = """\
3584Build succeeded.
3585
3586- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3587- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3588
3589For CI problems and help debugging, contact ci@example.org"""
3590
3591 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3592 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003593
James E. Blairec056492016-07-22 09:45:56 -07003594 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003595 def test_merge_failure_reporters(self):
3596 """Check that the config is set up correctly"""
3597
James E. Blairf84026c2015-12-08 16:11:46 -08003598 self.updateConfigLayout(
3599 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003600 self.sched.reconfigure(self.config)
3601 self.registerJobs()
3602
3603 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003604 "Merge Failed.\n\nThis change or one of its cross-repo "
3605 "dependencies was unable to be automatically merged with the "
3606 "current state of its repository. Please rebase the change and "
3607 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003608 self.sched.layout.pipelines['check'].merge_failure_message)
3609 self.assertEqual(
3610 "The merge failed! For more information...",
3611 self.sched.layout.pipelines['gate'].merge_failure_message)
3612
3613 self.assertEqual(
3614 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3615 self.assertEqual(
3616 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3617
3618 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003619 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3620 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003621
3622 self.assertTrue(
3623 (
3624 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003625 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003626 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003627 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003628 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003629 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003630 ) or (
3631 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003632 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003633 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003634 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003635 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003636 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003637 )
3638 )
3639
James E. Blairec056492016-07-22 09:45:56 -07003640 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003641 def test_merge_failure_reports(self):
3642 """Check that when a change fails to merge the correct message is sent
3643 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003644 self.updateConfigLayout(
3645 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003646 self.sched.reconfigure(self.config)
3647 self.registerJobs()
3648
3649 # Check a test failure isn't reported to SMTP
3650 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003651 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003652 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003653 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003654 self.waitUntilSettled()
3655
3656 self.assertEqual(3, len(self.history)) # 3 jobs
3657 self.assertEqual(0, len(self.smtp_messages))
3658
3659 # Check a merge failure is reported to SMTP
3660 # B should be merged, but C will conflict with B
3661 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3662 B.addPatchset(['conflict'])
3663 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3664 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003665 B.addApproval('code-review', 2)
3666 C.addApproval('code-review', 2)
3667 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3668 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003669 self.waitUntilSettled()
3670
3671 self.assertEqual(6, len(self.history)) # A and B jobs
3672 self.assertEqual(1, len(self.smtp_messages))
3673 self.assertEqual('The merge failed! For more information...',
3674 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003675
James E. Blairec056492016-07-22 09:45:56 -07003676 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003677 def test_default_merge_failure_reports(self):
3678 """Check that the default merge failure reports are correct."""
3679
3680 # A should report success, B should report merge failure.
3681 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3682 A.addPatchset(['conflict'])
3683 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3684 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003685 A.addApproval('code-review', 2)
3686 B.addApproval('code-review', 2)
3687 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3688 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003689 self.waitUntilSettled()
3690
3691 self.assertEqual(3, len(self.history)) # A jobs
3692 self.assertEqual(A.reported, 2)
3693 self.assertEqual(B.reported, 2)
3694 self.assertEqual(A.data['status'], 'MERGED')
3695 self.assertEqual(B.data['status'], 'NEW')
3696 self.assertIn('Build succeeded', A.messages[1])
3697 self.assertIn('Merge Failed', B.messages[1])
3698 self.assertIn('automatically merged', B.messages[1])
3699 self.assertNotIn('logs.example.com', B.messages[1])
3700 self.assertNotIn('SKIPPED', B.messages[1])
3701
James E. Blairec056492016-07-22 09:45:56 -07003702 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003703 def test_swift_instructions(self):
3704 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003705 self.updateConfigLayout(
3706 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003707 self.sched.reconfigure(self.config)
3708 self.registerJobs()
3709
James E. Blair08d19992016-08-10 15:25:31 -07003710 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003711 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3712
James E. Blair8b5408c2016-08-08 15:37:46 -07003713 A.addApproval('code-review', 2)
3714 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003715 self.waitUntilSettled()
3716
3717 self.assertEqual(
3718 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3719 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003720 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003721 self.assertEqual(5,
3722 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3723 split('\n')))
3724 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3725
3726 self.assertEqual(
3727 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3728 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003729 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003730 self.assertEqual(5,
3731 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3732 split('\n')))
3733 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3734
3735 self.assertEqual(
3736 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3737 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003738 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003739 self.assertEqual(5,
3740 len(self.builds[1].
3741 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3742 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3743
James E. Blair08d19992016-08-10 15:25:31 -07003744 self.launch_server.hold_jobs_in_build = False
3745 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003746 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003747
James E. Blairec056492016-07-22 09:45:56 -07003748 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003749 def test_client_get_running_jobs(self):
3750 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003751 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003752 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003753 A.addApproval('code-review', 2)
3754 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003755 self.waitUntilSettled()
3756
3757 client = zuul.rpcclient.RPCClient('127.0.0.1',
3758 self.gearman_server.port)
3759
3760 # Wait for gearman server to send the initial workData back to zuul
3761 start = time.time()
3762 while True:
3763 if time.time() - start > 10:
3764 raise Exception("Timeout waiting for gearman server to report "
3765 + "back to the client")
3766 build = self.launcher.builds.values()[0]
3767 if build.worker.name == "My Worker":
3768 break
3769 else:
3770 time.sleep(0)
3771
3772 running_items = client.get_running_jobs()
3773
3774 self.assertEqual(1, len(running_items))
3775 running_item = running_items[0]
3776 self.assertEqual([], running_item['failing_reasons'])
3777 self.assertEqual([], running_item['items_behind'])
3778 self.assertEqual('https://hostname/1', running_item['url'])
3779 self.assertEqual(None, running_item['item_ahead'])
3780 self.assertEqual('org/project', running_item['project'])
3781 self.assertEqual(None, running_item['remaining_time'])
3782 self.assertEqual(True, running_item['active'])
3783 self.assertEqual('1,1', running_item['id'])
3784
3785 self.assertEqual(3, len(running_item['jobs']))
3786 for job in running_item['jobs']:
3787 if job['name'] == 'project-merge':
3788 self.assertEqual('project-merge', job['name'])
3789 self.assertEqual('gate', job['pipeline'])
3790 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003791 self.assertEqual('https://server/job/project-merge/0/',
3792 job['url'])
3793 self.assertEqual(7, len(job['worker']))
3794 self.assertEqual(False, job['canceled'])
3795 self.assertEqual(True, job['voting'])
3796 self.assertEqual(None, job['result'])
3797 self.assertEqual('gate', job['pipeline'])
3798 break
3799
James E. Blair08d19992016-08-10 15:25:31 -07003800 self.launch_server.hold_jobs_in_build = False
3801 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003802 self.waitUntilSettled()
3803
3804 running_items = client.get_running_jobs()
3805 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003806
3807 def test_nonvoting_pipeline(self):
3808 "Test that a nonvoting pipeline (experimental) can still report"
3809
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003810 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3811 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003812 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3813 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003814
3815 self.assertEqual(self.getJobFromHistory('project-merge').result,
3816 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003817 self.assertEqual(
3818 self.getJobFromHistory('experimental-project-test').result,
3819 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003820 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003821
James E. Blairec056492016-07-22 09:45:56 -07003822 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003823 def test_crd_gate(self):
3824 "Test cross-repo dependencies"
3825 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3826 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003827 A.addApproval('code-review', 2)
3828 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003829
3830 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3831 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3832 AM2.setMerged()
3833 AM1.setMerged()
3834
3835 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3836 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3837 BM2.setMerged()
3838 BM1.setMerged()
3839
3840 # A -> AM1 -> AM2
3841 # B -> BM1 -> BM2
3842 # A Depends-On: B
3843 # M2 is here to make sure it is never queried. If it is, it
3844 # means zuul is walking down the entire history of merged
3845 # changes.
3846
3847 B.setDependsOn(BM1, 1)
3848 BM1.setDependsOn(BM2, 1)
3849
3850 A.setDependsOn(AM1, 1)
3851 AM1.setDependsOn(AM2, 1)
3852
3853 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3854 A.subject, B.data['id'])
3855
James E. Blair8b5408c2016-08-08 15:37:46 -07003856 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003857 self.waitUntilSettled()
3858
3859 self.assertEqual(A.data['status'], 'NEW')
3860 self.assertEqual(B.data['status'], 'NEW')
3861
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003862 for connection in self.connections.values():
3863 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003864
James E. Blair08d19992016-08-10 15:25:31 -07003865 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003866 B.addApproval('approved', 1)
3867 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003868 self.waitUntilSettled()
3869
James E. Blair08d19992016-08-10 15:25:31 -07003870 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003871 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003872 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003873 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003874 self.launch_server.hold_jobs_in_build = False
3875 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003876 self.waitUntilSettled()
3877
3878 self.assertEqual(AM2.queried, 0)
3879 self.assertEqual(BM2.queried, 0)
3880 self.assertEqual(A.data['status'], 'MERGED')
3881 self.assertEqual(B.data['status'], 'MERGED')
3882 self.assertEqual(A.reported, 2)
3883 self.assertEqual(B.reported, 2)
3884
James E. Blair8f78d882015-02-05 08:51:37 -08003885 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3886 '2,1 1,1')
3887
James E. Blairec056492016-07-22 09:45:56 -07003888 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003889 def test_crd_branch(self):
3890 "Test cross-repo dependencies in multiple branches"
3891 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3892 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3893 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3894 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003895 A.addApproval('code-review', 2)
3896 B.addApproval('code-review', 2)
3897 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003898
3899 # A Depends-On: B+C
3900 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3901 A.subject, B.data['id'])
3902
James E. Blair08d19992016-08-10 15:25:31 -07003903 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003904 B.addApproval('approved', 1)
3905 C.addApproval('approved', 1)
3906 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003907 self.waitUntilSettled()
3908
James E. Blair08d19992016-08-10 15:25:31 -07003909 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003910 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003911 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003912 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003913 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003914 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003915 self.launch_server.hold_jobs_in_build = False
3916 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003917 self.waitUntilSettled()
3918
3919 self.assertEqual(A.data['status'], 'MERGED')
3920 self.assertEqual(B.data['status'], 'MERGED')
3921 self.assertEqual(C.data['status'], 'MERGED')
3922 self.assertEqual(A.reported, 2)
3923 self.assertEqual(B.reported, 2)
3924 self.assertEqual(C.reported, 2)
3925
3926 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3927 '2,1 3,1 1,1')
3928
James E. Blairec056492016-07-22 09:45:56 -07003929 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003930 def test_crd_multiline(self):
3931 "Test multiple depends-on lines in commit"
3932 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3933 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3934 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003935 A.addApproval('code-review', 2)
3936 B.addApproval('code-review', 2)
3937 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003938
3939 # A Depends-On: B+C
3940 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
3941 A.subject, B.data['id'], C.data['id'])
3942
James E. Blair08d19992016-08-10 15:25:31 -07003943 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003944 B.addApproval('approved', 1)
3945 C.addApproval('approved', 1)
3946 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003947 self.waitUntilSettled()
3948
James E. Blair08d19992016-08-10 15:25:31 -07003949 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003950 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003951 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003952 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003953 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003954 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003955 self.launch_server.hold_jobs_in_build = False
3956 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003957 self.waitUntilSettled()
3958
3959 self.assertEqual(A.data['status'], 'MERGED')
3960 self.assertEqual(B.data['status'], 'MERGED')
3961 self.assertEqual(C.data['status'], 'MERGED')
3962 self.assertEqual(A.reported, 2)
3963 self.assertEqual(B.reported, 2)
3964 self.assertEqual(C.reported, 2)
3965
3966 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3967 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08003968
3969 def test_crd_unshared_gate(self):
3970 "Test cross-repo dependencies in unshared gate queues"
3971 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3972 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003973 A.addApproval('code-review', 2)
3974 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003975
3976 # A Depends-On: B
3977 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3978 A.subject, B.data['id'])
3979
3980 # A and B do not share a queue, make sure that A is unable to
3981 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07003982 B.addApproval('approved', 1)
3983 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003984 self.waitUntilSettled()
3985
3986 self.assertEqual(A.data['status'], 'NEW')
3987 self.assertEqual(B.data['status'], 'NEW')
3988 self.assertEqual(A.reported, 0)
3989 self.assertEqual(B.reported, 0)
3990 self.assertEqual(len(self.history), 0)
3991
3992 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07003993 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003994 self.waitUntilSettled()
3995
3996 self.assertEqual(B.data['status'], 'MERGED')
3997 self.assertEqual(B.reported, 2)
3998
3999 # Now that B is merged, A should be able to be enqueued and
4000 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004001 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004002 self.waitUntilSettled()
4003
4004 self.assertEqual(A.data['status'], 'MERGED')
4005 self.assertEqual(A.reported, 2)
4006
James E. Blairec056492016-07-22 09:45:56 -07004007 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004008 def test_crd_gate_reverse(self):
4009 "Test reverse cross-repo dependencies"
4010 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4011 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004012 A.addApproval('code-review', 2)
4013 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004014
4015 # A Depends-On: B
4016
4017 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4018 A.subject, B.data['id'])
4019
James E. Blair8b5408c2016-08-08 15:37:46 -07004020 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004021 self.waitUntilSettled()
4022
4023 self.assertEqual(A.data['status'], 'NEW')
4024 self.assertEqual(B.data['status'], 'NEW')
4025
James E. Blair08d19992016-08-10 15:25:31 -07004026 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004027 A.addApproval('approved', 1)
4028 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004029 self.waitUntilSettled()
4030
James E. Blair08d19992016-08-10 15:25:31 -07004031 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004032 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004033 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004034 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004035 self.launch_server.hold_jobs_in_build = False
4036 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004037 self.waitUntilSettled()
4038
4039 self.assertEqual(A.data['status'], 'MERGED')
4040 self.assertEqual(B.data['status'], 'MERGED')
4041 self.assertEqual(A.reported, 2)
4042 self.assertEqual(B.reported, 2)
4043
4044 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4045 '2,1 1,1')
4046
James E. Blair5ee24252014-12-30 10:12:29 -08004047 def test_crd_cycle(self):
4048 "Test cross-repo dependency cycles"
4049 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4050 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004051 A.addApproval('code-review', 2)
4052 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004053
4054 # A -> B -> A (via commit-depends)
4055
4056 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4057 A.subject, B.data['id'])
4058 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4059 B.subject, A.data['id'])
4060
James E. Blair8b5408c2016-08-08 15:37:46 -07004061 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004062 self.waitUntilSettled()
4063
4064 self.assertEqual(A.reported, 0)
4065 self.assertEqual(B.reported, 0)
4066 self.assertEqual(A.data['status'], 'NEW')
4067 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004068
James E. Blairec056492016-07-22 09:45:56 -07004069 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004070 def test_crd_gate_unknown(self):
4071 "Test unknown projects in dependent pipeline"
4072 self.init_repo("org/unknown")
4073 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4074 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004075 A.addApproval('code-review', 2)
4076 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004077
4078 # A Depends-On: B
4079 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4080 A.subject, B.data['id'])
4081
James E. Blair8b5408c2016-08-08 15:37:46 -07004082 B.addApproval('approved', 1)
4083 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004084 self.waitUntilSettled()
4085
4086 # Unknown projects cannot share a queue with any other
4087 # since they don't have common jobs with any other (they have no jobs).
4088 # Changes which depend on unknown project changes
4089 # should not be processed in dependent pipeline
4090 self.assertEqual(A.data['status'], 'NEW')
4091 self.assertEqual(B.data['status'], 'NEW')
4092 self.assertEqual(A.reported, 0)
4093 self.assertEqual(B.reported, 0)
4094 self.assertEqual(len(self.history), 0)
4095
4096 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004097 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004098 B.setMerged()
4099 self.waitUntilSettled()
4100 self.assertEqual(len(self.history), 0)
4101
4102 # Now that B is merged, A should be able to be enqueued and
4103 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004104 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004105 self.waitUntilSettled()
4106
4107 self.assertEqual(A.data['status'], 'MERGED')
4108 self.assertEqual(A.reported, 2)
4109 self.assertEqual(B.data['status'], 'MERGED')
4110 self.assertEqual(B.reported, 0)
4111
James E. Blairec056492016-07-22 09:45:56 -07004112 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004113 def test_crd_check(self):
4114 "Test cross-repo dependencies in independent pipelines"
4115
4116 self.gearman_server.hold_jobs_in_queue = True
4117 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4118 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4119
4120 # A Depends-On: B
4121 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4122 A.subject, B.data['id'])
4123
4124 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4125 self.waitUntilSettled()
4126
4127 queue = self.gearman_server.getQueue()
4128 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4129 self.gearman_server.hold_jobs_in_queue = False
4130 self.gearman_server.release()
4131 self.waitUntilSettled()
4132
4133 path = os.path.join(self.git_root, "org/project1")
4134 repo = git.Repo(path)
4135 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4136 repo_messages.reverse()
4137 correct_messages = ['initial commit', 'A-1']
4138 self.assertEqual(repo_messages, correct_messages)
4139
4140 path = os.path.join(self.git_root, "org/project2")
4141 repo = git.Repo(path)
4142 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4143 repo_messages.reverse()
4144 correct_messages = ['initial commit', 'B-1']
4145 self.assertEqual(repo_messages, correct_messages)
4146
4147 self.assertEqual(A.data['status'], 'NEW')
4148 self.assertEqual(B.data['status'], 'NEW')
4149 self.assertEqual(A.reported, 1)
4150 self.assertEqual(B.reported, 0)
4151
4152 self.assertEqual(self.history[0].changes, '2,1 1,1')
4153 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004154
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004155 def test_crd_check_git_depends(self):
4156 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004157 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004158 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4159 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4160
4161 # Add two git-dependent changes and make sure they both report
4162 # success.
4163 B.setDependsOn(A, 1)
4164 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4165 self.waitUntilSettled()
4166 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4167 self.waitUntilSettled()
4168
James E. Blairb8c16472015-05-05 14:55:26 -07004169 self.orderedRelease()
4170 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004171 self.waitUntilSettled()
4172
4173 self.assertEqual(A.data['status'], 'NEW')
4174 self.assertEqual(B.data['status'], 'NEW')
4175 self.assertEqual(A.reported, 1)
4176 self.assertEqual(B.reported, 1)
4177
4178 self.assertEqual(self.history[0].changes, '1,1')
4179 self.assertEqual(self.history[-1].changes, '1,1 2,1')
Paul Belanger08136962016-11-03 17:57:38 -04004180 tenant = self.sched.abide.tenants.get('tenant-one')
4181 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004182
4183 self.assertIn('Build succeeded', A.messages[0])
4184 self.assertIn('Build succeeded', B.messages[0])
4185
4186 def test_crd_check_duplicate(self):
4187 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004188 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004189 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4190 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
Paul Belanger08136962016-11-03 17:57:38 -04004191 tenant = self.sched.abide.tenants.get('tenant-one')
4192 check_pipeline = tenant.layout.pipelines['check']
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004193
4194 # Add two git-dependent changes...
4195 B.setDependsOn(A, 1)
4196 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4197 self.waitUntilSettled()
4198 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4199
4200 # ...make sure the live one is not duplicated...
4201 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4202 self.waitUntilSettled()
4203 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4204
4205 # ...but the non-live one is able to be.
4206 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4207 self.waitUntilSettled()
4208 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4209
Clark Boylandd849822015-03-02 12:38:14 -08004210 # Release jobs in order to avoid races with change A jobs
4211 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004212 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004213 self.launch_server.hold_jobs_in_build = False
4214 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004215 self.waitUntilSettled()
4216
4217 self.assertEqual(A.data['status'], 'NEW')
4218 self.assertEqual(B.data['status'], 'NEW')
4219 self.assertEqual(A.reported, 1)
4220 self.assertEqual(B.reported, 1)
4221
4222 self.assertEqual(self.history[0].changes, '1,1 2,1')
4223 self.assertEqual(self.history[1].changes, '1,1')
Paul Belanger08136962016-11-03 17:57:38 -04004224 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004225
4226 self.assertIn('Build succeeded', A.messages[0])
4227 self.assertIn('Build succeeded', B.messages[0])
4228
James E. Blairec056492016-07-22 09:45:56 -07004229 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004230 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004231 "Test cross-repo dependencies re-enqueued in independent pipelines"
4232
4233 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004234 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4235 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004236
4237 # A Depends-On: B
4238 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4239 A.subject, B.data['id'])
4240
4241 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4242 self.waitUntilSettled()
4243
4244 self.sched.reconfigure(self.config)
4245
4246 # Make sure the items still share a change queue, and the
4247 # first one is not live.
4248 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4249 queue = self.sched.layout.pipelines['check'].queues[0]
4250 first_item = queue.queue[0]
4251 for item in queue.queue:
4252 self.assertEqual(item.queue, first_item.queue)
4253 self.assertFalse(first_item.live)
4254 self.assertTrue(queue.queue[1].live)
4255
4256 self.gearman_server.hold_jobs_in_queue = False
4257 self.gearman_server.release()
4258 self.waitUntilSettled()
4259
4260 self.assertEqual(A.data['status'], 'NEW')
4261 self.assertEqual(B.data['status'], 'NEW')
4262 self.assertEqual(A.reported, 1)
4263 self.assertEqual(B.reported, 0)
4264
4265 self.assertEqual(self.history[0].changes, '2,1 1,1')
4266 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004267
James E. Blairec056492016-07-22 09:45:56 -07004268 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004269 def test_crd_check_reconfiguration(self):
4270 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4271
James E. Blairec056492016-07-22 09:45:56 -07004272 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004273 def test_crd_undefined_project(self):
4274 """Test that undefined projects in dependencies are handled for
4275 independent pipelines"""
4276 # It's a hack for fake gerrit,
4277 # as it implies repo creation upon the creation of any change
4278 self.init_repo("org/unknown")
4279 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4280
James E. Blairec056492016-07-22 09:45:56 -07004281 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004282 def test_crd_check_ignore_dependencies(self):
4283 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004284 self.updateConfigLayout(
4285 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004286 self.sched.reconfigure(self.config)
4287 self.registerJobs()
4288
4289 self.gearman_server.hold_jobs_in_queue = True
4290 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4291 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4292 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4293
4294 # A Depends-On: B
4295 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4296 A.subject, B.data['id'])
4297 # C git-depends on B
4298 C.setDependsOn(B, 1)
4299 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4300 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4301 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4302 self.waitUntilSettled()
4303
4304 # Make sure none of the items share a change queue, and all
4305 # are live.
4306 check_pipeline = self.sched.layout.pipelines['check']
4307 self.assertEqual(len(check_pipeline.queues), 3)
4308 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4309 for item in check_pipeline.getAllItems():
4310 self.assertTrue(item.live)
4311
4312 self.gearman_server.hold_jobs_in_queue = False
4313 self.gearman_server.release()
4314 self.waitUntilSettled()
4315
4316 self.assertEqual(A.data['status'], 'NEW')
4317 self.assertEqual(B.data['status'], 'NEW')
4318 self.assertEqual(C.data['status'], 'NEW')
4319 self.assertEqual(A.reported, 1)
4320 self.assertEqual(B.reported, 1)
4321 self.assertEqual(C.reported, 1)
4322
4323 # Each job should have tested exactly one change
4324 for job in self.history:
4325 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004326
James E. Blairec056492016-07-22 09:45:56 -07004327 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004328 def test_crd_check_transitive(self):
4329 "Test transitive cross-repo dependencies"
4330 # Specifically, if A -> B -> C, and C gets a new patchset and
4331 # A gets a new patchset, ensure the test of A,2 includes B,1
4332 # and C,2 (not C,1 which would indicate stale data in the
4333 # cache for B).
4334 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4335 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4336 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4337
4338 # A Depends-On: B
4339 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4340 A.subject, B.data['id'])
4341
4342 # B Depends-On: C
4343 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4344 B.subject, C.data['id'])
4345
4346 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4347 self.waitUntilSettled()
4348 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4349
4350 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4351 self.waitUntilSettled()
4352 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4353
4354 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4355 self.waitUntilSettled()
4356 self.assertEqual(self.history[-1].changes, '3,1')
4357
4358 C.addPatchset()
4359 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4360 self.waitUntilSettled()
4361 self.assertEqual(self.history[-1].changes, '3,2')
4362
4363 A.addPatchset()
4364 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4365 self.waitUntilSettled()
4366 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004367
James E. Blairec056492016-07-22 09:45:56 -07004368 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004369 def test_crd_check_unknown(self):
4370 "Test unknown projects in independent pipeline"
4371 self.init_repo("org/unknown")
4372 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4373 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4374 # A Depends-On: B
4375 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4376 A.subject, B.data['id'])
4377
4378 # Make sure zuul has seen an event on B.
4379 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4380 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4381 self.waitUntilSettled()
4382
4383 self.assertEqual(A.data['status'], 'NEW')
4384 self.assertEqual(A.reported, 1)
4385 self.assertEqual(B.data['status'], 'NEW')
4386 self.assertEqual(B.reported, 0)
4387
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004388 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004389 def test_crd_cycle_join(self):
4390 "Test an updated change creates a cycle"
4391 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4392
4393 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4394 self.waitUntilSettled()
4395
4396 # Create B->A
4397 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4398 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4399 B.subject, A.data['id'])
4400 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4401 self.waitUntilSettled()
4402
4403 # Update A to add A->B (a cycle).
4404 A.addPatchset()
4405 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4406 A.subject, B.data['id'])
4407 # Normally we would submit the patchset-created event for
4408 # processing here, however, we have no way of noting whether
4409 # the dependency cycle detection correctly raised an
4410 # exception, so instead, we reach into the source driver and
4411 # call the method that would ultimately be called by the event
4412 # processing.
4413
4414 source = self.sched.layout.pipelines['gate'].source
4415 with testtools.ExpectedException(
4416 Exception, "Dependency cycle detected"):
4417 source._getChange(u'1', u'2', True)
4418 self.log.debug("Got expected dependency cycle exception")
4419
4420 # Now if we update B to remove the depends-on, everything
4421 # should be okay. B; A->B
4422
4423 B.addPatchset()
4424 B.data['commitMessage'] = '%s\n' % (B.subject,)
4425 source._getChange(u'1', u'2', True)
4426 source._getChange(u'2', u'2', True)
4427
James E. Blairec056492016-07-22 09:45:56 -07004428 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004429 def test_disable_at(self):
4430 "Test a pipeline will only report to the disabled trigger when failing"
4431
James E. Blairf84026c2015-12-08 16:11:46 -08004432 self.updateConfigLayout(
4433 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004434 self.sched.reconfigure(self.config)
4435
4436 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4437 self.assertEqual(
4438 0, self.sched.layout.pipelines['check']._consecutive_failures)
4439 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4440
4441 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4442 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4443 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4444 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4445 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4446 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4447 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4448 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4449 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4450 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4451 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4452
James E. Blair08d19992016-08-10 15:25:31 -07004453 self.launch_server.failJob('project-test1', A)
4454 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004455 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004456 self.launch_server.failJob('project-test1', D)
4457 self.launch_server.failJob('project-test1', E)
4458 self.launch_server.failJob('project-test1', F)
4459 self.launch_server.failJob('project-test1', G)
4460 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004461 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004462 self.launch_server.failJob('project-test1', J)
4463 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004464
4465 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4466 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4467 self.waitUntilSettled()
4468
4469 self.assertEqual(
4470 2, self.sched.layout.pipelines['check']._consecutive_failures)
4471 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4472
4473 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4474 self.waitUntilSettled()
4475
4476 self.assertEqual(
4477 0, self.sched.layout.pipelines['check']._consecutive_failures)
4478 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4479
4480 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4481 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4482 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4483 self.waitUntilSettled()
4484
4485 # We should be disabled now
4486 self.assertEqual(
4487 3, self.sched.layout.pipelines['check']._consecutive_failures)
4488 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4489
4490 # We need to wait between each of these patches to make sure the
4491 # smtp messages come back in an expected order
4492 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4493 self.waitUntilSettled()
4494 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4495 self.waitUntilSettled()
4496 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4497 self.waitUntilSettled()
4498
4499 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4500 # leaving a message on each change
4501 self.assertEqual(1, len(A.messages))
4502 self.assertIn('Build failed.', A.messages[0])
4503 self.assertEqual(1, len(B.messages))
4504 self.assertIn('Build failed.', B.messages[0])
4505 self.assertEqual(1, len(C.messages))
4506 self.assertIn('Build succeeded.', C.messages[0])
4507 self.assertEqual(1, len(D.messages))
4508 self.assertIn('Build failed.', D.messages[0])
4509 self.assertEqual(1, len(E.messages))
4510 self.assertIn('Build failed.', E.messages[0])
4511 self.assertEqual(1, len(F.messages))
4512 self.assertIn('Build failed.', F.messages[0])
4513
4514 # The last 3 (GHI) would have only reported via smtp.
4515 self.assertEqual(3, len(self.smtp_messages))
4516 self.assertEqual(0, len(G.messages))
4517 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4518 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4519 self.assertEqual(0, len(H.messages))
4520 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4521 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4522 self.assertEqual(0, len(I.messages))
4523 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4524 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4525
4526 # Now reload the configuration (simulate a HUP) to check the pipeline
4527 # comes out of disabled
4528 self.sched.reconfigure(self.config)
4529
4530 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4531 self.assertEqual(
4532 0, self.sched.layout.pipelines['check']._consecutive_failures)
4533 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4534
4535 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4536 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4537 self.waitUntilSettled()
4538
4539 self.assertEqual(
4540 2, self.sched.layout.pipelines['check']._consecutive_failures)
4541 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4542
4543 # J and K went back to gerrit
4544 self.assertEqual(1, len(J.messages))
4545 self.assertIn('Build failed.', J.messages[0])
4546 self.assertEqual(1, len(K.messages))
4547 self.assertIn('Build failed.', K.messages[0])
4548 # No more messages reported via smtp
4549 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004550
James E. Blairec056492016-07-22 09:45:56 -07004551 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004552 def test_success_pattern(self):
4553 "Ensure bad build params are ignored"
4554
4555 # Use SMTP reporter to grab the result message easier
4556 self.init_repo("org/docs")
4557 self.config.set('zuul', 'layout_config',
4558 'tests/fixtures/layout-success-pattern.yaml')
4559 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004560 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004561 self.registerJobs()
4562
4563 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4564 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4565 self.waitUntilSettled()
4566
4567 # Grab build id
4568 self.assertEqual(len(self.builds), 1)
4569 uuid = self.builds[0].unique[:7]
4570
James E. Blair08d19992016-08-10 15:25:31 -07004571 self.launch_server.hold_jobs_in_build = False
4572 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004573 self.waitUntilSettled()
4574
4575 self.assertEqual(len(self.smtp_messages), 1)
4576 body = self.smtp_messages[0]['body'].splitlines()
4577 self.assertEqual('Build succeeded.', body[0])
4578
4579 self.assertIn(
4580 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4581 'docs-draft-test/%s/publish-docs/' % uuid,
4582 body[2])
4583 self.assertIn(
4584 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4585 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004586
4587
4588class TestDuplicatePipeline(ZuulTestCase):
4589 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4590
4591 def test_duplicate_pipelines(self):
4592 "Test that a change matching multiple pipelines works"
4593
4594 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4595 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4596 self.waitUntilSettled()
4597
4598 self.assertHistory([
4599 dict(name='project-test1', result='SUCCESS', changes='1,1',
4600 pipeline='dup1'),
4601 dict(name='project-test1', result='SUCCESS', changes='1,1',
4602 pipeline='dup2'),
4603 ])
4604
4605 self.assertEqual(len(A.messages), 2)
4606
4607 self.assertIn('dup1', A.messages[0])
4608 self.assertNotIn('dup2', A.messages[0])
4609 self.assertIn('project-test1', A.messages[0])
4610
4611 self.assertIn('dup2', A.messages[1])
4612 self.assertNotIn('dup1', A.messages[1])
4613 self.assertIn('project-test1', A.messages[1])
Paul Belangerfac69ba2016-11-03 09:03:13 -04004614
4615
4616class TestSchedulerOneJobProject(ZuulTestCase):
4617 tenant_config_file = 'config/one-job-project/main.yaml'
4618
4619 def test_one_job_project(self):
4620 "Test that queueing works with one job"
4621 A = self.fake_gerrit.addFakeChange('org/one-job-project',
4622 'master', 'A')
4623 B = self.fake_gerrit.addFakeChange('org/one-job-project',
4624 'master', 'B')
4625 A.addApproval('code-review', 2)
4626 B.addApproval('code-review', 2)
4627 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
4628 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
4629 self.waitUntilSettled()
4630
4631 self.assertEqual(A.data['status'], 'MERGED')
4632 self.assertEqual(A.reported, 2)
4633 self.assertEqual(B.data['status'], 'MERGED')
4634 self.assertEqual(B.reported, 2)
Paul Belanger86085b32016-11-03 12:48:57 -04004635
4636
4637class TestSchedulerTemplatedProject(ZuulTestCase):
4638 tenant_config_file = 'config/templated-project/main.yaml'
4639
4640 def test_job_from_templates_launched(self):
4641 "Test whether a job generated via a template can be launched"
4642
4643 A = self.fake_gerrit.addFakeChange(
4644 'org/templated-project', 'master', 'A')
4645 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4646 self.waitUntilSettled()
4647
4648 self.assertEqual(self.getJobFromHistory('project-test1').result,
4649 'SUCCESS')
4650 self.assertEqual(self.getJobFromHistory('project-test2').result,
4651 'SUCCESS')
Paul Belanger3adf72f2016-11-03 14:57:31 -04004652
4653 def test_layered_templates(self):
4654 "Test whether a job generated via a template can be launched"
4655
4656 A = self.fake_gerrit.addFakeChange(
4657 'org/layered-project', 'master', 'A')
4658 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4659 self.waitUntilSettled()
4660
4661 self.assertEqual(self.getJobFromHistory('project-test1').result,
4662 'SUCCESS')
4663 self.assertEqual(self.getJobFromHistory('project-test2').result,
4664 'SUCCESS')
4665 self.assertEqual(self.getJobFromHistory('layered-project-test3'
4666 ).result, 'SUCCESS')
4667 self.assertEqual(self.getJobFromHistory('layered-project-test4'
4668 ).result, 'SUCCESS')
4669 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
4670 ).result, 'SUCCESS')
4671 self.assertEqual(self.getJobFromHistory('project-test6').result,
4672 'SUCCESS')