blob: ac90d307256f9964c728b47e06c2ff080d33e99a [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. Blairec056492016-07-22 09:45:56 -0700608 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700609 def test_two_failed_changes_at_head(self):
610 "Test that changes are reparented correctly if 2 fail at head"
611
James E. Blair08d19992016-08-10 15:25:31 -0700612 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700613 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
614 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
615 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700616 A.addApproval('code-review', 2)
617 B.addApproval('code-review', 2)
618 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700619
James E. Blair08d19992016-08-10 15:25:31 -0700620 self.launch_server.failJob('project-test1', A)
621 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700622
James E. Blair8b5408c2016-08-08 15:37:46 -0700623 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
624 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
625 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700626 self.waitUntilSettled()
627
James E. Blair08d19992016-08-10 15:25:31 -0700628 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700629 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700630 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700631 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700632 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700633 self.waitUntilSettled()
634
635 self.assertEqual(len(self.builds), 6)
636 self.assertEqual(self.builds[0].name, 'project-test1')
637 self.assertEqual(self.builds[1].name, 'project-test2')
638 self.assertEqual(self.builds[2].name, 'project-test1')
639 self.assertEqual(self.builds[3].name, 'project-test2')
640 self.assertEqual(self.builds[4].name, 'project-test1')
641 self.assertEqual(self.builds[5].name, 'project-test2')
642
643 self.assertTrue(self.job_has_changes(self.builds[0], A))
644 self.assertTrue(self.job_has_changes(self.builds[2], A))
645 self.assertTrue(self.job_has_changes(self.builds[2], B))
646 self.assertTrue(self.job_has_changes(self.builds[4], A))
647 self.assertTrue(self.job_has_changes(self.builds[4], B))
648 self.assertTrue(self.job_has_changes(self.builds[4], C))
649
650 # Fail change B first
651 self.release(self.builds[2])
652 self.waitUntilSettled()
653
654 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700655 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700656 self.waitUntilSettled()
657
658 self.assertEqual(len(self.builds), 5)
659 self.assertEqual(self.builds[0].name, 'project-test1')
660 self.assertEqual(self.builds[1].name, 'project-test2')
661 self.assertEqual(self.builds[2].name, 'project-test2')
662 self.assertEqual(self.builds[3].name, 'project-test1')
663 self.assertEqual(self.builds[4].name, 'project-test2')
664
665 self.assertTrue(self.job_has_changes(self.builds[1], A))
666 self.assertTrue(self.job_has_changes(self.builds[2], A))
667 self.assertTrue(self.job_has_changes(self.builds[2], B))
668 self.assertTrue(self.job_has_changes(self.builds[4], A))
669 self.assertFalse(self.job_has_changes(self.builds[4], B))
670 self.assertTrue(self.job_has_changes(self.builds[4], C))
671
672 # Finish running all passing jobs for change A
673 self.release(self.builds[1])
674 self.waitUntilSettled()
675 # Fail and report change A
676 self.release(self.builds[0])
677 self.waitUntilSettled()
678
679 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700680 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700681 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700682 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700683 self.waitUntilSettled()
684
685 self.assertEqual(len(self.builds), 4)
686 self.assertEqual(self.builds[0].name, 'project-test1') # B
687 self.assertEqual(self.builds[1].name, 'project-test2') # B
688 self.assertEqual(self.builds[2].name, 'project-test1') # C
689 self.assertEqual(self.builds[3].name, 'project-test2') # C
690
691 self.assertFalse(self.job_has_changes(self.builds[1], A))
692 self.assertTrue(self.job_has_changes(self.builds[1], B))
693 self.assertFalse(self.job_has_changes(self.builds[1], C))
694
695 self.assertFalse(self.job_has_changes(self.builds[2], A))
696 # After A failed and B and C restarted, B should be back in
697 # C's tests because it has not failed yet.
698 self.assertTrue(self.job_has_changes(self.builds[2], B))
699 self.assertTrue(self.job_has_changes(self.builds[2], C))
700
James E. Blair08d19992016-08-10 15:25:31 -0700701 self.launch_server.hold_jobs_in_build = False
702 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700703 self.waitUntilSettled()
704
705 self.assertEqual(len(self.builds), 0)
706 self.assertEqual(len(self.history), 21)
707 self.assertEqual(A.data['status'], 'NEW')
708 self.assertEqual(B.data['status'], 'NEW')
709 self.assertEqual(C.data['status'], 'MERGED')
710 self.assertEqual(A.reported, 2)
711 self.assertEqual(B.reported, 2)
712 self.assertEqual(C.reported, 2)
713
James E. Blairec056492016-07-22 09:45:56 -0700714 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700715 def test_parse_skip_if(self):
716 job_yaml = """
717jobs:
718 - name: job_name
719 skip-if:
720 - project: ^project_name$
721 branch: ^stable/icehouse$
722 all-files-match-any:
723 - ^filename$
724 - project: ^project2_name$
725 all-files-match-any:
726 - ^filename2$
727 """.strip()
728 data = yaml.load(job_yaml)
729 config_job = data.get('jobs')[0]
730 cm = zuul.change_matcher
731 expected = cm.MatchAny([
732 cm.MatchAll([
733 cm.ProjectMatcher('^project_name$'),
734 cm.BranchMatcher('^stable/icehouse$'),
735 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
736 ]),
737 cm.MatchAll([
738 cm.ProjectMatcher('^project2_name$'),
739 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
740 ]),
741 ])
742 matcher = self.sched._parseSkipIf(config_job)
743 self.assertEqual(expected, matcher)
744
James E. Blair8c803f82012-07-31 16:25:42 -0700745 def test_patch_order(self):
746 "Test that dependent patches are tested in the right order"
747 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
748 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
749 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700750 A.addApproval('code-review', 2)
751 B.addApproval('code-review', 2)
752 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700753
754 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
755 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
756 M2.setMerged()
757 M1.setMerged()
758
759 # C -> B -> A -> M1 -> M2
760 # M2 is here to make sure it is never queried. If it is, it
761 # means zuul is walking down the entire history of merged
762 # changes.
763
764 C.setDependsOn(B, 1)
765 B.setDependsOn(A, 1)
766 A.setDependsOn(M1, 1)
767 M1.setDependsOn(M2, 1)
768
James E. Blair8b5408c2016-08-08 15:37:46 -0700769 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700770
771 self.waitUntilSettled()
772
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400773 self.assertEqual(A.data['status'], 'NEW')
774 self.assertEqual(B.data['status'], 'NEW')
775 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700776
James E. Blair8b5408c2016-08-08 15:37:46 -0700777 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
778 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700779
780 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400781 self.assertEqual(M2.queried, 0)
782 self.assertEqual(A.data['status'], 'MERGED')
783 self.assertEqual(B.data['status'], 'MERGED')
784 self.assertEqual(C.data['status'], 'MERGED')
785 self.assertEqual(A.reported, 2)
786 self.assertEqual(B.reported, 2)
787 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700788
James E. Blair063672f2015-01-29 13:09:12 -0800789 def test_needed_changes_enqueue(self):
790 "Test that a needed change is enqueued ahead"
791 # A Given a git tree like this, if we enqueue
792 # / \ change C, we should walk up and down the tree
793 # B G and enqueue changes in the order ABCDEFG.
794 # /|\ This is also the order that you would get if
795 # *C E F you enqueued changes in the order ABCDEFG, so
796 # / the ordering is stable across re-enqueue events.
797 # D
798
799 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
800 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
801 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
802 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
803 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
804 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
805 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
806 B.setDependsOn(A, 1)
807 C.setDependsOn(B, 1)
808 D.setDependsOn(C, 1)
809 E.setDependsOn(B, 1)
810 F.setDependsOn(B, 1)
811 G.setDependsOn(A, 1)
812
James E. Blair8b5408c2016-08-08 15:37:46 -0700813 A.addApproval('code-review', 2)
814 B.addApproval('code-review', 2)
815 C.addApproval('code-review', 2)
816 D.addApproval('code-review', 2)
817 E.addApproval('code-review', 2)
818 F.addApproval('code-review', 2)
819 G.addApproval('code-review', 2)
820 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800821
822 self.waitUntilSettled()
823
824 self.assertEqual(A.data['status'], 'NEW')
825 self.assertEqual(B.data['status'], 'NEW')
826 self.assertEqual(C.data['status'], 'NEW')
827 self.assertEqual(D.data['status'], 'NEW')
828 self.assertEqual(E.data['status'], 'NEW')
829 self.assertEqual(F.data['status'], 'NEW')
830 self.assertEqual(G.data['status'], 'NEW')
831
832 # We're about to add approvals to changes without adding the
833 # triggering events to Zuul, so that we can be sure that it is
834 # enqueing the changes based on dependencies, not because of
835 # triggering events. Since it will have the changes cached
836 # already (without approvals), we need to clear the cache
837 # first.
Paul Belanger593480a2016-11-02 19:06:28 -0400838 for connection in self.connections.connections.values():
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100839 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800840
James E. Blair08d19992016-08-10 15:25:31 -0700841 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700842 A.addApproval('approved', 1)
843 B.addApproval('approved', 1)
844 D.addApproval('approved', 1)
845 E.addApproval('approved', 1)
846 F.addApproval('approved', 1)
847 G.addApproval('approved', 1)
848 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800849
850 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700851 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800852 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700853 self.launch_server.hold_jobs_in_build = False
854 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800855 self.waitUntilSettled()
856
857 self.assertEqual(A.data['status'], 'MERGED')
858 self.assertEqual(B.data['status'], 'MERGED')
859 self.assertEqual(C.data['status'], 'MERGED')
860 self.assertEqual(D.data['status'], 'MERGED')
861 self.assertEqual(E.data['status'], 'MERGED')
862 self.assertEqual(F.data['status'], 'MERGED')
863 self.assertEqual(G.data['status'], 'MERGED')
864 self.assertEqual(A.reported, 2)
865 self.assertEqual(B.reported, 2)
866 self.assertEqual(C.reported, 2)
867 self.assertEqual(D.reported, 2)
868 self.assertEqual(E.reported, 2)
869 self.assertEqual(F.reported, 2)
870 self.assertEqual(G.reported, 2)
871 self.assertEqual(self.history[6].changes,
872 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
873
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100874 def test_source_cache(self):
875 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700876 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700877
878 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
879 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
880 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700881 A.addApproval('code-review', 2)
882 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700883
884 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
885 M1.setMerged()
886
887 B.setDependsOn(A, 1)
888 A.setDependsOn(M1, 1)
889
James E. Blair8b5408c2016-08-08 15:37:46 -0700890 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700891 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
892
893 self.waitUntilSettled()
894
895 for build in self.builds:
896 if build.parameters['ZUUL_PIPELINE'] == 'check':
897 build.release()
898 self.waitUntilSettled()
899 for build in self.builds:
900 if build.parameters['ZUUL_PIPELINE'] == 'check':
901 build.release()
902 self.waitUntilSettled()
903
James E. Blair8b5408c2016-08-08 15:37:46 -0700904 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700905 self.waitUntilSettled()
906
Joshua Hesketh352264b2015-08-11 23:42:08 +1000907 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700908 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000909 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700910
James E. Blair08d19992016-08-10 15:25:31 -0700911 self.launch_server.hold_jobs_in_build = False
912 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700913 self.waitUntilSettled()
914
915 self.assertEqual(A.data['status'], 'MERGED')
916 self.assertEqual(B.data['status'], 'MERGED')
917 self.assertEqual(A.queried, 2) # Initial and isMerged
918 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
919
James E. Blair8c803f82012-07-31 16:25:42 -0700920 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700921 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700922 # TODO: move to test_gerrit (this is a unit test!)
923 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Paul Belanger9bba4902016-11-02 16:07:33 -0400924 tenant = self.sched.abide.tenants.get('tenant-one')
925 source = tenant.layout.pipelines['gate'].source
926
927 # TODO(pabelanger): As we add more source / trigger APIs we should make
928 # it easier for users to create events for testing.
929 event = zuul.model.TriggerEvent()
930 event.trigger_name = 'gerrit'
931 event.change_number = '1'
932 event.patch_number = '2'
933
934 a = source.getChange(event)
935 mgr = tenant.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700936 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700937
James E. Blair8b5408c2016-08-08 15:37:46 -0700938 A.addApproval('code-review', 2)
Paul Belanger9bba4902016-11-02 16:07:33 -0400939 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700940 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700941
James E. Blair8b5408c2016-08-08 15:37:46 -0700942 A.addApproval('approved', 1)
Paul Belanger9bba4902016-11-02 16:07:33 -0400943 a = source.getChange(event, refresh=True)
James E. Blairc0dedf82014-08-06 09:37:52 -0700944 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700945
James E. Blairec056492016-07-22 09:45:56 -0700946 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700947 def test_build_configuration(self):
948 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700949
950 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700951 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
952 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
953 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700954 A.addApproval('code-review', 2)
955 B.addApproval('code-review', 2)
956 C.addApproval('code-review', 2)
957 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
958 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
959 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700960 self.waitUntilSettled()
961
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700962 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700963 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700964 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700965 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700966 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700967 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700968 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700969 ref = self.getParameter(queue[-1], 'ZUUL_REF')
970 self.gearman_server.hold_jobs_in_queue = False
971 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700972 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700973
Monty Taylorbc758832013-06-17 17:22:42 -0400974 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700975 repo = git.Repo(path)
976 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
977 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700978 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400979 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700980
James E. Blairec056492016-07-22 09:45:56 -0700981 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700982 def test_build_configuration_conflict(self):
983 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700984
985 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700986 A = self.fake_gerrit.addFakeChange('org/conflict-project',
987 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700988 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700989 B = self.fake_gerrit.addFakeChange('org/conflict-project',
990 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700991 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700992 C = self.fake_gerrit.addFakeChange('org/conflict-project',
993 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700994 A.addApproval('code-review', 2)
995 B.addApproval('code-review', 2)
996 C.addApproval('code-review', 2)
997 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
998 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
999 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -07001000 self.waitUntilSettled()
1001
James E. Blair6736beb2013-07-11 15:18:15 -07001002 self.assertEqual(A.reported, 1)
1003 self.assertEqual(B.reported, 1)
1004 self.assertEqual(C.reported, 1)
1005
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001006 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001007 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001008 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001009 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001010 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001011 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001012
1013 self.assertEqual(len(self.history), 2) # A and C merge jobs
1014
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001015 self.gearman_server.hold_jobs_in_queue = False
1016 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001017 self.waitUntilSettled()
1018
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001019 self.assertEqual(A.data['status'], 'MERGED')
1020 self.assertEqual(B.data['status'], 'NEW')
1021 self.assertEqual(C.data['status'], 'MERGED')
1022 self.assertEqual(A.reported, 2)
1023 self.assertEqual(B.reported, 2)
1024 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001025 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001026
James E. Blairec056492016-07-22 09:45:56 -07001027 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001028 def test_post(self):
1029 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001030
Zhongyue Luo5d556072012-09-21 02:00:47 +09001031 e = {
1032 "type": "ref-updated",
1033 "submitter": {
1034 "name": "User Name",
1035 },
1036 "refUpdate": {
1037 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1038 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1039 "refName": "master",
1040 "project": "org/project",
1041 }
1042 }
James E. Blairdaabed22012-08-15 15:38:57 -07001043 self.fake_gerrit.addEvent(e)
1044 self.waitUntilSettled()
1045
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001046 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001047 self.assertEqual(len(self.history), 1)
1048 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001049
James E. Blairec056492016-07-22 09:45:56 -07001050 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001051 def test_post_ignore_deletes(self):
1052 "Test that deleting refs does not trigger post jobs"
1053
1054 e = {
1055 "type": "ref-updated",
1056 "submitter": {
1057 "name": "User Name",
1058 },
1059 "refUpdate": {
1060 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1061 "newRev": "0000000000000000000000000000000000000000",
1062 "refName": "master",
1063 "project": "org/project",
1064 }
1065 }
1066 self.fake_gerrit.addEvent(e)
1067 self.waitUntilSettled()
1068
1069 job_names = [x.name for x in self.history]
1070 self.assertEqual(len(self.history), 0)
1071 self.assertNotIn('project-post', job_names)
1072
James E. Blairec056492016-07-22 09:45:56 -07001073 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001074 def test_post_ignore_deletes_negative(self):
1075 "Test that deleting refs does trigger post jobs"
1076
James E. Blairf84026c2015-12-08 16:11:46 -08001077 self.updateConfigLayout(
1078 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001079 self.sched.reconfigure(self.config)
1080
1081 e = {
1082 "type": "ref-updated",
1083 "submitter": {
1084 "name": "User Name",
1085 },
1086 "refUpdate": {
1087 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1088 "newRev": "0000000000000000000000000000000000000000",
1089 "refName": "master",
1090 "project": "org/project",
1091 }
1092 }
1093 self.fake_gerrit.addEvent(e)
1094 self.waitUntilSettled()
1095
1096 job_names = [x.name for x in self.history]
1097 self.assertEqual(len(self.history), 1)
1098 self.assertIn('project-post', job_names)
1099
James E. Blairec056492016-07-22 09:45:56 -07001100 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001101 def test_build_configuration_branch(self):
1102 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001103
1104 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001105 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1106 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1107 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001108 A.addApproval('code-review', 2)
1109 B.addApproval('code-review', 2)
1110 C.addApproval('code-review', 2)
1111 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1112 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1113 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001114 self.waitUntilSettled()
1115
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001116 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001117 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001118 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001119 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001120 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001121 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001122 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001123 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1124 self.gearman_server.hold_jobs_in_queue = False
1125 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001126 self.waitUntilSettled()
1127
Monty Taylorbc758832013-06-17 17:22:42 -04001128 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001129 repo = git.Repo(path)
1130 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1131 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001132 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001133 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001134
James E. Blairec056492016-07-22 09:45:56 -07001135 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001136 def test_build_configuration_branch_interaction(self):
1137 "Test that switching between branches works"
1138 self.test_build_configuration()
1139 self.test_build_configuration_branch()
1140 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001141 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001142 repo = git.Repo(path)
1143 repo.heads.master.commit = repo.commit('init')
1144 self.test_build_configuration()
1145
James E. Blairec056492016-07-22 09:45:56 -07001146 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001147 def test_build_configuration_multi_branch(self):
1148 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001149
1150 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001151 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1152 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1153 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001154 A.addApproval('code-review', 2)
1155 B.addApproval('code-review', 2)
1156 C.addApproval('code-review', 2)
1157 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1158 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1159 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001160 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001161 queue = self.gearman_server.getQueue()
1162 job_A = None
1163 for job in queue:
1164 if 'project-merge' in job.name:
1165 job_A = job
1166 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1167 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1168 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1169 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001170
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001171 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001172 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001173 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001174 job_B = None
1175 for job in queue:
1176 if 'project-merge' in job.name:
1177 job_B = job
1178 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001179 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001180 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001181 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1182
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001183 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001184 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001185 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001186 for job in queue:
1187 if 'project-merge' in job.name:
1188 job_C = job
1189 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001190 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001191 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001192 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001193 self.gearman_server.hold_jobs_in_queue = False
1194 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001195 self.waitUntilSettled()
1196
Monty Taylorbc758832013-06-17 17:22:42 -04001197 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001198 repo = git.Repo(path)
1199
1200 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001201 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001202 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001203 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001204 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001205 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001206 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001207 # Ensure ZUUL_REF -> ZUUL_COMMIT
1208 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001209
1210 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001211 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001212 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001213 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001214 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001215 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001216 self.assertEqual(repo_shas[0], commit_B)
1217
1218 repo_messages = [c.message.strip()
1219 for c in repo.iter_commits(ref_A)]
1220 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1221 repo_messages.reverse()
1222 correct_messages = ['initial commit', 'A-1']
1223 self.assertEqual(repo_messages, correct_messages)
1224 self.assertEqual(repo_shas[0], commit_A)
1225
1226 self.assertNotEqual(ref_A, ref_B, ref_C)
1227 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001228
James E. Blaircaec0c52012-08-22 14:52:22 -07001229 def test_dependent_changes_dequeue(self):
1230 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001231
James E. Blaircaec0c52012-08-22 14:52:22 -07001232 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1233 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1234 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001235 A.addApproval('code-review', 2)
1236 B.addApproval('code-review', 2)
1237 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001238
1239 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1240 M1.setMerged()
1241
1242 # C -> B -> A -> M1
1243
1244 C.setDependsOn(B, 1)
1245 B.setDependsOn(A, 1)
1246 A.setDependsOn(M1, 1)
1247
James E. Blair08d19992016-08-10 15:25:31 -07001248 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001249
James E. Blair8b5408c2016-08-08 15:37:46 -07001250 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1251 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1252 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001253
1254 self.waitUntilSettled()
1255
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001256 self.assertEqual(A.data['status'], 'NEW')
1257 self.assertEqual(A.reported, 2)
1258 self.assertEqual(B.data['status'], 'NEW')
1259 self.assertEqual(B.reported, 2)
1260 self.assertEqual(C.data['status'], 'NEW')
1261 self.assertEqual(C.reported, 2)
1262 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001263
James E. Blair972e3c72013-08-29 12:04:55 -07001264 def test_failing_dependent_changes(self):
1265 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001266 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001267 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1268 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1269 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1270 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1271 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001272 A.addApproval('code-review', 2)
1273 B.addApproval('code-review', 2)
1274 C.addApproval('code-review', 2)
1275 D.addApproval('code-review', 2)
1276 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001277
1278 # E, D -> C -> B, A
1279
1280 D.setDependsOn(C, 1)
1281 C.setDependsOn(B, 1)
1282
James E. Blair08d19992016-08-10 15:25:31 -07001283 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001284
James E. Blair8b5408c2016-08-08 15:37:46 -07001285 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1286 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1287 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1288 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1289 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001290
1291 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001292 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001293 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001294 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001295 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001296 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001297 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001298 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001299 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001300 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001301 self.waitUntilSettled()
1302
James E. Blair08d19992016-08-10 15:25:31 -07001303 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001304 for build in self.builds:
1305 if build.parameters['ZUUL_CHANGE'] != '1':
1306 build.release()
1307 self.waitUntilSettled()
1308
James E. Blair08d19992016-08-10 15:25:31 -07001309 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001310 self.waitUntilSettled()
1311
1312 self.assertEqual(A.data['status'], 'MERGED')
1313 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001314 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001315 self.assertEqual(B.data['status'], 'NEW')
1316 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001317 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001318 self.assertEqual(C.data['status'], 'NEW')
1319 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001320 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001321 self.assertEqual(D.data['status'], 'NEW')
1322 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001323 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001324 self.assertEqual(E.data['status'], 'MERGED')
1325 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001326 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001327 self.assertEqual(len(self.history), 18)
1328
James E. Blairec056492016-07-22 09:45:56 -07001329 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001330 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001331 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001332 # If it's dequeued more than once, we should see extra
1333 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001334
James E. Blair08d19992016-08-10 15:25:31 -07001335 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001336 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1337 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1338 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001339 A.addApproval('code-review', 2)
1340 B.addApproval('code-review', 2)
1341 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001342
James E. Blair08d19992016-08-10 15:25:31 -07001343 self.launch_server.failJob('project1-test1', A)
1344 self.launch_server.failJob('project1-test2', A)
1345 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001346
James E. Blair8b5408c2016-08-08 15:37:46 -07001347 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1348 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1349 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001350
1351 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001352
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001353 self.assertEqual(len(self.builds), 1)
1354 self.assertEqual(self.builds[0].name, 'project1-merge')
1355 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001356
James E. Blair08d19992016-08-10 15:25:31 -07001357 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001358 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001359 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001360 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001361 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001362 self.waitUntilSettled()
1363
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001364 self.assertEqual(len(self.builds), 9)
1365 self.assertEqual(self.builds[0].name, 'project1-test1')
1366 self.assertEqual(self.builds[1].name, 'project1-test2')
1367 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1368 self.assertEqual(self.builds[3].name, 'project1-test1')
1369 self.assertEqual(self.builds[4].name, 'project1-test2')
1370 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1371 self.assertEqual(self.builds[6].name, 'project1-test1')
1372 self.assertEqual(self.builds[7].name, 'project1-test2')
1373 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001374
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001375 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001376 self.waitUntilSettled()
1377
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001378 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1379 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001380
James E. Blair08d19992016-08-10 15:25:31 -07001381 self.launch_server.hold_jobs_in_build = False
1382 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001383 self.waitUntilSettled()
1384
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001385 self.assertEqual(len(self.builds), 0)
1386 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001387
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001388 self.assertEqual(A.data['status'], 'NEW')
1389 self.assertEqual(B.data['status'], 'MERGED')
1390 self.assertEqual(C.data['status'], 'MERGED')
1391 self.assertEqual(A.reported, 2)
1392 self.assertEqual(B.reported, 2)
1393 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001394
James E. Blairec056492016-07-22 09:45:56 -07001395 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001396 def test_nonvoting_job(self):
1397 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001398
James E. Blair4ec821f2012-08-23 15:28:28 -07001399 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1400 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001401 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001402 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001403 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001404
1405 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001406
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001407 self.assertEqual(A.data['status'], 'MERGED')
1408 self.assertEqual(A.reported, 2)
1409 self.assertEqual(
1410 self.getJobFromHistory('nonvoting-project-merge').result,
1411 'SUCCESS')
1412 self.assertEqual(
1413 self.getJobFromHistory('nonvoting-project-test1').result,
1414 'SUCCESS')
1415 self.assertEqual(
1416 self.getJobFromHistory('nonvoting-project-test2').result,
1417 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001418
James E. Blair5821bd92015-09-16 08:48:15 -07001419 for build in self.builds:
1420 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1421
James E. Blaire0487072012-08-29 17:38:31 -07001422 def test_check_queue_success(self):
1423 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001424
James E. Blaire0487072012-08-29 17:38:31 -07001425 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1426 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1427
1428 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001429
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001430 self.assertEqual(A.data['status'], 'NEW')
1431 self.assertEqual(A.reported, 1)
1432 self.assertEqual(self.getJobFromHistory('project-merge').result,
1433 'SUCCESS')
1434 self.assertEqual(self.getJobFromHistory('project-test1').result,
1435 'SUCCESS')
1436 self.assertEqual(self.getJobFromHistory('project-test2').result,
1437 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001438
1439 def test_check_queue_failure(self):
1440 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001441
James E. Blaire0487072012-08-29 17:38:31 -07001442 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001443 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001444 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1445
1446 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001447
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001448 self.assertEqual(A.data['status'], 'NEW')
1449 self.assertEqual(A.reported, 1)
1450 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001451 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001452 self.assertEqual(self.getJobFromHistory('project-test1').result,
1453 'SUCCESS')
1454 self.assertEqual(self.getJobFromHistory('project-test2').result,
1455 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001456
James E. Blairec056492016-07-22 09:45:56 -07001457 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001458 def test_dependent_behind_dequeue(self):
1459 "test that dependent changes behind dequeued changes work"
1460 # This complicated test is a reproduction of a real life bug
1461 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001462
James E. Blair08d19992016-08-10 15:25:31 -07001463 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001464 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1465 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1466 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1467 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1468 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1469 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1470 D.setDependsOn(C, 1)
1471 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001472 A.addApproval('code-review', 2)
1473 B.addApproval('code-review', 2)
1474 C.addApproval('code-review', 2)
1475 D.addApproval('code-review', 2)
1476 E.addApproval('code-review', 2)
1477 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001478
1479 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001480
1481 # Change object re-use in the gerrit trigger is hidden if
1482 # changes are added in quick succession; waiting makes it more
1483 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001484 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001485 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001486 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001487 self.waitUntilSettled()
1488
James E. Blair08d19992016-08-10 15:25:31 -07001489 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001490 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001491 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001492 self.waitUntilSettled()
1493
James E. Blair8b5408c2016-08-08 15:37:46 -07001494 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001495 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001496 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001497 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001498 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001499 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001500 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001501 self.waitUntilSettled()
1502
James E. Blair08d19992016-08-10 15:25:31 -07001503 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001504 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001505 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001506 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001507 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001508 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001509 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001510 self.waitUntilSettled()
1511
1512 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001513
1514 # Grab pointers to the jobs we want to release before
1515 # releasing any, because list indexes may change as
1516 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001517 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001518 a.release()
1519 b.release()
1520 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001521 self.waitUntilSettled()
1522
James E. Blair08d19992016-08-10 15:25:31 -07001523 self.launch_server.hold_jobs_in_build = False
1524 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001525 self.waitUntilSettled()
1526
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001527 self.assertEqual(A.data['status'], 'NEW')
1528 self.assertEqual(B.data['status'], 'MERGED')
1529 self.assertEqual(C.data['status'], 'MERGED')
1530 self.assertEqual(D.data['status'], 'MERGED')
1531 self.assertEqual(E.data['status'], 'MERGED')
1532 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001533
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001534 self.assertEqual(A.reported, 2)
1535 self.assertEqual(B.reported, 2)
1536 self.assertEqual(C.reported, 2)
1537 self.assertEqual(D.reported, 2)
1538 self.assertEqual(E.reported, 2)
1539 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001540
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001541 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1542 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001543
James E. Blairec056492016-07-22 09:45:56 -07001544 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001545 def test_merger_repack(self):
1546 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001547
James E. Blair05fed602012-09-07 12:45:24 -07001548 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001549 A.addApproval('code-review', 2)
1550 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001551 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001552 self.assertEqual(self.getJobFromHistory('project-merge').result,
1553 'SUCCESS')
1554 self.assertEqual(self.getJobFromHistory('project-test1').result,
1555 'SUCCESS')
1556 self.assertEqual(self.getJobFromHistory('project-test2').result,
1557 'SUCCESS')
1558 self.assertEqual(A.data['status'], 'MERGED')
1559 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001560 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001561 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001562
Monty Taylorbc758832013-06-17 17:22:42 -04001563 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001564 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001565
1566 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001567 A.addApproval('code-review', 2)
1568 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001569 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001570 self.assertEqual(self.getJobFromHistory('project-merge').result,
1571 'SUCCESS')
1572 self.assertEqual(self.getJobFromHistory('project-test1').result,
1573 'SUCCESS')
1574 self.assertEqual(self.getJobFromHistory('project-test2').result,
1575 'SUCCESS')
1576 self.assertEqual(A.data['status'], 'MERGED')
1577 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001578
James E. Blairec056492016-07-22 09:45:56 -07001579 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001580 def test_merger_repack_large_change(self):
1581 "Test that the merger works with large changes after a repack"
1582 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001583 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001584 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001585 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001586 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001587 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1588 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001589 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001590 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001591 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001592 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001593
James E. Blair8b5408c2016-08-08 15:37:46 -07001594 A.addApproval('code-review', 2)
1595 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001596 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001597 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1598 'SUCCESS')
1599 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1600 'SUCCESS')
1601 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1602 'SUCCESS')
1603 self.assertEqual(A.data['status'], 'MERGED')
1604 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001605
James E. Blairec056492016-07-22 09:45:56 -07001606 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001607 def test_nonexistent_job(self):
1608 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001609 # Set to the state immediately after a restart
1610 self.resetGearmanServer()
1611 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001612
1613 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001614 A.addApproval('code-review', 2)
1615 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001616 # There may be a thread about to report a lost change
1617 while A.reported < 2:
1618 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001619 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001620 self.assertFalse(job_names)
1621 self.assertEqual(A.data['status'], 'NEW')
1622 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001623 self.assertEmptyQueues()
1624
1625 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001626 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001627 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001628 A.addApproval('code-review', 2)
1629 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001630 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001631 self.assertEqual(self.getJobFromHistory('project-merge').result,
1632 'SUCCESS')
1633 self.assertEqual(self.getJobFromHistory('project-test1').result,
1634 'SUCCESS')
1635 self.assertEqual(self.getJobFromHistory('project-test2').result,
1636 'SUCCESS')
1637 self.assertEqual(A.data['status'], 'MERGED')
1638 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001639
James E. Blair2fa50962013-01-30 21:50:41 -08001640 def test_new_patchset_dequeues_old(self):
1641 "Test that a new patchset causes the old to be dequeued"
1642 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001643 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001644 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1645 M.setMerged()
1646
1647 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1648 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1649 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1650 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001651 A.addApproval('code-review', 2)
1652 B.addApproval('code-review', 2)
1653 C.addApproval('code-review', 2)
1654 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001655
1656 C.setDependsOn(B, 1)
1657 B.setDependsOn(A, 1)
1658 A.setDependsOn(M, 1)
1659
James E. Blair8b5408c2016-08-08 15:37:46 -07001660 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1661 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1662 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1663 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001664 self.waitUntilSettled()
1665
1666 B.addPatchset()
1667 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1668 self.waitUntilSettled()
1669
James E. Blair08d19992016-08-10 15:25:31 -07001670 self.launch_server.hold_jobs_in_build = False
1671 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001672 self.waitUntilSettled()
1673
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001674 self.assertEqual(A.data['status'], 'MERGED')
1675 self.assertEqual(A.reported, 2)
1676 self.assertEqual(B.data['status'], 'NEW')
1677 self.assertEqual(B.reported, 2)
1678 self.assertEqual(C.data['status'], 'NEW')
1679 self.assertEqual(C.reported, 2)
1680 self.assertEqual(D.data['status'], 'MERGED')
1681 self.assertEqual(D.reported, 2)
1682 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001683
James E. Blairba437362015-02-07 11:41:52 -08001684 def test_new_patchset_check(self):
1685 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001686
James E. Blair08d19992016-08-10 15:25:31 -07001687 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001688
1689 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001690 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Paul Belanger18e5f632016-11-03 15:24:16 -04001691 tenant = self.sched.abide.tenants.get('tenant-one')
1692 check_pipeline = tenant.layout.pipelines['check']
James E. Blairba437362015-02-07 11:41:52 -08001693
1694 # Add two git-dependent changes
1695 B.setDependsOn(A, 1)
1696 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1697 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001698 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1699 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001700
1701 # A live item, and a non-live/live pair
1702 items = check_pipeline.getAllItems()
1703 self.assertEqual(len(items), 3)
1704
1705 self.assertEqual(items[0].change.number, '1')
1706 self.assertEqual(items[0].change.patchset, '1')
1707 self.assertFalse(items[0].live)
1708
1709 self.assertEqual(items[1].change.number, '2')
1710 self.assertEqual(items[1].change.patchset, '1')
1711 self.assertTrue(items[1].live)
1712
1713 self.assertEqual(items[2].change.number, '1')
1714 self.assertEqual(items[2].change.patchset, '1')
1715 self.assertTrue(items[2].live)
1716
1717 # Add a new patchset to A
1718 A.addPatchset()
1719 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1720 self.waitUntilSettled()
1721
1722 # The live copy of A,1 should be gone, but the non-live and B
1723 # should continue, and we should have a new A,2
1724 items = check_pipeline.getAllItems()
1725 self.assertEqual(len(items), 3)
1726
1727 self.assertEqual(items[0].change.number, '1')
1728 self.assertEqual(items[0].change.patchset, '1')
1729 self.assertFalse(items[0].live)
1730
1731 self.assertEqual(items[1].change.number, '2')
1732 self.assertEqual(items[1].change.patchset, '1')
1733 self.assertTrue(items[1].live)
1734
1735 self.assertEqual(items[2].change.number, '1')
1736 self.assertEqual(items[2].change.patchset, '2')
1737 self.assertTrue(items[2].live)
1738
1739 # Add a new patchset to B
1740 B.addPatchset()
1741 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1742 self.waitUntilSettled()
1743
1744 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1745 # but we should have a new B,2 (still based on A,1)
1746 items = check_pipeline.getAllItems()
1747 self.assertEqual(len(items), 3)
1748
1749 self.assertEqual(items[0].change.number, '1')
1750 self.assertEqual(items[0].change.patchset, '2')
1751 self.assertTrue(items[0].live)
1752
1753 self.assertEqual(items[1].change.number, '1')
1754 self.assertEqual(items[1].change.patchset, '1')
1755 self.assertFalse(items[1].live)
1756
1757 self.assertEqual(items[2].change.number, '2')
1758 self.assertEqual(items[2].change.patchset, '2')
1759 self.assertTrue(items[2].live)
1760
1761 self.builds[0].release()
1762 self.waitUntilSettled()
1763 self.builds[0].release()
1764 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001765 self.launch_server.hold_jobs_in_build = False
1766 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001767 self.waitUntilSettled()
1768
1769 self.assertEqual(A.reported, 1)
1770 self.assertEqual(B.reported, 1)
1771 self.assertEqual(self.history[0].result, 'ABORTED')
1772 self.assertEqual(self.history[0].changes, '1,1')
1773 self.assertEqual(self.history[1].result, 'ABORTED')
1774 self.assertEqual(self.history[1].changes, '1,1 2,1')
1775 self.assertEqual(self.history[2].result, 'SUCCESS')
1776 self.assertEqual(self.history[2].changes, '1,2')
1777 self.assertEqual(self.history[3].result, 'SUCCESS')
1778 self.assertEqual(self.history[3].changes, '1,1 2,2')
1779
1780 def test_abandoned_gate(self):
1781 "Test that an abandoned change is dequeued from gate"
1782
James E. Blair08d19992016-08-10 15:25:31 -07001783 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001784
1785 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001786 A.addApproval('code-review', 2)
1787 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001788 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001789 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1790 self.assertEqual(self.builds[0].name, 'project-merge')
1791
1792 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1793 self.waitUntilSettled()
1794
James E. Blair08d19992016-08-10 15:25:31 -07001795 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001796 self.waitUntilSettled()
1797
Arie5b4048c2016-10-05 16:12:06 +03001798 self.assertBuilds([])
1799 self.assertHistory([
1800 dict(name='project-merge', result='ABORTED', changes='1,1')],
1801 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001802 self.assertEqual(A.reported, 1,
1803 "Abandoned gate change should report only start")
1804
1805 def test_abandoned_check(self):
1806 "Test that an abandoned change is dequeued from check"
1807
James E. Blair08d19992016-08-10 15:25:31 -07001808 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001809
1810 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1811 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
Paul Belanger18e5f632016-11-03 15:24:16 -04001812 tenant = self.sched.abide.tenants.get('tenant-one')
1813 check_pipeline = tenant.layout.pipelines['check']
James E. Blairba437362015-02-07 11:41:52 -08001814
1815 # Add two git-dependent changes
1816 B.setDependsOn(A, 1)
1817 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1818 self.waitUntilSettled()
1819 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1820 self.waitUntilSettled()
1821 # A live item, and a non-live/live pair
1822 items = check_pipeline.getAllItems()
1823 self.assertEqual(len(items), 3)
1824
1825 self.assertEqual(items[0].change.number, '1')
1826 self.assertFalse(items[0].live)
1827
1828 self.assertEqual(items[1].change.number, '2')
1829 self.assertTrue(items[1].live)
1830
1831 self.assertEqual(items[2].change.number, '1')
1832 self.assertTrue(items[2].live)
1833
1834 # Abandon A
1835 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1836 self.waitUntilSettled()
1837
1838 # The live copy of A should be gone, but the non-live and B
1839 # should continue
1840 items = check_pipeline.getAllItems()
1841 self.assertEqual(len(items), 2)
1842
1843 self.assertEqual(items[0].change.number, '1')
1844 self.assertFalse(items[0].live)
1845
1846 self.assertEqual(items[1].change.number, '2')
1847 self.assertTrue(items[1].live)
1848
James E. Blair08d19992016-08-10 15:25:31 -07001849 self.launch_server.hold_jobs_in_build = False
1850 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001851 self.waitUntilSettled()
1852
1853 self.assertEqual(len(self.history), 4)
1854 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001855 'Build should have been aborted')
1856 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001857 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001858
James E. Blairec056492016-07-22 09:45:56 -07001859 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001860 def test_abandoned_not_timer(self):
1861 "Test that an abandoned change does not cancel timer jobs"
1862
James E. Blair08d19992016-08-10 15:25:31 -07001863 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001864
1865 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001866 self.updateConfigLayout(
1867 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001868 self.sched.reconfigure(self.config)
1869 self.registerJobs()
1870 # The pipeline triggers every second, so we should have seen
1871 # several by now.
1872 time.sleep(5)
1873 self.waitUntilSettled()
1874 # Stop queuing timer triggered jobs so that the assertions
1875 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001876 self.updateConfigLayout(
1877 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001878 self.sched.reconfigure(self.config)
1879 self.registerJobs()
1880 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1881
1882 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1883 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1884 self.waitUntilSettled()
1885 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1886
1887 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1888 self.waitUntilSettled()
1889
1890 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1891
James E. Blair08d19992016-08-10 15:25:31 -07001892 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001893 self.waitUntilSettled()
1894
Arx Cruzb1b010d2013-10-28 19:49:59 -02001895 def test_zuul_url_return(self):
1896 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001897 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001898 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001899
1900 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001901 A.addApproval('code-review', 2)
1902 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001903 self.waitUntilSettled()
1904
1905 self.assertEqual(len(self.builds), 1)
1906 for build in self.builds:
1907 self.assertTrue('ZUUL_URL' in build.parameters)
1908
James E. Blair08d19992016-08-10 15:25:31 -07001909 self.launch_server.hold_jobs_in_build = False
1910 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001911 self.waitUntilSettled()
1912
James E. Blair2fa50962013-01-30 21:50:41 -08001913 def test_new_patchset_dequeues_old_on_head(self):
1914 "Test that a new patchset causes the old to be dequeued (at head)"
1915 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001916 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001917 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1918 M.setMerged()
1919 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1920 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1921 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1922 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001923 A.addApproval('code-review', 2)
1924 B.addApproval('code-review', 2)
1925 C.addApproval('code-review', 2)
1926 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001927
1928 C.setDependsOn(B, 1)
1929 B.setDependsOn(A, 1)
1930 A.setDependsOn(M, 1)
1931
James E. Blair8b5408c2016-08-08 15:37:46 -07001932 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1933 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1934 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1935 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001936 self.waitUntilSettled()
1937
1938 A.addPatchset()
1939 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1940 self.waitUntilSettled()
1941
James E. Blair08d19992016-08-10 15:25:31 -07001942 self.launch_server.hold_jobs_in_build = False
1943 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001944 self.waitUntilSettled()
1945
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001946 self.assertEqual(A.data['status'], 'NEW')
1947 self.assertEqual(A.reported, 2)
1948 self.assertEqual(B.data['status'], 'NEW')
1949 self.assertEqual(B.reported, 2)
1950 self.assertEqual(C.data['status'], 'NEW')
1951 self.assertEqual(C.reported, 2)
1952 self.assertEqual(D.data['status'], 'MERGED')
1953 self.assertEqual(D.reported, 2)
1954 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08001955
1956 def test_new_patchset_dequeues_old_without_dependents(self):
1957 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07001958 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001959 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1960 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1961 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001962 A.addApproval('code-review', 2)
1963 B.addApproval('code-review', 2)
1964 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001965
James E. Blair8b5408c2016-08-08 15:37:46 -07001966 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1967 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1968 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001969 self.waitUntilSettled()
1970
1971 B.addPatchset()
1972 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1973 self.waitUntilSettled()
1974
James E. Blair08d19992016-08-10 15:25:31 -07001975 self.launch_server.hold_jobs_in_build = False
1976 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001977 self.waitUntilSettled()
1978
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001979 self.assertEqual(A.data['status'], 'MERGED')
1980 self.assertEqual(A.reported, 2)
1981 self.assertEqual(B.data['status'], 'NEW')
1982 self.assertEqual(B.reported, 2)
1983 self.assertEqual(C.data['status'], 'MERGED')
1984 self.assertEqual(C.reported, 2)
1985 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08001986
1987 def test_new_patchset_dequeues_old_independent_queue(self):
1988 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07001989 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001990 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1991 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1992 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1993 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1994 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1995 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
1996 self.waitUntilSettled()
1997
1998 B.addPatchset()
1999 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2000 self.waitUntilSettled()
2001
James E. Blair08d19992016-08-10 15:25:31 -07002002 self.launch_server.hold_jobs_in_build = False
2003 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002004 self.waitUntilSettled()
2005
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002006 self.assertEqual(A.data['status'], 'NEW')
2007 self.assertEqual(A.reported, 1)
2008 self.assertEqual(B.data['status'], 'NEW')
2009 self.assertEqual(B.reported, 1)
2010 self.assertEqual(C.data['status'], 'NEW')
2011 self.assertEqual(C.reported, 1)
2012 self.assertEqual(len(self.history), 10)
2013 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002014
James E. Blairec056492016-07-22 09:45:56 -07002015 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002016 def test_noop_job(self):
2017 "Test that the internal noop job works"
2018 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002019 A.addApproval('code-review', 2)
2020 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002021 self.waitUntilSettled()
2022
2023 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2024 self.assertTrue(self.sched._areAllBuildsComplete())
2025 self.assertEqual(len(self.history), 0)
2026 self.assertEqual(A.data['status'], 'MERGED')
2027 self.assertEqual(A.reported, 2)
2028
James E. Blairec056492016-07-22 09:45:56 -07002029 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002030 def test_no_job_project(self):
2031 "Test that reports with no jobs don't get sent"
2032 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2033 'master', 'A')
2034 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2035 self.waitUntilSettled()
2036
2037 # Change wasn't reported to
2038 self.assertEqual(A.reported, False)
2039
2040 # Check queue is empty afterwards
2041 check_pipeline = self.sched.layout.pipelines['check']
2042 items = check_pipeline.getAllItems()
2043 self.assertEqual(len(items), 0)
2044
2045 self.assertEqual(len(self.history), 0)
2046
James E. Blairec056492016-07-22 09:45:56 -07002047 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002048 def test_zuul_refs(self):
2049 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002050 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002051 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2052 M1.setMerged()
2053 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2054 M2.setMerged()
2055
2056 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2057 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2058 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2059 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002060 A.addApproval('code-review', 2)
2061 B.addApproval('code-review', 2)
2062 C.addApproval('code-review', 2)
2063 D.addApproval('code-review', 2)
2064 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2065 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2066 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2067 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002068
2069 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002070 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002071 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002072 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002073 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002074 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002075 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002076 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002077 self.waitUntilSettled()
2078
James E. Blair7d0dedc2013-02-21 17:26:09 -08002079 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002080 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002081 if x.parameters['ZUUL_CHANGE'] == '3':
2082 a_zref = x.parameters['ZUUL_REF']
2083 if x.parameters['ZUUL_CHANGE'] == '4':
2084 b_zref = x.parameters['ZUUL_REF']
2085 if x.parameters['ZUUL_CHANGE'] == '5':
2086 c_zref = x.parameters['ZUUL_REF']
2087 if x.parameters['ZUUL_CHANGE'] == '6':
2088 d_zref = x.parameters['ZUUL_REF']
2089
2090 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002091 self.assertIsNotNone(a_zref)
2092 self.assertIsNotNone(b_zref)
2093 self.assertIsNotNone(c_zref)
2094 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002095
2096 # And they should all be different
2097 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002098 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002099
2100 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002101 self.assertTrue(self.ref_has_change(a_zref, A))
2102 self.assertFalse(self.ref_has_change(a_zref, B))
2103 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002104
2105 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002106 self.assertTrue(self.ref_has_change(b_zref, A))
2107 self.assertTrue(self.ref_has_change(b_zref, B))
2108 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002109
2110 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002111 self.assertTrue(self.ref_has_change(c_zref, A))
2112 self.assertTrue(self.ref_has_change(c_zref, B))
2113 self.assertTrue(self.ref_has_change(c_zref, C))
2114 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002115
2116 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002117 self.assertTrue(self.ref_has_change(d_zref, A))
2118 self.assertTrue(self.ref_has_change(d_zref, B))
2119 self.assertTrue(self.ref_has_change(d_zref, C))
2120 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002121
James E. Blair08d19992016-08-10 15:25:31 -07002122 self.launch_server.hold_jobs_in_build = False
2123 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002124 self.waitUntilSettled()
2125
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002126 self.assertEqual(A.data['status'], 'MERGED')
2127 self.assertEqual(A.reported, 2)
2128 self.assertEqual(B.data['status'], 'MERGED')
2129 self.assertEqual(B.reported, 2)
2130 self.assertEqual(C.data['status'], 'MERGED')
2131 self.assertEqual(C.reported, 2)
2132 self.assertEqual(D.data['status'], 'MERGED')
2133 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002134
James E. Blairec056492016-07-22 09:45:56 -07002135 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002136 def test_rerun_on_error(self):
2137 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002138 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002139 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002140 A.addApproval('code-review', 2)
2141 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002142 self.waitUntilSettled()
2143
2144 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002145 self.launch_server.hold_jobs_in_build = False
2146 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002147 self.waitUntilSettled()
2148 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2149 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2150
James E. Blair412e5582013-04-22 15:50:12 -07002151 def test_statsd(self):
2152 "Test each of the statsd methods used in the scheduler"
2153 import extras
2154 statsd = extras.try_import('statsd.statsd')
2155 statsd.incr('test-incr')
2156 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002157 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002158 self.assertReportedStat('test-incr', '1|c')
2159 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002160 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002161
James E. Blairec056492016-07-22 09:45:56 -07002162 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002163 def test_stuck_job_cleanup(self):
2164 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002165 # This job won't be registered at startup because it is not in
2166 # the standard layout, but we need it to already be registerd
2167 # for when we reconfigure, as that is when Zuul will attempt
2168 # to run the new job.
2169 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002170 self.gearman_server.hold_jobs_in_queue = True
2171 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002172 A.addApproval('code-review', 2)
2173 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002174 self.waitUntilSettled()
2175 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2176
James E. Blairf84026c2015-12-08 16:11:46 -08002177 self.updateConfigLayout(
2178 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002179 self.sched.reconfigure(self.config)
2180 self.waitUntilSettled()
2181
James E. Blair18c64442014-03-18 10:14:45 -07002182 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002183 self.waitUntilSettled()
2184 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2185 self.assertTrue(self.sched._areAllBuildsComplete())
2186
2187 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002188 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002189 self.assertEqual(self.history[0].result, 'SUCCESS')
2190
James E. Blairec056492016-07-22 09:45:56 -07002191 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002192 def test_file_head(self):
2193 # This is a regression test for an observed bug. A change
2194 # with a file named "HEAD" in the root directory of the repo
2195 # was processed by a merger. It then was unable to reset the
2196 # repo because of:
2197 # GitCommandError: 'git reset --hard HEAD' returned
2198 # with exit code 128
2199 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2200 # and filename
2201 # Use '--' to separate filenames from revisions'
2202
2203 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2204 A.addPatchset(['HEAD'])
2205 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2206
2207 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2208 self.waitUntilSettled()
2209
2210 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2211 self.waitUntilSettled()
2212
2213 self.assertIn('Build succeeded', A.messages[0])
2214 self.assertIn('Build succeeded', B.messages[0])
2215
James E. Blairec056492016-07-22 09:45:56 -07002216 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002217 def test_file_jobs(self):
2218 "Test that file jobs run only when appropriate"
2219 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2220 A.addPatchset(['pip-requires'])
2221 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002222 A.addApproval('code-review', 2)
2223 B.addApproval('code-review', 2)
2224 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2225 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002226 self.waitUntilSettled()
2227
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002228 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002229 if x.name == 'project-testfile']
2230
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002231 self.assertEqual(len(testfile_jobs), 1)
2232 self.assertEqual(testfile_jobs[0].changes, '1,2')
2233 self.assertEqual(A.data['status'], 'MERGED')
2234 self.assertEqual(A.reported, 2)
2235 self.assertEqual(B.data['status'], 'MERGED')
2236 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002237
James E. Blairec056492016-07-22 09:45:56 -07002238 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002239 def _test_skip_if_jobs(self, branch, should_skip):
2240 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002241 self.updateConfigLayout(
2242 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002243 self.sched.reconfigure(self.config)
2244 self.registerJobs()
2245
2246 change = self.fake_gerrit.addFakeChange('org/project',
2247 branch,
2248 'test skip-if')
2249 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2250 self.waitUntilSettled()
2251
2252 tested_change_ids = [x.changes[0] for x in self.history
2253 if x.name == 'project-test-skip-if']
2254
2255 if should_skip:
2256 self.assertEqual([], tested_change_ids)
2257 else:
2258 self.assertIn(change.data['number'], tested_change_ids)
2259
James E. Blairec056492016-07-22 09:45:56 -07002260 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002261 def test_skip_if_match_skips_job(self):
2262 self._test_skip_if_jobs(branch='master', should_skip=True)
2263
James E. Blairec056492016-07-22 09:45:56 -07002264 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002265 def test_skip_if_no_match_runs_job(self):
2266 self._test_skip_if_jobs(branch='mp', should_skip=False)
2267
James E. Blairec056492016-07-22 09:45:56 -07002268 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002269 def test_test_config(self):
2270 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002271 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002272 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002273
James E. Blairec056492016-07-22 09:45:56 -07002274 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002275 def test_queue_names(self):
2276 "Test shared change queue names"
2277 project1 = self.sched.layout.projects['org/project1']
2278 project2 = self.sched.layout.projects['org/project2']
2279 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2280 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2281 self.assertEqual(q1.name, 'integration')
2282 self.assertEqual(q2.name, 'integration')
2283
James E. Blairf84026c2015-12-08 16:11:46 -08002284 self.updateConfigLayout(
2285 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002286 with testtools.ExpectedException(
2287 Exception, "More than one name assigned to change queue"):
2288 self.sched.reconfigure(self.config)
2289
James E. Blairec056492016-07-22 09:45:56 -07002290 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002291 def test_queue_precedence(self):
2292 "Test that queue precedence works"
2293
2294 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002295 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002296 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2297 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002298 A.addApproval('code-review', 2)
2299 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002300
2301 self.waitUntilSettled()
2302 self.gearman_server.hold_jobs_in_queue = False
2303 self.gearman_server.release()
2304 self.waitUntilSettled()
2305
James E. Blair8de58bd2013-07-18 16:23:33 -07002306 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002307 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002308 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002309 self.waitUntilSettled()
2310
James E. Blair64ed6f22013-07-10 14:07:23 -07002311 self.log.debug(self.history)
2312 self.assertEqual(self.history[0].pipeline, 'gate')
2313 self.assertEqual(self.history[1].pipeline, 'check')
2314 self.assertEqual(self.history[2].pipeline, 'gate')
2315 self.assertEqual(self.history[3].pipeline, 'gate')
2316 self.assertEqual(self.history[4].pipeline, 'check')
2317 self.assertEqual(self.history[5].pipeline, 'check')
2318
James E. Blairec056492016-07-22 09:45:56 -07002319 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002320 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002321 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002322 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002323 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002324 A.addApproval('code-review', 2)
2325 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002326 self.waitUntilSettled()
2327
James E. Blair08d19992016-08-10 15:25:31 -07002328 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002329 self.waitUntilSettled()
2330
James E. Blair1843a552013-07-03 14:19:52 -07002331 port = self.webapp.server.socket.getsockname()[1]
2332
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002333 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2334 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002335 headers = f.info()
2336 self.assertIn('Content-Length', headers)
2337 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002338 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2339 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002340 self.assertIn('Access-Control-Allow-Origin', headers)
2341 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002342 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002343 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002344 data = f.read()
2345
James E. Blair08d19992016-08-10 15:25:31 -07002346 self.launch_server.hold_jobs_in_build = False
2347 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002348 self.waitUntilSettled()
2349
2350 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002351 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002352 for p in data['pipelines']:
2353 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002354 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002355 self.assertEqual(q['window'], 20)
2356 else:
2357 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002358 for head in q['heads']:
2359 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002360 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002361 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002362 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002363 status_jobs.append(job)
2364 self.assertEqual('project-merge', status_jobs[0]['name'])
2365 self.assertEqual('https://server/job/project-merge/0/',
2366 status_jobs[0]['url'])
2367 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2368 status_jobs[0]['report_url'])
2369
2370 self.assertEqual('project-test1', status_jobs[1]['name'])
2371 self.assertEqual('https://server/job/project-test1/1/',
2372 status_jobs[1]['url'])
2373 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2374 status_jobs[1]['report_url'])
2375
2376 self.assertEqual('project-test2', status_jobs[2]['name'])
2377 self.assertEqual('https://server/job/project-test2/2/',
2378 status_jobs[2]['url'])
2379 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2380 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002381
James E. Blairec056492016-07-22 09:45:56 -07002382 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002383 def test_merging_queues(self):
2384 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002385 self.updateConfigLayout(
2386 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002387 self.sched.reconfigure(self.config)
2388 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2389
James E. Blairec056492016-07-22 09:45:56 -07002390 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002391 def test_mutex(self):
2392 "Test job mutexes"
2393 self.config.set('zuul', 'layout_config',
2394 'tests/fixtures/layout-mutex.yaml')
2395 self.sched.reconfigure(self.config)
2396
James E. Blair08d19992016-08-10 15:25:31 -07002397 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002398 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2399 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2400 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2401
2402 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2403 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2404 self.waitUntilSettled()
2405 self.assertEqual(len(self.builds), 3)
2406 self.assertEqual(self.builds[0].name, 'project-test1')
2407 self.assertEqual(self.builds[1].name, 'mutex-one')
2408 self.assertEqual(self.builds[2].name, 'project-test1')
2409
James E. Blair08d19992016-08-10 15:25:31 -07002410 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002411 self.waitUntilSettled()
2412
2413 self.assertEqual(len(self.builds), 3)
2414 self.assertEqual(self.builds[0].name, 'project-test1')
2415 self.assertEqual(self.builds[1].name, 'project-test1')
2416 self.assertEqual(self.builds[2].name, 'mutex-two')
2417 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2418
James E. Blair08d19992016-08-10 15:25:31 -07002419 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002420 self.waitUntilSettled()
2421
2422 self.assertEqual(len(self.builds), 3)
2423 self.assertEqual(self.builds[0].name, 'project-test1')
2424 self.assertEqual(self.builds[1].name, 'project-test1')
2425 self.assertEqual(self.builds[2].name, 'mutex-one')
2426 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2427
James E. Blair08d19992016-08-10 15:25:31 -07002428 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002429 self.waitUntilSettled()
2430
2431 self.assertEqual(len(self.builds), 3)
2432 self.assertEqual(self.builds[0].name, 'project-test1')
2433 self.assertEqual(self.builds[1].name, 'project-test1')
2434 self.assertEqual(self.builds[2].name, 'mutex-two')
2435 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2436
James E. Blair08d19992016-08-10 15:25:31 -07002437 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002438 self.waitUntilSettled()
2439
2440 self.assertEqual(len(self.builds), 2)
2441 self.assertEqual(self.builds[0].name, 'project-test1')
2442 self.assertEqual(self.builds[1].name, 'project-test1')
2443 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2444
James E. Blair08d19992016-08-10 15:25:31 -07002445 self.launch_server.hold_jobs_in_build = False
2446 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002447
2448 self.waitUntilSettled()
2449 self.assertEqual(len(self.builds), 0)
2450
2451 self.assertEqual(A.reported, 1)
2452 self.assertEqual(B.reported, 1)
2453 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2454
James E. Blairec056492016-07-22 09:45:56 -07002455 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002456 def test_node_label(self):
2457 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002458 self.worker.registerFunction('build:node-project-test1:debian')
2459
2460 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002461 A.addApproval('code-review', 2)
2462 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002463 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002464
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002465 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2466 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2467 'debian')
2468 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002469
James E. Blairec056492016-07-22 09:45:56 -07002470 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002471 def test_live_reconfiguration(self):
2472 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002473 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002474 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002475 A.addApproval('code-review', 2)
2476 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002477 self.waitUntilSettled()
2478
2479 self.sched.reconfigure(self.config)
2480
James E. Blair08d19992016-08-10 15:25:31 -07002481 self.launch_server.hold_jobs_in_build = False
2482 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002483 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002484 self.assertEqual(self.getJobFromHistory('project-merge').result,
2485 'SUCCESS')
2486 self.assertEqual(self.getJobFromHistory('project-test1').result,
2487 'SUCCESS')
2488 self.assertEqual(self.getJobFromHistory('project-test2').result,
2489 'SUCCESS')
2490 self.assertEqual(A.data['status'], 'MERGED')
2491 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002492
James E. Blairec056492016-07-22 09:45:56 -07002493 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002494 def test_live_reconfiguration_merge_conflict(self):
2495 # A real-world bug: a change in a gate queue has a merge
2496 # conflict and a job is added to its project while it's
2497 # sitting in the queue. The job gets added to the change and
2498 # enqueued and the change gets stuck.
2499 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002500 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002501
2502 # This change is fine. It's here to stop the queue long
2503 # enough for the next change to be subject to the
2504 # reconfiguration, as well as to provide a conflict for the
2505 # next change. This change will succeed and merge.
2506 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2507 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002508 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002509
2510 # This change will be in merge conflict. During the
2511 # reconfiguration, we will add a job. We want to make sure
2512 # that doesn't cause it to get stuck.
2513 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2514 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002515 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002516
James E. Blair8b5408c2016-08-08 15:37:46 -07002517 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2518 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002519
2520 self.waitUntilSettled()
2521
2522 # No jobs have run yet
2523 self.assertEqual(A.data['status'], 'NEW')
2524 self.assertEqual(A.reported, 1)
2525 self.assertEqual(B.data['status'], 'NEW')
2526 self.assertEqual(B.reported, 1)
2527 self.assertEqual(len(self.history), 0)
2528
2529 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002530 self.updateConfigLayout(
2531 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002532 self.sched.reconfigure(self.config)
2533 self.waitUntilSettled()
2534
James E. Blair08d19992016-08-10 15:25:31 -07002535 self.launch_server.hold_jobs_in_build = False
2536 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002537 self.waitUntilSettled()
2538
2539 self.assertEqual(A.data['status'], 'MERGED')
2540 self.assertEqual(A.reported, 2)
2541 self.assertEqual(B.data['status'], 'NEW')
2542 self.assertEqual(B.reported, 2)
2543 self.assertEqual(self.getJobFromHistory('project-merge').result,
2544 'SUCCESS')
2545 self.assertEqual(self.getJobFromHistory('project-test1').result,
2546 'SUCCESS')
2547 self.assertEqual(self.getJobFromHistory('project-test2').result,
2548 'SUCCESS')
2549 self.assertEqual(self.getJobFromHistory('project-test3').result,
2550 'SUCCESS')
2551 self.assertEqual(len(self.history), 4)
2552
James E. Blairec056492016-07-22 09:45:56 -07002553 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002554 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002555 # An extrapolation of test_live_reconfiguration_merge_conflict
2556 # that tests a job added to a job tree with a failed root does
2557 # not run.
2558 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002559 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002560
2561 # This change is fine. It's here to stop the queue long
2562 # enough for the next change to be subject to the
2563 # reconfiguration. This change will succeed and merge.
2564 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2565 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002566 A.addApproval('code-review', 2)
2567 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002568 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002569 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002570 self.waitUntilSettled()
2571
2572 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002573 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002574 B.addApproval('code-review', 2)
2575 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002576 self.waitUntilSettled()
2577
James E. Blair08d19992016-08-10 15:25:31 -07002578 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002579 self.waitUntilSettled()
2580
2581 # Both -merge jobs have run, but no others.
2582 self.assertEqual(A.data['status'], 'NEW')
2583 self.assertEqual(A.reported, 1)
2584 self.assertEqual(B.data['status'], 'NEW')
2585 self.assertEqual(B.reported, 1)
2586 self.assertEqual(self.history[0].result, 'SUCCESS')
2587 self.assertEqual(self.history[0].name, 'project-merge')
2588 self.assertEqual(self.history[1].result, 'FAILURE')
2589 self.assertEqual(self.history[1].name, 'project-merge')
2590 self.assertEqual(len(self.history), 2)
2591
2592 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002593 self.updateConfigLayout(
2594 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002595 self.sched.reconfigure(self.config)
2596 self.waitUntilSettled()
2597
James E. Blair08d19992016-08-10 15:25:31 -07002598 self.launch_server.hold_jobs_in_build = False
2599 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002600 self.waitUntilSettled()
2601
2602 self.assertEqual(A.data['status'], 'MERGED')
2603 self.assertEqual(A.reported, 2)
2604 self.assertEqual(B.data['status'], 'NEW')
2605 self.assertEqual(B.reported, 2)
2606 self.assertEqual(self.history[0].result, 'SUCCESS')
2607 self.assertEqual(self.history[0].name, 'project-merge')
2608 self.assertEqual(self.history[1].result, 'FAILURE')
2609 self.assertEqual(self.history[1].name, 'project-merge')
2610 self.assertEqual(self.history[2].result, 'SUCCESS')
2611 self.assertEqual(self.history[3].result, 'SUCCESS')
2612 self.assertEqual(self.history[4].result, 'SUCCESS')
2613 self.assertEqual(len(self.history), 5)
2614
James E. Blairec056492016-07-22 09:45:56 -07002615 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002616 def test_live_reconfiguration_failed_job(self):
2617 # Test that a change with a removed failing job does not
2618 # disrupt reconfiguration. If a change has a failed job and
2619 # that job is removed during a reconfiguration, we observed a
2620 # bug where the code to re-set build statuses would run on
2621 # that build and raise an exception because the job no longer
2622 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002623 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002624
2625 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2626
2627 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002628 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002629
2630 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2631 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002632 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002633 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002634 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002635 self.waitUntilSettled()
2636
2637 self.assertEqual(A.data['status'], 'NEW')
2638 self.assertEqual(A.reported, 0)
2639
2640 self.assertEqual(self.getJobFromHistory('project-merge').result,
2641 'SUCCESS')
2642 self.assertEqual(self.getJobFromHistory('project-test1').result,
2643 'FAILURE')
2644 self.assertEqual(len(self.history), 2)
2645
2646 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002647 self.updateConfigLayout(
2648 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002649 self.sched.reconfigure(self.config)
2650 self.waitUntilSettled()
2651
James E. Blair08d19992016-08-10 15:25:31 -07002652 self.launch_server.hold_jobs_in_build = False
2653 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002654 self.waitUntilSettled()
2655
2656 self.assertEqual(self.getJobFromHistory('project-test2').result,
2657 'SUCCESS')
2658 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2659 'SUCCESS')
2660 self.assertEqual(len(self.history), 4)
2661
2662 self.assertEqual(A.data['status'], 'NEW')
2663 self.assertEqual(A.reported, 1)
2664 self.assertIn('Build succeeded', A.messages[0])
2665 # Ensure the removed job was not included in the report.
2666 self.assertNotIn('project-test1', A.messages[0])
2667
James E. Blairec056492016-07-22 09:45:56 -07002668 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002669 def test_live_reconfiguration_shared_queue(self):
2670 # Test that a change with a failing job which was removed from
2671 # this project but otherwise still exists in the system does
2672 # not disrupt reconfiguration.
2673
James E. Blair08d19992016-08-10 15:25:31 -07002674 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002675
2676 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2677
James E. Blair08d19992016-08-10 15:25:31 -07002678 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002679
2680 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2681 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002682 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002683 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002684 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002685 self.waitUntilSettled()
2686
2687 self.assertEqual(A.data['status'], 'NEW')
2688 self.assertEqual(A.reported, 0)
2689
2690 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2691 'SUCCESS')
2692 self.assertEqual(self.getJobFromHistory(
2693 'project1-project2-integration').result, 'FAILURE')
2694 self.assertEqual(len(self.history), 2)
2695
2696 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002697 self.updateConfigLayout(
2698 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002699 self.sched.reconfigure(self.config)
2700 self.waitUntilSettled()
2701
James E. Blair08d19992016-08-10 15:25:31 -07002702 self.launch_server.hold_jobs_in_build = False
2703 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002704 self.waitUntilSettled()
2705
2706 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2707 'SUCCESS')
2708 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2709 'SUCCESS')
2710 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2711 'SUCCESS')
2712 self.assertEqual(self.getJobFromHistory(
2713 'project1-project2-integration').result, 'FAILURE')
2714 self.assertEqual(len(self.history), 4)
2715
2716 self.assertEqual(A.data['status'], 'NEW')
2717 self.assertEqual(A.reported, 1)
2718 self.assertIn('Build succeeded', A.messages[0])
2719 # Ensure the removed job was not included in the report.
2720 self.assertNotIn('project1-project2-integration', A.messages[0])
2721
James E. Blairec056492016-07-22 09:45:56 -07002722 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002723 def test_double_live_reconfiguration_shared_queue(self):
2724 # This was a real-world regression. A change is added to
2725 # gate; a reconfigure happens, a second change which depends
2726 # on the first is added, and a second reconfiguration happens.
2727 # Ensure that both changes merge.
2728
2729 # A failure may indicate incorrect caching or cleaning up of
2730 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002731 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002732
2733 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2734 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2735 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002736 A.addApproval('code-review', 2)
2737 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002738
2739 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002740 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002741 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002742 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002743 self.waitUntilSettled()
2744
2745 # Reconfigure (with only one change in the pipeline).
2746 self.sched.reconfigure(self.config)
2747 self.waitUntilSettled()
2748
2749 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002750 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002751 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002752 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002753 self.waitUntilSettled()
2754
2755 # Reconfigure (with both in the pipeline).
2756 self.sched.reconfigure(self.config)
2757 self.waitUntilSettled()
2758
James E. Blair08d19992016-08-10 15:25:31 -07002759 self.launch_server.hold_jobs_in_build = False
2760 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002761 self.waitUntilSettled()
2762
2763 self.assertEqual(len(self.history), 8)
2764
2765 self.assertEqual(A.data['status'], 'MERGED')
2766 self.assertEqual(A.reported, 2)
2767 self.assertEqual(B.data['status'], 'MERGED')
2768 self.assertEqual(B.reported, 2)
2769
James E. Blairec056492016-07-22 09:45:56 -07002770 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002771 def test_live_reconfiguration_del_project(self):
2772 # Test project deletion from layout
2773 # while changes are enqueued
2774
James E. Blair08d19992016-08-10 15:25:31 -07002775 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002776 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2777 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2778 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2779
2780 # A Depends-On: B
2781 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2782 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002783 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002784
2785 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2786 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2787 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002788 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002789 self.waitUntilSettled()
2790 self.assertEqual(len(self.builds), 5)
2791
2792 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002793 self.updateConfigLayout(
2794 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002795 self.sched.reconfigure(self.config)
2796 self.waitUntilSettled()
2797
2798 # Builds for C aborted, builds for A succeed,
2799 # and have change B applied ahead
2800 job_c = self.getJobFromHistory('project1-test1')
2801 self.assertEqual(job_c.changes, '3,1')
2802 self.assertEqual(job_c.result, 'ABORTED')
2803
James E. Blair08d19992016-08-10 15:25:31 -07002804 self.launch_server.hold_jobs_in_build = False
2805 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002806 self.waitUntilSettled()
2807
2808 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2809 '2,1 1,1')
2810
2811 self.assertEqual(A.data['status'], 'NEW')
2812 self.assertEqual(B.data['status'], 'NEW')
2813 self.assertEqual(C.data['status'], 'NEW')
2814 self.assertEqual(A.reported, 1)
2815 self.assertEqual(B.reported, 0)
2816 self.assertEqual(C.reported, 0)
2817
2818 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2819 self.assertIn('Build succeeded', A.messages[0])
2820
James E. Blairec056492016-07-22 09:45:56 -07002821 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002822 def test_live_reconfiguration_functions(self):
2823 "Test live reconfiguration with a custom function"
2824 self.worker.registerFunction('build:node-project-test1:debian')
2825 self.worker.registerFunction('build:node-project-test1:wheezy')
2826 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002827 A.addApproval('code-review', 2)
2828 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002829 self.waitUntilSettled()
2830
2831 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2832 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2833 'debian')
2834 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2835
James E. Blairf84026c2015-12-08 16:11:46 -08002836 self.updateConfigLayout(
2837 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002838 self.sched.reconfigure(self.config)
2839 self.worker.build_history = []
2840
2841 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002842 B.addApproval('code-review', 2)
2843 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002844 self.waitUntilSettled()
2845
2846 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2847 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2848 'wheezy')
2849 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2850
James E. Blairec056492016-07-22 09:45:56 -07002851 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002852 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002853 self.updateConfigLayout(
2854 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002855 self.sched.reconfigure(self.config)
2856
2857 self.init_repo("org/new-project")
2858 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2859
James E. Blair8b5408c2016-08-08 15:37:46 -07002860 A.addApproval('code-review', 2)
2861 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002862 self.waitUntilSettled()
2863 self.assertEqual(self.getJobFromHistory('project-merge').result,
2864 'SUCCESS')
2865 self.assertEqual(self.getJobFromHistory('project-test1').result,
2866 'SUCCESS')
2867 self.assertEqual(self.getJobFromHistory('project-test2').result,
2868 'SUCCESS')
2869 self.assertEqual(A.data['status'], 'MERGED')
2870 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002871
James E. Blairec056492016-07-22 09:45:56 -07002872 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002873 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002874 self.updateConfigLayout(
2875 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002876 self.sched.reconfigure(self.config)
2877
2878 self.init_repo("org/delete-project")
2879 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2880
James E. Blair8b5408c2016-08-08 15:37:46 -07002881 A.addApproval('code-review', 2)
2882 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002883 self.waitUntilSettled()
2884 self.assertEqual(self.getJobFromHistory('project-merge').result,
2885 'SUCCESS')
2886 self.assertEqual(self.getJobFromHistory('project-test1').result,
2887 'SUCCESS')
2888 self.assertEqual(self.getJobFromHistory('project-test2').result,
2889 'SUCCESS')
2890 self.assertEqual(A.data['status'], 'MERGED')
2891 self.assertEqual(A.reported, 2)
2892
2893 # Delete org/new-project zuul repo. Should be recloned.
2894 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2895
2896 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2897
James E. Blair8b5408c2016-08-08 15:37:46 -07002898 B.addApproval('code-review', 2)
2899 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002900 self.waitUntilSettled()
2901 self.assertEqual(self.getJobFromHistory('project-merge').result,
2902 'SUCCESS')
2903 self.assertEqual(self.getJobFromHistory('project-test1').result,
2904 'SUCCESS')
2905 self.assertEqual(self.getJobFromHistory('project-test2').result,
2906 'SUCCESS')
2907 self.assertEqual(B.data['status'], 'MERGED')
2908 self.assertEqual(B.reported, 2)
2909
James E. Blairec056492016-07-22 09:45:56 -07002910 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002911 def test_tags(self):
2912 "Test job tags"
2913 self.config.set('zuul', 'layout_config',
2914 'tests/fixtures/layout-tags.yaml')
2915 self.sched.reconfigure(self.config)
2916
2917 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2918 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2919 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2920 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2921 self.waitUntilSettled()
2922
2923 results = {'project1-merge': 'extratag merge project1',
2924 'project2-merge': 'merge'}
2925
2926 for build in self.history:
2927 self.assertEqual(results.get(build.name, ''),
2928 build.parameters.get('BUILD_TAGS'))
2929
James E. Blairec056492016-07-22 09:45:56 -07002930 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002931 def test_timer(self):
2932 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002933 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002934 self.updateConfigLayout(
2935 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002936 self.sched.reconfigure(self.config)
2937 self.registerJobs()
2938
Clark Boylan3ee090a2014-04-03 20:55:09 -07002939 # The pipeline triggers every second, so we should have seen
2940 # several by now.
2941 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002942 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002943
2944 self.assertEqual(len(self.builds), 2)
2945
James E. Blair63bb0ef2013-07-29 17:14:51 -07002946 port = self.webapp.server.socket.getsockname()[1]
2947
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002948 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2949 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002950 data = f.read()
2951
James E. Blair08d19992016-08-10 15:25:31 -07002952 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07002953 # Stop queuing timer triggered jobs so that the assertions
2954 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002955 self.updateConfigLayout(
2956 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002957 self.sched.reconfigure(self.config)
2958 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07002959 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07002960 self.waitUntilSettled()
2961
2962 self.assertEqual(self.getJobFromHistory(
2963 'project-bitrot-stable-old').result, 'SUCCESS')
2964 self.assertEqual(self.getJobFromHistory(
2965 'project-bitrot-stable-older').result, 'SUCCESS')
2966
2967 data = json.loads(data)
2968 status_jobs = set()
2969 for p in data['pipelines']:
2970 for q in p['change_queues']:
2971 for head in q['heads']:
2972 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07002973 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002974 for job in change['jobs']:
2975 status_jobs.add(job['name'])
2976 self.assertIn('project-bitrot-stable-old', status_jobs)
2977 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10002978
James E. Blairec056492016-07-22 09:45:56 -07002979 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07002980 def test_idle(self):
2981 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07002982 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07002983
Clark Boylan3ee090a2014-04-03 20:55:09 -07002984 for x in range(1, 3):
2985 # Test that timer triggers periodic jobs even across
2986 # layout config reloads.
2987 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08002988 self.updateConfigLayout(
2989 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002990 self.sched.reconfigure(self.config)
2991 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08002992 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07002993
Clark Boylan3ee090a2014-04-03 20:55:09 -07002994 # The pipeline triggers every second, so we should have seen
2995 # several by now.
2996 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07002997
2998 # Stop queuing timer triggered jobs so that the assertions
2999 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003000 self.updateConfigLayout(
3001 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003002 self.sched.reconfigure(self.config)
3003 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003004 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003005
3006 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003007 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003008 self.waitUntilSettled()
3009 self.assertEqual(len(self.builds), 0)
3010 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003011
James E. Blairec056492016-07-22 09:45:56 -07003012 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003013 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003014 self.updateConfigLayout(
3015 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003016 self.sched.reconfigure(self.config)
3017
3018 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3019 self.waitUntilSettled()
3020
3021 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3022 self.waitUntilSettled()
3023
James E. Blairff80a2f2013-12-27 13:24:06 -08003024 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003025
3026 # A.messages only holds what FakeGerrit places in it. Thus we
3027 # work on the knowledge of what the first message should be as
3028 # it is only configured to go to SMTP.
3029
3030 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003031 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003032 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003033 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003034 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003035 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003036
3037 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003038 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003039 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003040 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003041 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003042 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003043
James E. Blairec056492016-07-22 09:45:56 -07003044 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003045 def test_timer_smtp(self):
3046 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003047 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003048 self.updateConfigLayout(
3049 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003050 self.sched.reconfigure(self.config)
3051 self.registerJobs()
3052
Clark Boylan3ee090a2014-04-03 20:55:09 -07003053 # The pipeline triggers every second, so we should have seen
3054 # several by now.
3055 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003056 self.waitUntilSettled()
3057
Clark Boylan3ee090a2014-04-03 20:55:09 -07003058 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003059 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003060 self.waitUntilSettled()
3061 self.assertEqual(len(self.history), 2)
3062
James E. Blaire5910202013-12-27 09:50:31 -08003063 self.assertEqual(self.getJobFromHistory(
3064 'project-bitrot-stable-old').result, 'SUCCESS')
3065 self.assertEqual(self.getJobFromHistory(
3066 'project-bitrot-stable-older').result, 'SUCCESS')
3067
James E. Blairff80a2f2013-12-27 13:24:06 -08003068 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003069
3070 # A.messages only holds what FakeGerrit places in it. Thus we
3071 # work on the knowledge of what the first message should be as
3072 # it is only configured to go to SMTP.
3073
3074 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003075 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003076 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003077 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003078 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003079 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003080
Clark Boylan3ee090a2014-04-03 20:55:09 -07003081 # Stop queuing timer triggered jobs and let any that may have
3082 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003083 self.updateConfigLayout(
3084 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003085 self.sched.reconfigure(self.config)
3086 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003087 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003088 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003089 self.waitUntilSettled()
3090
James E. Blairec056492016-07-22 09:45:56 -07003091 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003092 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003093 "Test that the RPC client can enqueue a change"
3094 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003095 A.addApproval('code-review', 2)
3096 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003097
3098 client = zuul.rpcclient.RPCClient('127.0.0.1',
3099 self.gearman_server.port)
3100 r = client.enqueue(pipeline='gate',
3101 project='org/project',
3102 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003103 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003104 self.waitUntilSettled()
3105 self.assertEqual(self.getJobFromHistory('project-merge').result,
3106 'SUCCESS')
3107 self.assertEqual(self.getJobFromHistory('project-test1').result,
3108 'SUCCESS')
3109 self.assertEqual(self.getJobFromHistory('project-test2').result,
3110 'SUCCESS')
3111 self.assertEqual(A.data['status'], 'MERGED')
3112 self.assertEqual(A.reported, 2)
3113 self.assertEqual(r, True)
3114
James E. Blairec056492016-07-22 09:45:56 -07003115 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003116 def test_client_enqueue_ref(self):
3117 "Test that the RPC client can enqueue a ref"
3118
3119 client = zuul.rpcclient.RPCClient('127.0.0.1',
3120 self.gearman_server.port)
3121 r = client.enqueue_ref(
3122 pipeline='post',
3123 project='org/project',
3124 trigger='gerrit',
3125 ref='master',
3126 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3127 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3128 self.waitUntilSettled()
3129 job_names = [x.name for x in self.history]
3130 self.assertEqual(len(self.history), 1)
3131 self.assertIn('project-post', job_names)
3132 self.assertEqual(r, True)
3133
James E. Blairec056492016-07-22 09:45:56 -07003134 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003135 def test_client_enqueue_negative(self):
3136 "Test that the RPC client returns errors"
3137 client = zuul.rpcclient.RPCClient('127.0.0.1',
3138 self.gearman_server.port)
3139 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3140 "Invalid project"):
3141 r = client.enqueue(pipeline='gate',
3142 project='project-does-not-exist',
3143 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003144 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003145 client.shutdown()
3146 self.assertEqual(r, False)
3147
3148 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3149 "Invalid pipeline"):
3150 r = client.enqueue(pipeline='pipeline-does-not-exist',
3151 project='org/project',
3152 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003153 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003154 client.shutdown()
3155 self.assertEqual(r, False)
3156
3157 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3158 "Invalid trigger"):
3159 r = client.enqueue(pipeline='gate',
3160 project='org/project',
3161 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003162 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003163 client.shutdown()
3164 self.assertEqual(r, False)
3165
3166 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3167 "Invalid change"):
3168 r = client.enqueue(pipeline='gate',
3169 project='org/project',
3170 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003171 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003172 client.shutdown()
3173 self.assertEqual(r, False)
3174
3175 self.waitUntilSettled()
3176 self.assertEqual(len(self.history), 0)
3177 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003178
James E. Blairec056492016-07-22 09:45:56 -07003179 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003180 def test_client_promote(self):
3181 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003182 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003183 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3184 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3185 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003186 A.addApproval('code-review', 2)
3187 B.addApproval('code-review', 2)
3188 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003189
James E. Blair8b5408c2016-08-08 15:37:46 -07003190 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3191 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3192 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003193
3194 self.waitUntilSettled()
3195
Sean Daguef39b9ca2014-01-10 21:34:35 -05003196 items = self.sched.layout.pipelines['gate'].getAllItems()
3197 enqueue_times = {}
3198 for item in items:
3199 enqueue_times[str(item.change)] = item.enqueue_time
3200
James E. Blair36658cf2013-12-06 17:53:48 -08003201 client = zuul.rpcclient.RPCClient('127.0.0.1',
3202 self.gearman_server.port)
3203 r = client.promote(pipeline='gate',
3204 change_ids=['2,1', '3,1'])
3205
Sean Daguef39b9ca2014-01-10 21:34:35 -05003206 # ensure that enqueue times are durable
3207 items = self.sched.layout.pipelines['gate'].getAllItems()
3208 for item in items:
3209 self.assertEqual(
3210 enqueue_times[str(item.change)], item.enqueue_time)
3211
James E. Blair78acec92014-02-06 07:11:32 -08003212 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003213 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003214 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003215 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003216 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003217 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003218 self.waitUntilSettled()
3219
3220 self.assertEqual(len(self.builds), 6)
3221 self.assertEqual(self.builds[0].name, 'project-test1')
3222 self.assertEqual(self.builds[1].name, 'project-test2')
3223 self.assertEqual(self.builds[2].name, 'project-test1')
3224 self.assertEqual(self.builds[3].name, 'project-test2')
3225 self.assertEqual(self.builds[4].name, 'project-test1')
3226 self.assertEqual(self.builds[5].name, 'project-test2')
3227
3228 self.assertTrue(self.job_has_changes(self.builds[0], B))
3229 self.assertFalse(self.job_has_changes(self.builds[0], A))
3230 self.assertFalse(self.job_has_changes(self.builds[0], C))
3231
3232 self.assertTrue(self.job_has_changes(self.builds[2], B))
3233 self.assertTrue(self.job_has_changes(self.builds[2], C))
3234 self.assertFalse(self.job_has_changes(self.builds[2], A))
3235
3236 self.assertTrue(self.job_has_changes(self.builds[4], B))
3237 self.assertTrue(self.job_has_changes(self.builds[4], C))
3238 self.assertTrue(self.job_has_changes(self.builds[4], A))
3239
James E. Blair08d19992016-08-10 15:25:31 -07003240 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003241 self.waitUntilSettled()
3242
3243 self.assertEqual(A.data['status'], 'MERGED')
3244 self.assertEqual(A.reported, 2)
3245 self.assertEqual(B.data['status'], 'MERGED')
3246 self.assertEqual(B.reported, 2)
3247 self.assertEqual(C.data['status'], 'MERGED')
3248 self.assertEqual(C.reported, 2)
3249
3250 client.shutdown()
3251 self.assertEqual(r, True)
3252
James E. Blairec056492016-07-22 09:45:56 -07003253 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003254 def test_client_promote_dependent(self):
3255 "Test that the RPC client can promote a dependent change"
3256 # C (depends on B) -> B -> A ; then promote C to get:
3257 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003258 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003259 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3260 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3261 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3262
3263 C.setDependsOn(B, 1)
3264
James E. Blair8b5408c2016-08-08 15:37:46 -07003265 A.addApproval('code-review', 2)
3266 B.addApproval('code-review', 2)
3267 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003268
James E. Blair8b5408c2016-08-08 15:37:46 -07003269 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3270 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3271 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003272
3273 self.waitUntilSettled()
3274
3275 client = zuul.rpcclient.RPCClient('127.0.0.1',
3276 self.gearman_server.port)
3277 r = client.promote(pipeline='gate',
3278 change_ids=['3,1'])
3279
James E. Blair78acec92014-02-06 07:11:32 -08003280 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003281 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003282 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003283 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003284 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003285 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003286 self.waitUntilSettled()
3287
3288 self.assertEqual(len(self.builds), 6)
3289 self.assertEqual(self.builds[0].name, 'project-test1')
3290 self.assertEqual(self.builds[1].name, 'project-test2')
3291 self.assertEqual(self.builds[2].name, 'project-test1')
3292 self.assertEqual(self.builds[3].name, 'project-test2')
3293 self.assertEqual(self.builds[4].name, 'project-test1')
3294 self.assertEqual(self.builds[5].name, 'project-test2')
3295
3296 self.assertTrue(self.job_has_changes(self.builds[0], B))
3297 self.assertFalse(self.job_has_changes(self.builds[0], A))
3298 self.assertFalse(self.job_has_changes(self.builds[0], C))
3299
3300 self.assertTrue(self.job_has_changes(self.builds[2], B))
3301 self.assertTrue(self.job_has_changes(self.builds[2], C))
3302 self.assertFalse(self.job_has_changes(self.builds[2], A))
3303
3304 self.assertTrue(self.job_has_changes(self.builds[4], B))
3305 self.assertTrue(self.job_has_changes(self.builds[4], C))
3306 self.assertTrue(self.job_has_changes(self.builds[4], A))
3307
James E. Blair08d19992016-08-10 15:25:31 -07003308 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003309 self.waitUntilSettled()
3310
3311 self.assertEqual(A.data['status'], 'MERGED')
3312 self.assertEqual(A.reported, 2)
3313 self.assertEqual(B.data['status'], 'MERGED')
3314 self.assertEqual(B.reported, 2)
3315 self.assertEqual(C.data['status'], 'MERGED')
3316 self.assertEqual(C.reported, 2)
3317
3318 client.shutdown()
3319 self.assertEqual(r, True)
3320
James E. Blairec056492016-07-22 09:45:56 -07003321 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003322 def test_client_promote_negative(self):
3323 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003324 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003325 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003326 A.addApproval('code-review', 2)
3327 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003328 self.waitUntilSettled()
3329
3330 client = zuul.rpcclient.RPCClient('127.0.0.1',
3331 self.gearman_server.port)
3332
3333 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3334 r = client.promote(pipeline='nonexistent',
3335 change_ids=['2,1', '3,1'])
3336 client.shutdown()
3337 self.assertEqual(r, False)
3338
3339 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3340 r = client.promote(pipeline='gate',
3341 change_ids=['4,1'])
3342 client.shutdown()
3343 self.assertEqual(r, False)
3344
James E. Blair08d19992016-08-10 15:25:31 -07003345 self.launch_server.hold_jobs_in_build = False
3346 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003347 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003348
James E. Blairec056492016-07-22 09:45:56 -07003349 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003350 def test_queue_rate_limiting(self):
3351 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003352 self.updateConfigLayout(
3353 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003354 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003355 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003356 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3357 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3358 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3359
3360 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003361 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003362
James E. Blair8b5408c2016-08-08 15:37:46 -07003363 A.addApproval('code-review', 2)
3364 B.addApproval('code-review', 2)
3365 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003366
James E. Blair8b5408c2016-08-08 15:37:46 -07003367 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3368 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3369 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003370 self.waitUntilSettled()
3371
3372 # Only A and B will have their merge jobs queued because
3373 # window is 2.
3374 self.assertEqual(len(self.builds), 2)
3375 self.assertEqual(self.builds[0].name, 'project-merge')
3376 self.assertEqual(self.builds[1].name, 'project-merge')
3377
James E. Blair08d19992016-08-10 15:25:31 -07003378 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003379 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003380 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003381 self.waitUntilSettled()
3382
3383 # Only A and B will have their test jobs queued because
3384 # window is 2.
3385 self.assertEqual(len(self.builds), 4)
3386 self.assertEqual(self.builds[0].name, 'project-test1')
3387 self.assertEqual(self.builds[1].name, 'project-test2')
3388 self.assertEqual(self.builds[2].name, 'project-test1')
3389 self.assertEqual(self.builds[3].name, 'project-test2')
3390
James E. Blair08d19992016-08-10 15:25:31 -07003391 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003392 self.waitUntilSettled()
3393
3394 queue = self.sched.layout.pipelines['gate'].queues[0]
3395 # A failed so window is reduced by 1 to 1.
3396 self.assertEqual(queue.window, 1)
3397 self.assertEqual(queue.window_floor, 1)
3398 self.assertEqual(A.data['status'], 'NEW')
3399
3400 # Gate is reset and only B's merge job is queued because
3401 # window shrunk to 1.
3402 self.assertEqual(len(self.builds), 1)
3403 self.assertEqual(self.builds[0].name, 'project-merge')
3404
James E. Blair08d19992016-08-10 15:25:31 -07003405 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003406 self.waitUntilSettled()
3407
3408 # Only B's test jobs are queued because window is still 1.
3409 self.assertEqual(len(self.builds), 2)
3410 self.assertEqual(self.builds[0].name, 'project-test1')
3411 self.assertEqual(self.builds[1].name, 'project-test2')
3412
James E. Blair08d19992016-08-10 15:25:31 -07003413 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003414 self.waitUntilSettled()
3415
3416 # B was successfully merged so window is increased to 2.
3417 self.assertEqual(queue.window, 2)
3418 self.assertEqual(queue.window_floor, 1)
3419 self.assertEqual(B.data['status'], 'MERGED')
3420
3421 # Only C is left and its merge job is queued.
3422 self.assertEqual(len(self.builds), 1)
3423 self.assertEqual(self.builds[0].name, 'project-merge')
3424
James E. Blair08d19992016-08-10 15:25:31 -07003425 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003426 self.waitUntilSettled()
3427
3428 # After successful merge job the test jobs for C are queued.
3429 self.assertEqual(len(self.builds), 2)
3430 self.assertEqual(self.builds[0].name, 'project-test1')
3431 self.assertEqual(self.builds[1].name, 'project-test2')
3432
James E. Blair08d19992016-08-10 15:25:31 -07003433 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003434 self.waitUntilSettled()
3435
3436 # C successfully merged so window is bumped to 3.
3437 self.assertEqual(queue.window, 3)
3438 self.assertEqual(queue.window_floor, 1)
3439 self.assertEqual(C.data['status'], 'MERGED')
3440
James E. Blairec056492016-07-22 09:45:56 -07003441 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003442 def test_queue_rate_limiting_dependent(self):
3443 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003444 self.updateConfigLayout(
3445 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003446 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003447 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003448 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3449 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3450 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3451
3452 B.setDependsOn(A, 1)
3453
James E. Blair08d19992016-08-10 15:25:31 -07003454 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003455
James E. Blair8b5408c2016-08-08 15:37:46 -07003456 A.addApproval('code-review', 2)
3457 B.addApproval('code-review', 2)
3458 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003459
James E. Blair8b5408c2016-08-08 15:37:46 -07003460 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3461 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3462 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003463 self.waitUntilSettled()
3464
3465 # Only A and B will have their merge jobs queued because
3466 # window is 2.
3467 self.assertEqual(len(self.builds), 2)
3468 self.assertEqual(self.builds[0].name, 'project-merge')
3469 self.assertEqual(self.builds[1].name, 'project-merge')
3470
James E. Blair08d19992016-08-10 15:25:31 -07003471 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003472 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003473 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003474 self.waitUntilSettled()
3475
3476 # Only A and B will have their test jobs queued because
3477 # window is 2.
3478 self.assertEqual(len(self.builds), 4)
3479 self.assertEqual(self.builds[0].name, 'project-test1')
3480 self.assertEqual(self.builds[1].name, 'project-test2')
3481 self.assertEqual(self.builds[2].name, 'project-test1')
3482 self.assertEqual(self.builds[3].name, 'project-test2')
3483
James E. Blair08d19992016-08-10 15:25:31 -07003484 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003485 self.waitUntilSettled()
3486
3487 queue = self.sched.layout.pipelines['gate'].queues[0]
3488 # A failed so window is reduced by 1 to 1.
3489 self.assertEqual(queue.window, 1)
3490 self.assertEqual(queue.window_floor, 1)
3491 self.assertEqual(A.data['status'], 'NEW')
3492 self.assertEqual(B.data['status'], 'NEW')
3493
3494 # Gate is reset and only C's merge job is queued because
3495 # window shrunk to 1 and A and B were dequeued.
3496 self.assertEqual(len(self.builds), 1)
3497 self.assertEqual(self.builds[0].name, 'project-merge')
3498
James E. Blair08d19992016-08-10 15:25:31 -07003499 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003500 self.waitUntilSettled()
3501
3502 # Only C's test jobs are queued because window is still 1.
3503 self.assertEqual(len(self.builds), 2)
3504 self.assertEqual(self.builds[0].name, 'project-test1')
3505 self.assertEqual(self.builds[1].name, 'project-test2')
3506
James E. Blair08d19992016-08-10 15:25:31 -07003507 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003508 self.waitUntilSettled()
3509
3510 # C was successfully merged so window is increased to 2.
3511 self.assertEqual(queue.window, 2)
3512 self.assertEqual(queue.window_floor, 1)
3513 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003514
James E. Blairec056492016-07-22 09:45:56 -07003515 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003516 def test_worker_update_metadata(self):
3517 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003518 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003519
3520 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003521 A.addApproval('code-review', 2)
3522 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003523 self.waitUntilSettled()
3524
3525 self.assertEqual(len(self.launcher.builds), 1)
3526
3527 self.log.debug('Current builds:')
3528 self.log.debug(self.launcher.builds)
3529
3530 start = time.time()
3531 while True:
3532 if time.time() - start > 10:
3533 raise Exception("Timeout waiting for gearman server to report "
3534 + "back to the client")
3535 build = self.launcher.builds.values()[0]
3536 if build.worker.name == "My Worker":
3537 break
3538 else:
3539 time.sleep(0)
3540
3541 self.log.debug(build)
3542 self.assertEqual("My Worker", build.worker.name)
3543 self.assertEqual("localhost", build.worker.hostname)
3544 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3545 self.assertEqual("zuul.example.org", build.worker.fqdn)
3546 self.assertEqual("FakeBuilder", build.worker.program)
3547 self.assertEqual("v1.1", build.worker.version)
3548 self.assertEqual({'something': 'else'}, build.worker.extra)
3549
James E. Blair08d19992016-08-10 15:25:31 -07003550 self.launch_server.hold_jobs_in_build = False
3551 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003552 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003553
James E. Blairec056492016-07-22 09:45:56 -07003554 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003555 def test_footer_message(self):
3556 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003557 self.updateConfigLayout(
3558 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003559 self.sched.reconfigure(self.config)
3560 self.registerJobs()
3561
3562 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003563 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003564 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003565 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003566 self.waitUntilSettled()
3567
3568 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003569 B.addApproval('code-review', 2)
3570 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003571 self.waitUntilSettled()
3572
3573 self.assertEqual(2, len(self.smtp_messages))
3574
3575 failure_body = """\
3576Build failed. For information on how to proceed, see \
3577http://wiki.example.org/Test_Failures
3578
3579- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3580- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3581
3582For CI problems and help debugging, contact ci@example.org"""
3583
3584 success_body = """\
3585Build succeeded.
3586
3587- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3588- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3589
3590For CI problems and help debugging, contact ci@example.org"""
3591
3592 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3593 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003594
James E. Blairec056492016-07-22 09:45:56 -07003595 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003596 def test_merge_failure_reporters(self):
3597 """Check that the config is set up correctly"""
3598
James E. Blairf84026c2015-12-08 16:11:46 -08003599 self.updateConfigLayout(
3600 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003601 self.sched.reconfigure(self.config)
3602 self.registerJobs()
3603
3604 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003605 "Merge Failed.\n\nThis change or one of its cross-repo "
3606 "dependencies was unable to be automatically merged with the "
3607 "current state of its repository. Please rebase the change and "
3608 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003609 self.sched.layout.pipelines['check'].merge_failure_message)
3610 self.assertEqual(
3611 "The merge failed! For more information...",
3612 self.sched.layout.pipelines['gate'].merge_failure_message)
3613
3614 self.assertEqual(
3615 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3616 self.assertEqual(
3617 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3618
3619 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003620 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3621 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003622
3623 self.assertTrue(
3624 (
3625 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003626 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003627 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003628 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003629 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003630 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003631 ) or (
3632 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003633 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003634 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003635 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003636 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003637 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003638 )
3639 )
3640
James E. Blairec056492016-07-22 09:45:56 -07003641 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003642 def test_merge_failure_reports(self):
3643 """Check that when a change fails to merge the correct message is sent
3644 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003645 self.updateConfigLayout(
3646 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003647 self.sched.reconfigure(self.config)
3648 self.registerJobs()
3649
3650 # Check a test failure isn't reported to SMTP
3651 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003652 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003653 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003654 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003655 self.waitUntilSettled()
3656
3657 self.assertEqual(3, len(self.history)) # 3 jobs
3658 self.assertEqual(0, len(self.smtp_messages))
3659
3660 # Check a merge failure is reported to SMTP
3661 # B should be merged, but C will conflict with B
3662 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3663 B.addPatchset(['conflict'])
3664 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3665 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003666 B.addApproval('code-review', 2)
3667 C.addApproval('code-review', 2)
3668 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3669 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003670 self.waitUntilSettled()
3671
3672 self.assertEqual(6, len(self.history)) # A and B jobs
3673 self.assertEqual(1, len(self.smtp_messages))
3674 self.assertEqual('The merge failed! For more information...',
3675 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003676
James E. Blairec056492016-07-22 09:45:56 -07003677 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003678 def test_default_merge_failure_reports(self):
3679 """Check that the default merge failure reports are correct."""
3680
3681 # A should report success, B should report merge failure.
3682 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3683 A.addPatchset(['conflict'])
3684 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3685 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003686 A.addApproval('code-review', 2)
3687 B.addApproval('code-review', 2)
3688 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3689 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003690 self.waitUntilSettled()
3691
3692 self.assertEqual(3, len(self.history)) # A jobs
3693 self.assertEqual(A.reported, 2)
3694 self.assertEqual(B.reported, 2)
3695 self.assertEqual(A.data['status'], 'MERGED')
3696 self.assertEqual(B.data['status'], 'NEW')
3697 self.assertIn('Build succeeded', A.messages[1])
3698 self.assertIn('Merge Failed', B.messages[1])
3699 self.assertIn('automatically merged', B.messages[1])
3700 self.assertNotIn('logs.example.com', B.messages[1])
3701 self.assertNotIn('SKIPPED', B.messages[1])
3702
James E. Blairec056492016-07-22 09:45:56 -07003703 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003704 def test_swift_instructions(self):
3705 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003706 self.updateConfigLayout(
3707 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003708 self.sched.reconfigure(self.config)
3709 self.registerJobs()
3710
James E. Blair08d19992016-08-10 15:25:31 -07003711 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003712 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3713
James E. Blair8b5408c2016-08-08 15:37:46 -07003714 A.addApproval('code-review', 2)
3715 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003716 self.waitUntilSettled()
3717
3718 self.assertEqual(
3719 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3720 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003721 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003722 self.assertEqual(5,
3723 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3724 split('\n')))
3725 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3726
3727 self.assertEqual(
3728 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3729 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003730 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003731 self.assertEqual(5,
3732 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3733 split('\n')))
3734 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3735
3736 self.assertEqual(
3737 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3738 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003739 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003740 self.assertEqual(5,
3741 len(self.builds[1].
3742 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3743 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3744
James E. Blair08d19992016-08-10 15:25:31 -07003745 self.launch_server.hold_jobs_in_build = False
3746 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003747 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003748
James E. Blairec056492016-07-22 09:45:56 -07003749 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003750 def test_client_get_running_jobs(self):
3751 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003752 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003753 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003754 A.addApproval('code-review', 2)
3755 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003756 self.waitUntilSettled()
3757
3758 client = zuul.rpcclient.RPCClient('127.0.0.1',
3759 self.gearman_server.port)
3760
3761 # Wait for gearman server to send the initial workData back to zuul
3762 start = time.time()
3763 while True:
3764 if time.time() - start > 10:
3765 raise Exception("Timeout waiting for gearman server to report "
3766 + "back to the client")
3767 build = self.launcher.builds.values()[0]
3768 if build.worker.name == "My Worker":
3769 break
3770 else:
3771 time.sleep(0)
3772
3773 running_items = client.get_running_jobs()
3774
3775 self.assertEqual(1, len(running_items))
3776 running_item = running_items[0]
3777 self.assertEqual([], running_item['failing_reasons'])
3778 self.assertEqual([], running_item['items_behind'])
3779 self.assertEqual('https://hostname/1', running_item['url'])
3780 self.assertEqual(None, running_item['item_ahead'])
3781 self.assertEqual('org/project', running_item['project'])
3782 self.assertEqual(None, running_item['remaining_time'])
3783 self.assertEqual(True, running_item['active'])
3784 self.assertEqual('1,1', running_item['id'])
3785
3786 self.assertEqual(3, len(running_item['jobs']))
3787 for job in running_item['jobs']:
3788 if job['name'] == 'project-merge':
3789 self.assertEqual('project-merge', job['name'])
3790 self.assertEqual('gate', job['pipeline'])
3791 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003792 self.assertEqual('https://server/job/project-merge/0/',
3793 job['url'])
3794 self.assertEqual(7, len(job['worker']))
3795 self.assertEqual(False, job['canceled'])
3796 self.assertEqual(True, job['voting'])
3797 self.assertEqual(None, job['result'])
3798 self.assertEqual('gate', job['pipeline'])
3799 break
3800
James E. Blair08d19992016-08-10 15:25:31 -07003801 self.launch_server.hold_jobs_in_build = False
3802 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003803 self.waitUntilSettled()
3804
3805 running_items = client.get_running_jobs()
3806 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003807
3808 def test_nonvoting_pipeline(self):
3809 "Test that a nonvoting pipeline (experimental) can still report"
3810
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003811 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3812 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003813 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3814 self.waitUntilSettled()
Paul Belanger15e3e202016-10-14 16:27:34 -04003815
3816 self.assertEqual(self.getJobFromHistory('project-merge').result,
3817 'SUCCESS')
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003818 self.assertEqual(
3819 self.getJobFromHistory('experimental-project-test').result,
3820 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003821 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003822
James E. Blairec056492016-07-22 09:45:56 -07003823 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003824 def test_crd_gate(self):
3825 "Test cross-repo dependencies"
3826 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3827 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003828 A.addApproval('code-review', 2)
3829 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003830
3831 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3832 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3833 AM2.setMerged()
3834 AM1.setMerged()
3835
3836 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3837 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3838 BM2.setMerged()
3839 BM1.setMerged()
3840
3841 # A -> AM1 -> AM2
3842 # B -> BM1 -> BM2
3843 # A Depends-On: B
3844 # M2 is here to make sure it is never queried. If it is, it
3845 # means zuul is walking down the entire history of merged
3846 # changes.
3847
3848 B.setDependsOn(BM1, 1)
3849 BM1.setDependsOn(BM2, 1)
3850
3851 A.setDependsOn(AM1, 1)
3852 AM1.setDependsOn(AM2, 1)
3853
3854 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3855 A.subject, B.data['id'])
3856
James E. Blair8b5408c2016-08-08 15:37:46 -07003857 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003858 self.waitUntilSettled()
3859
3860 self.assertEqual(A.data['status'], 'NEW')
3861 self.assertEqual(B.data['status'], 'NEW')
3862
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003863 for connection in self.connections.values():
3864 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003865
James E. Blair08d19992016-08-10 15:25:31 -07003866 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003867 B.addApproval('approved', 1)
3868 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003869 self.waitUntilSettled()
3870
James E. Blair08d19992016-08-10 15:25:31 -07003871 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003872 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003873 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003874 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003875 self.launch_server.hold_jobs_in_build = False
3876 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003877 self.waitUntilSettled()
3878
3879 self.assertEqual(AM2.queried, 0)
3880 self.assertEqual(BM2.queried, 0)
3881 self.assertEqual(A.data['status'], 'MERGED')
3882 self.assertEqual(B.data['status'], 'MERGED')
3883 self.assertEqual(A.reported, 2)
3884 self.assertEqual(B.reported, 2)
3885
James E. Blair8f78d882015-02-05 08:51:37 -08003886 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3887 '2,1 1,1')
3888
James E. Blairec056492016-07-22 09:45:56 -07003889 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003890 def test_crd_branch(self):
3891 "Test cross-repo dependencies in multiple branches"
3892 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3893 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3894 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3895 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003896 A.addApproval('code-review', 2)
3897 B.addApproval('code-review', 2)
3898 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003899
3900 # A Depends-On: B+C
3901 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3902 A.subject, B.data['id'])
3903
James E. Blair08d19992016-08-10 15:25:31 -07003904 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003905 B.addApproval('approved', 1)
3906 C.addApproval('approved', 1)
3907 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003908 self.waitUntilSettled()
3909
James E. Blair08d19992016-08-10 15:25:31 -07003910 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003911 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003912 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003913 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003914 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003915 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003916 self.launch_server.hold_jobs_in_build = False
3917 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003918 self.waitUntilSettled()
3919
3920 self.assertEqual(A.data['status'], 'MERGED')
3921 self.assertEqual(B.data['status'], 'MERGED')
3922 self.assertEqual(C.data['status'], 'MERGED')
3923 self.assertEqual(A.reported, 2)
3924 self.assertEqual(B.reported, 2)
3925 self.assertEqual(C.reported, 2)
3926
3927 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3928 '2,1 3,1 1,1')
3929
James E. Blairec056492016-07-22 09:45:56 -07003930 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003931 def test_crd_multiline(self):
3932 "Test multiple depends-on lines in commit"
3933 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3934 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3935 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003936 A.addApproval('code-review', 2)
3937 B.addApproval('code-review', 2)
3938 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003939
3940 # A Depends-On: B+C
3941 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
3942 A.subject, B.data['id'], C.data['id'])
3943
James E. Blair08d19992016-08-10 15:25:31 -07003944 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003945 B.addApproval('approved', 1)
3946 C.addApproval('approved', 1)
3947 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003948 self.waitUntilSettled()
3949
James E. Blair08d19992016-08-10 15:25:31 -07003950 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003951 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003952 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003953 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003954 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003955 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003956 self.launch_server.hold_jobs_in_build = False
3957 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003958 self.waitUntilSettled()
3959
3960 self.assertEqual(A.data['status'], 'MERGED')
3961 self.assertEqual(B.data['status'], 'MERGED')
3962 self.assertEqual(C.data['status'], 'MERGED')
3963 self.assertEqual(A.reported, 2)
3964 self.assertEqual(B.reported, 2)
3965 self.assertEqual(C.reported, 2)
3966
3967 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3968 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08003969
James E. Blairec056492016-07-22 09:45:56 -07003970 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003971 def test_crd_unshared_gate(self):
3972 "Test cross-repo dependencies in unshared gate queues"
3973 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3974 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003975 A.addApproval('code-review', 2)
3976 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003977
3978 # A Depends-On: B
3979 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3980 A.subject, B.data['id'])
3981
3982 # A and B do not share a queue, make sure that A is unable to
3983 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07003984 B.addApproval('approved', 1)
3985 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003986 self.waitUntilSettled()
3987
3988 self.assertEqual(A.data['status'], 'NEW')
3989 self.assertEqual(B.data['status'], 'NEW')
3990 self.assertEqual(A.reported, 0)
3991 self.assertEqual(B.reported, 0)
3992 self.assertEqual(len(self.history), 0)
3993
3994 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07003995 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003996 self.waitUntilSettled()
3997
3998 self.assertEqual(B.data['status'], 'MERGED')
3999 self.assertEqual(B.reported, 2)
4000
4001 # Now that B is merged, A should be able to be enqueued and
4002 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004003 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004004 self.waitUntilSettled()
4005
4006 self.assertEqual(A.data['status'], 'MERGED')
4007 self.assertEqual(A.reported, 2)
4008
James E. Blairec056492016-07-22 09:45:56 -07004009 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004010 def test_crd_gate_reverse(self):
4011 "Test reverse cross-repo dependencies"
4012 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4013 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004014 A.addApproval('code-review', 2)
4015 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004016
4017 # A Depends-On: B
4018
4019 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4020 A.subject, B.data['id'])
4021
James E. Blair8b5408c2016-08-08 15:37:46 -07004022 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004023 self.waitUntilSettled()
4024
4025 self.assertEqual(A.data['status'], 'NEW')
4026 self.assertEqual(B.data['status'], 'NEW')
4027
James E. Blair08d19992016-08-10 15:25:31 -07004028 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004029 A.addApproval('approved', 1)
4030 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004031 self.waitUntilSettled()
4032
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.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004036 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004037 self.launch_server.hold_jobs_in_build = False
4038 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004039 self.waitUntilSettled()
4040
4041 self.assertEqual(A.data['status'], 'MERGED')
4042 self.assertEqual(B.data['status'], 'MERGED')
4043 self.assertEqual(A.reported, 2)
4044 self.assertEqual(B.reported, 2)
4045
4046 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4047 '2,1 1,1')
4048
James E. Blairec056492016-07-22 09:45:56 -07004049 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004050 def test_crd_cycle(self):
4051 "Test cross-repo dependency cycles"
4052 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4053 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004054 A.addApproval('code-review', 2)
4055 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004056
4057 # A -> B -> A (via commit-depends)
4058
4059 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4060 A.subject, B.data['id'])
4061 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4062 B.subject, A.data['id'])
4063
James E. Blair8b5408c2016-08-08 15:37:46 -07004064 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004065 self.waitUntilSettled()
4066
4067 self.assertEqual(A.reported, 0)
4068 self.assertEqual(B.reported, 0)
4069 self.assertEqual(A.data['status'], 'NEW')
4070 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004071
James E. Blairec056492016-07-22 09:45:56 -07004072 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004073 def test_crd_gate_unknown(self):
4074 "Test unknown projects in dependent pipeline"
4075 self.init_repo("org/unknown")
4076 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4077 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004078 A.addApproval('code-review', 2)
4079 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004080
4081 # A Depends-On: B
4082 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4083 A.subject, B.data['id'])
4084
James E. Blair8b5408c2016-08-08 15:37:46 -07004085 B.addApproval('approved', 1)
4086 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004087 self.waitUntilSettled()
4088
4089 # Unknown projects cannot share a queue with any other
4090 # since they don't have common jobs with any other (they have no jobs).
4091 # Changes which depend on unknown project changes
4092 # should not be processed in dependent pipeline
4093 self.assertEqual(A.data['status'], 'NEW')
4094 self.assertEqual(B.data['status'], 'NEW')
4095 self.assertEqual(A.reported, 0)
4096 self.assertEqual(B.reported, 0)
4097 self.assertEqual(len(self.history), 0)
4098
4099 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004100 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004101 B.setMerged()
4102 self.waitUntilSettled()
4103 self.assertEqual(len(self.history), 0)
4104
4105 # Now that B is merged, A should be able to be enqueued and
4106 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004107 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004108 self.waitUntilSettled()
4109
4110 self.assertEqual(A.data['status'], 'MERGED')
4111 self.assertEqual(A.reported, 2)
4112 self.assertEqual(B.data['status'], 'MERGED')
4113 self.assertEqual(B.reported, 0)
4114
James E. Blairec056492016-07-22 09:45:56 -07004115 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004116 def test_crd_check(self):
4117 "Test cross-repo dependencies in independent pipelines"
4118
4119 self.gearman_server.hold_jobs_in_queue = True
4120 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4121 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4122
4123 # A Depends-On: B
4124 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4125 A.subject, B.data['id'])
4126
4127 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4128 self.waitUntilSettled()
4129
4130 queue = self.gearman_server.getQueue()
4131 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4132 self.gearman_server.hold_jobs_in_queue = False
4133 self.gearman_server.release()
4134 self.waitUntilSettled()
4135
4136 path = os.path.join(self.git_root, "org/project1")
4137 repo = git.Repo(path)
4138 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4139 repo_messages.reverse()
4140 correct_messages = ['initial commit', 'A-1']
4141 self.assertEqual(repo_messages, correct_messages)
4142
4143 path = os.path.join(self.git_root, "org/project2")
4144 repo = git.Repo(path)
4145 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4146 repo_messages.reverse()
4147 correct_messages = ['initial commit', 'B-1']
4148 self.assertEqual(repo_messages, correct_messages)
4149
4150 self.assertEqual(A.data['status'], 'NEW')
4151 self.assertEqual(B.data['status'], 'NEW')
4152 self.assertEqual(A.reported, 1)
4153 self.assertEqual(B.reported, 0)
4154
4155 self.assertEqual(self.history[0].changes, '2,1 1,1')
4156 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004157
James E. Blairec056492016-07-22 09:45:56 -07004158 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004159 def test_crd_check_git_depends(self):
4160 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004161 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004162 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4163 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4164
4165 # Add two git-dependent changes and make sure they both report
4166 # success.
4167 B.setDependsOn(A, 1)
4168 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4169 self.waitUntilSettled()
4170 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4171 self.waitUntilSettled()
4172
James E. Blairb8c16472015-05-05 14:55:26 -07004173 self.orderedRelease()
4174 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004175 self.waitUntilSettled()
4176
4177 self.assertEqual(A.data['status'], 'NEW')
4178 self.assertEqual(B.data['status'], 'NEW')
4179 self.assertEqual(A.reported, 1)
4180 self.assertEqual(B.reported, 1)
4181
4182 self.assertEqual(self.history[0].changes, '1,1')
4183 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4184 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4185
4186 self.assertIn('Build succeeded', A.messages[0])
4187 self.assertIn('Build succeeded', B.messages[0])
4188
James E. Blairec056492016-07-22 09:45:56 -07004189 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004190 def test_crd_check_duplicate(self):
4191 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004192 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004193 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4194 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4195 check_pipeline = self.sched.layout.pipelines['check']
4196
4197 # Add two git-dependent changes...
4198 B.setDependsOn(A, 1)
4199 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4200 self.waitUntilSettled()
4201 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4202
4203 # ...make sure the live one is not duplicated...
4204 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4205 self.waitUntilSettled()
4206 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4207
4208 # ...but the non-live one is able to be.
4209 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4210 self.waitUntilSettled()
4211 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4212
Clark Boylandd849822015-03-02 12:38:14 -08004213 # Release jobs in order to avoid races with change A jobs
4214 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004215 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004216 self.launch_server.hold_jobs_in_build = False
4217 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004218 self.waitUntilSettled()
4219
4220 self.assertEqual(A.data['status'], 'NEW')
4221 self.assertEqual(B.data['status'], 'NEW')
4222 self.assertEqual(A.reported, 1)
4223 self.assertEqual(B.reported, 1)
4224
4225 self.assertEqual(self.history[0].changes, '1,1 2,1')
4226 self.assertEqual(self.history[1].changes, '1,1')
4227 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4228
4229 self.assertIn('Build succeeded', A.messages[0])
4230 self.assertIn('Build succeeded', B.messages[0])
4231
James E. Blairec056492016-07-22 09:45:56 -07004232 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004233 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004234 "Test cross-repo dependencies re-enqueued in independent pipelines"
4235
4236 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004237 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4238 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004239
4240 # A Depends-On: B
4241 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4242 A.subject, B.data['id'])
4243
4244 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4245 self.waitUntilSettled()
4246
4247 self.sched.reconfigure(self.config)
4248
4249 # Make sure the items still share a change queue, and the
4250 # first one is not live.
4251 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4252 queue = self.sched.layout.pipelines['check'].queues[0]
4253 first_item = queue.queue[0]
4254 for item in queue.queue:
4255 self.assertEqual(item.queue, first_item.queue)
4256 self.assertFalse(first_item.live)
4257 self.assertTrue(queue.queue[1].live)
4258
4259 self.gearman_server.hold_jobs_in_queue = False
4260 self.gearman_server.release()
4261 self.waitUntilSettled()
4262
4263 self.assertEqual(A.data['status'], 'NEW')
4264 self.assertEqual(B.data['status'], 'NEW')
4265 self.assertEqual(A.reported, 1)
4266 self.assertEqual(B.reported, 0)
4267
4268 self.assertEqual(self.history[0].changes, '2,1 1,1')
4269 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004270
James E. Blairec056492016-07-22 09:45:56 -07004271 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004272 def test_crd_check_reconfiguration(self):
4273 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4274
James E. Blairec056492016-07-22 09:45:56 -07004275 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004276 def test_crd_undefined_project(self):
4277 """Test that undefined projects in dependencies are handled for
4278 independent pipelines"""
4279 # It's a hack for fake gerrit,
4280 # as it implies repo creation upon the creation of any change
4281 self.init_repo("org/unknown")
4282 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4283
James E. Blairec056492016-07-22 09:45:56 -07004284 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004285 def test_crd_check_ignore_dependencies(self):
4286 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004287 self.updateConfigLayout(
4288 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004289 self.sched.reconfigure(self.config)
4290 self.registerJobs()
4291
4292 self.gearman_server.hold_jobs_in_queue = True
4293 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4294 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4295 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4296
4297 # A Depends-On: B
4298 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4299 A.subject, B.data['id'])
4300 # C git-depends on B
4301 C.setDependsOn(B, 1)
4302 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4303 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4304 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4305 self.waitUntilSettled()
4306
4307 # Make sure none of the items share a change queue, and all
4308 # are live.
4309 check_pipeline = self.sched.layout.pipelines['check']
4310 self.assertEqual(len(check_pipeline.queues), 3)
4311 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4312 for item in check_pipeline.getAllItems():
4313 self.assertTrue(item.live)
4314
4315 self.gearman_server.hold_jobs_in_queue = False
4316 self.gearman_server.release()
4317 self.waitUntilSettled()
4318
4319 self.assertEqual(A.data['status'], 'NEW')
4320 self.assertEqual(B.data['status'], 'NEW')
4321 self.assertEqual(C.data['status'], 'NEW')
4322 self.assertEqual(A.reported, 1)
4323 self.assertEqual(B.reported, 1)
4324 self.assertEqual(C.reported, 1)
4325
4326 # Each job should have tested exactly one change
4327 for job in self.history:
4328 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004329
James E. Blairec056492016-07-22 09:45:56 -07004330 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004331 def test_crd_check_transitive(self):
4332 "Test transitive cross-repo dependencies"
4333 # Specifically, if A -> B -> C, and C gets a new patchset and
4334 # A gets a new patchset, ensure the test of A,2 includes B,1
4335 # and C,2 (not C,1 which would indicate stale data in the
4336 # cache for B).
4337 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4338 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4339 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4340
4341 # A Depends-On: B
4342 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4343 A.subject, B.data['id'])
4344
4345 # B Depends-On: C
4346 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4347 B.subject, C.data['id'])
4348
4349 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4350 self.waitUntilSettled()
4351 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4352
4353 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4354 self.waitUntilSettled()
4355 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4356
4357 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4358 self.waitUntilSettled()
4359 self.assertEqual(self.history[-1].changes, '3,1')
4360
4361 C.addPatchset()
4362 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4363 self.waitUntilSettled()
4364 self.assertEqual(self.history[-1].changes, '3,2')
4365
4366 A.addPatchset()
4367 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4368 self.waitUntilSettled()
4369 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004370
James E. Blairec056492016-07-22 09:45:56 -07004371 @skip("Disabled for early v3 development")
James E. Blaira8b90b32016-08-24 15:18:50 -07004372 def test_crd_check_unknown(self):
4373 "Test unknown projects in independent pipeline"
4374 self.init_repo("org/unknown")
4375 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4376 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
4377 # A Depends-On: B
4378 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4379 A.subject, B.data['id'])
4380
4381 # Make sure zuul has seen an event on B.
4382 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4383 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4384 self.waitUntilSettled()
4385
4386 self.assertEqual(A.data['status'], 'NEW')
4387 self.assertEqual(A.reported, 1)
4388 self.assertEqual(B.data['status'], 'NEW')
4389 self.assertEqual(B.reported, 0)
4390
Joshua Heskethefeeb6d2016-09-20 14:42:37 +02004391 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004392 def test_crd_cycle_join(self):
4393 "Test an updated change creates a cycle"
4394 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4395
4396 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4397 self.waitUntilSettled()
4398
4399 # Create B->A
4400 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4401 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4402 B.subject, A.data['id'])
4403 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4404 self.waitUntilSettled()
4405
4406 # Update A to add A->B (a cycle).
4407 A.addPatchset()
4408 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4409 A.subject, B.data['id'])
4410 # Normally we would submit the patchset-created event for
4411 # processing here, however, we have no way of noting whether
4412 # the dependency cycle detection correctly raised an
4413 # exception, so instead, we reach into the source driver and
4414 # call the method that would ultimately be called by the event
4415 # processing.
4416
4417 source = self.sched.layout.pipelines['gate'].source
4418 with testtools.ExpectedException(
4419 Exception, "Dependency cycle detected"):
4420 source._getChange(u'1', u'2', True)
4421 self.log.debug("Got expected dependency cycle exception")
4422
4423 # Now if we update B to remove the depends-on, everything
4424 # should be okay. B; A->B
4425
4426 B.addPatchset()
4427 B.data['commitMessage'] = '%s\n' % (B.subject,)
4428 source._getChange(u'1', u'2', True)
4429 source._getChange(u'2', u'2', True)
4430
James E. Blairec056492016-07-22 09:45:56 -07004431 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004432 def test_disable_at(self):
4433 "Test a pipeline will only report to the disabled trigger when failing"
4434
James E. Blairf84026c2015-12-08 16:11:46 -08004435 self.updateConfigLayout(
4436 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004437 self.sched.reconfigure(self.config)
4438
4439 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4440 self.assertEqual(
4441 0, self.sched.layout.pipelines['check']._consecutive_failures)
4442 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4443
4444 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4445 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4446 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4447 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4448 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4449 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4450 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4451 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4452 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4453 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4454 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4455
James E. Blair08d19992016-08-10 15:25:31 -07004456 self.launch_server.failJob('project-test1', A)
4457 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004458 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004459 self.launch_server.failJob('project-test1', D)
4460 self.launch_server.failJob('project-test1', E)
4461 self.launch_server.failJob('project-test1', F)
4462 self.launch_server.failJob('project-test1', G)
4463 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004464 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004465 self.launch_server.failJob('project-test1', J)
4466 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004467
4468 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4469 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4470 self.waitUntilSettled()
4471
4472 self.assertEqual(
4473 2, self.sched.layout.pipelines['check']._consecutive_failures)
4474 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4475
4476 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4477 self.waitUntilSettled()
4478
4479 self.assertEqual(
4480 0, self.sched.layout.pipelines['check']._consecutive_failures)
4481 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4482
4483 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4484 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4485 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4486 self.waitUntilSettled()
4487
4488 # We should be disabled now
4489 self.assertEqual(
4490 3, self.sched.layout.pipelines['check']._consecutive_failures)
4491 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4492
4493 # We need to wait between each of these patches to make sure the
4494 # smtp messages come back in an expected order
4495 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4496 self.waitUntilSettled()
4497 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4498 self.waitUntilSettled()
4499 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4500 self.waitUntilSettled()
4501
4502 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4503 # leaving a message on each change
4504 self.assertEqual(1, len(A.messages))
4505 self.assertIn('Build failed.', A.messages[0])
4506 self.assertEqual(1, len(B.messages))
4507 self.assertIn('Build failed.', B.messages[0])
4508 self.assertEqual(1, len(C.messages))
4509 self.assertIn('Build succeeded.', C.messages[0])
4510 self.assertEqual(1, len(D.messages))
4511 self.assertIn('Build failed.', D.messages[0])
4512 self.assertEqual(1, len(E.messages))
4513 self.assertIn('Build failed.', E.messages[0])
4514 self.assertEqual(1, len(F.messages))
4515 self.assertIn('Build failed.', F.messages[0])
4516
4517 # The last 3 (GHI) would have only reported via smtp.
4518 self.assertEqual(3, len(self.smtp_messages))
4519 self.assertEqual(0, len(G.messages))
4520 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4521 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4522 self.assertEqual(0, len(H.messages))
4523 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4524 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4525 self.assertEqual(0, len(I.messages))
4526 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4527 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4528
4529 # Now reload the configuration (simulate a HUP) to check the pipeline
4530 # comes out of disabled
4531 self.sched.reconfigure(self.config)
4532
4533 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4534 self.assertEqual(
4535 0, self.sched.layout.pipelines['check']._consecutive_failures)
4536 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4537
4538 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4539 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4540 self.waitUntilSettled()
4541
4542 self.assertEqual(
4543 2, self.sched.layout.pipelines['check']._consecutive_failures)
4544 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4545
4546 # J and K went back to gerrit
4547 self.assertEqual(1, len(J.messages))
4548 self.assertIn('Build failed.', J.messages[0])
4549 self.assertEqual(1, len(K.messages))
4550 self.assertIn('Build failed.', K.messages[0])
4551 # No more messages reported via smtp
4552 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004553
James E. Blairec056492016-07-22 09:45:56 -07004554 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004555 def test_success_pattern(self):
4556 "Ensure bad build params are ignored"
4557
4558 # Use SMTP reporter to grab the result message easier
4559 self.init_repo("org/docs")
4560 self.config.set('zuul', 'layout_config',
4561 'tests/fixtures/layout-success-pattern.yaml')
4562 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004563 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004564 self.registerJobs()
4565
4566 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4567 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4568 self.waitUntilSettled()
4569
4570 # Grab build id
4571 self.assertEqual(len(self.builds), 1)
4572 uuid = self.builds[0].unique[:7]
4573
James E. Blair08d19992016-08-10 15:25:31 -07004574 self.launch_server.hold_jobs_in_build = False
4575 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004576 self.waitUntilSettled()
4577
4578 self.assertEqual(len(self.smtp_messages), 1)
4579 body = self.smtp_messages[0]['body'].splitlines()
4580 self.assertEqual('Build succeeded.', body[0])
4581
4582 self.assertIn(
4583 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4584 'docs-draft-test/%s/publish-docs/' % uuid,
4585 body[2])
4586 self.assertIn(
4587 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4588 body[3])
Arieb6f068c2016-10-09 13:11:06 +03004589
4590
4591class TestDuplicatePipeline(ZuulTestCase):
4592 tenant_config_file = 'config/duplicate-pipeline/main.yaml'
4593
4594 def test_duplicate_pipelines(self):
4595 "Test that a change matching multiple pipelines works"
4596
4597 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4598 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
4599 self.waitUntilSettled()
4600
4601 self.assertHistory([
4602 dict(name='project-test1', result='SUCCESS', changes='1,1',
4603 pipeline='dup1'),
4604 dict(name='project-test1', result='SUCCESS', changes='1,1',
4605 pipeline='dup2'),
4606 ])
4607
4608 self.assertEqual(len(A.messages), 2)
4609
4610 self.assertIn('dup1', A.messages[0])
4611 self.assertNotIn('dup2', A.messages[0])
4612 self.assertIn('project-test1', A.messages[0])
4613
4614 self.assertIn('dup2', A.messages[1])
4615 self.assertNotIn('dup1', A.messages[1])
4616 self.assertIn('project-test1', A.messages[1])
Paul Belangerfac69ba2016-11-03 09:03:13 -04004617
4618
4619class TestSchedulerOneJobProject(ZuulTestCase):
4620 tenant_config_file = 'config/one-job-project/main.yaml'
4621
4622 def test_one_job_project(self):
4623 "Test that queueing works with one job"
4624 A = self.fake_gerrit.addFakeChange('org/one-job-project',
4625 'master', 'A')
4626 B = self.fake_gerrit.addFakeChange('org/one-job-project',
4627 'master', 'B')
4628 A.addApproval('code-review', 2)
4629 B.addApproval('code-review', 2)
4630 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
4631 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
4632 self.waitUntilSettled()
4633
4634 self.assertEqual(A.data['status'], 'MERGED')
4635 self.assertEqual(A.reported, 2)
4636 self.assertEqual(B.data['status'], 'MERGED')
4637 self.assertEqual(B.reported, 2)
Paul Belanger86085b32016-11-03 12:48:57 -04004638
4639
4640class TestSchedulerTemplatedProject(ZuulTestCase):
4641 tenant_config_file = 'config/templated-project/main.yaml'
4642
4643 def test_job_from_templates_launched(self):
4644 "Test whether a job generated via a template can be launched"
4645
4646 A = self.fake_gerrit.addFakeChange(
4647 'org/templated-project', 'master', 'A')
4648 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4649 self.waitUntilSettled()
4650
4651 self.assertEqual(self.getJobFromHistory('project-test1').result,
4652 'SUCCESS')
4653 self.assertEqual(self.getJobFromHistory('project-test2').result,
4654 'SUCCESS')
Paul Belanger3adf72f2016-11-03 14:57:31 -04004655
4656 def test_layered_templates(self):
4657 "Test whether a job generated via a template can be launched"
4658
4659 A = self.fake_gerrit.addFakeChange(
4660 'org/layered-project', 'master', 'A')
4661 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4662 self.waitUntilSettled()
4663
4664 self.assertEqual(self.getJobFromHistory('project-test1').result,
4665 'SUCCESS')
4666 self.assertEqual(self.getJobFromHistory('project-test2').result,
4667 'SUCCESS')
4668 self.assertEqual(self.getJobFromHistory('layered-project-test3'
4669 ).result, 'SUCCESS')
4670 self.assertEqual(self.getJobFromHistory('layered-project-test4'
4671 ).result, 'SUCCESS')
4672 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
4673 ).result, 'SUCCESS')
4674 self.assertEqual(self.getJobFromHistory('project-test6').result,
4675 'SUCCESS')