blob: 1ce61fcc15e248b07257980f308f547bdf329837 [file] [log] [blame]
James E. Blairb0fcae42012-07-17 11:12:10 -07001#!/usr/bin/env python
2
3# Copyright 2012 Hewlett-Packard Development Company, L.P.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
James E. Blairb0fcae42012-07-17 11:12:10 -070017import json
Monty Taylorbc758832013-06-17 17:22:42 -040018import logging
19import os
James E. Blairb0fcae42012-07-17 11:12:10 -070020import re
James E. Blair4886cc12012-07-18 15:39:41 -070021import shutil
Monty Taylorbc758832013-06-17 17:22:42 -040022import time
Maru Newby3fe5f852015-01-13 04:22:14 +000023import yaml
James E. Blairec056492016-07-22 09:45:56 -070024from unittest import skip
Monty Taylorbc758832013-06-17 17:22:42 -040025
James E. Blair4886cc12012-07-18 15:39:41 -070026import git
Morgan Fainberg293f7f82016-05-30 14:01:22 -070027from six.moves import urllib
Monty Taylorbc758832013-06-17 17:22:42 -040028import testtools
James E. Blairb0fcae42012-07-17 11:12:10 -070029
Maru Newby3fe5f852015-01-13 04:22:14 +000030import zuul.change_matcher
James E. Blairb0fcae42012-07-17 11:12:10 -070031import zuul.scheduler
James E. Blairad28e912013-11-27 10:43:22 -080032import zuul.rpcclient
Joshua Hesketh1879cf72013-08-19 14:13:15 +100033import zuul.reporter.gerrit
Joshua Hesketh5fea8672013-08-19 17:32:01 +100034import zuul.reporter.smtp
James E. Blairb0fcae42012-07-17 11:12:10 -070035
Maru Newby3fe5f852015-01-13 04:22:14 +000036from tests.base import (
Maru Newby3fe5f852015-01-13 04:22:14 +000037 ZuulTestCase,
38 repack_repo,
39)
James E. Blairb0fcae42012-07-17 11:12:10 -070040
James E. Blair1f4c2bb2013-04-26 08:40:46 -070041logging.basicConfig(level=logging.DEBUG,
42 format='%(asctime)s %(name)-32s '
43 '%(levelname)-8s %(message)s')
James E. Blairb0fcae42012-07-17 11:12:10 -070044
45
Clark Boylanb640e052014-04-03 16:41:46 -070046class TestScheduler(ZuulTestCase):
James E. Blair552b54f2016-07-22 13:55:32 -070047 tenant_config_file = 'config/single-tenant/main.yaml'
Antoine Mussobd86a312014-01-08 14:51:33 +010048
James E. Blairb0fcae42012-07-17 11:12:10 -070049 def test_jobs_launched(self):
50 "Test that jobs are launched and a change is merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -070051
James E. Blairb0fcae42012-07-17 11:12:10 -070052 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -070053 A.addApproval('code-review', 2)
54 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -070055 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -040056 self.assertEqual(self.getJobFromHistory('project-merge').result,
57 'SUCCESS')
58 self.assertEqual(self.getJobFromHistory('project-test1').result,
59 'SUCCESS')
60 self.assertEqual(self.getJobFromHistory('project-test2').result,
61 'SUCCESS')
62 self.assertEqual(A.data['status'], 'MERGED')
63 self.assertEqual(A.reported, 2)
James E. Blair34776ee2016-08-25 13:53:54 -070064 self.assertEqual(self.getJobFromHistory('project-test1').node,
65 'image1')
James E. Blairb0fcae42012-07-17 11:12:10 -070066
James E. Blair552b54f2016-07-22 13:55:32 -070067 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070068 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
69 self.assertReportedStat('zuul.pipeline.gate.current_changes',
70 value='1|g')
71 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
72 kind='ms')
73 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
74 value='1|c')
75 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
76 self.assertReportedStat('zuul.pipeline.gate.total_changes',
77 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070078 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070079 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
James E. Blair412e5582013-04-22 15:50:12 -070080 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070081 'zuul.pipeline.gate.org.project.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070082
James E. Blair5821bd92015-09-16 08:48:15 -070083 for build in self.builds:
84 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
85
James E. Blair3cb10702013-08-24 08:56:03 -070086 def test_initial_pipeline_gauges(self):
87 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070088 self.assertReportedStat('zuul.pipeline.gate.current_changes',
89 value='0|g')
90 self.assertReportedStat('zuul.pipeline.check.current_changes',
91 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070092
James E. Blair34776ee2016-08-25 13:53:54 -070093 def test_job_branch(self):
94 "Test the correct variant of a job runs on a branch"
95 self.create_branch('org/project', 'stable')
96 A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A')
97 A.addApproval('code-review', 2)
98 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
99 self.waitUntilSettled()
100 self.assertEqual(self.getJobFromHistory('project-test1').result,
101 'SUCCESS')
102 self.assertEqual(self.getJobFromHistory('project-test2').result,
103 'SUCCESS')
104 self.assertEqual(A.data['status'], 'MERGED')
105 self.assertEqual(A.reported, 2,
106 "A should report start and success")
107 self.assertIn('gate', A.messages[1],
108 "A should transit gate")
109 self.assertEqual(self.getJobFromHistory('project-test1').node,
110 'image2')
111
James E. Blairec056492016-07-22 09:45:56 -0700112 @skip("Disabled for early v3 development")
James E. Blair42f74822013-05-14 15:18:03 -0700113 def test_duplicate_pipelines(self):
114 "Test that a change matching multiple pipelines works"
James E. Blair1b4d9722013-05-21 10:32:04 -0700115
James E. Blair42f74822013-05-14 15:18:03 -0700116 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
117 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
118 self.waitUntilSettled()
James E. Blair42f74822013-05-14 15:18:03 -0700119
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400120 self.assertEqual(len(self.history), 2)
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400121 self.history[0].name == 'project-test1'
122 self.history[1].name == 'project-test1'
James E. Blair42f74822013-05-14 15:18:03 -0700123
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400124 self.assertEqual(len(A.messages), 2)
James E. Blair42f74822013-05-14 15:18:03 -0700125 if 'dup1/project-test1' in A.messages[0]:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400126 self.assertIn('dup1/project-test1', A.messages[0])
127 self.assertNotIn('dup2/project-test1', A.messages[0])
128 self.assertNotIn('dup1/project-test1', A.messages[1])
129 self.assertIn('dup2/project-test1', A.messages[1])
James E. Blair42f74822013-05-14 15:18:03 -0700130 else:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400131 self.assertIn('dup1/project-test1', A.messages[1])
132 self.assertNotIn('dup2/project-test1', A.messages[1])
133 self.assertNotIn('dup1/project-test1', A.messages[0])
134 self.assertIn('dup2/project-test1', A.messages[0])
James E. Blair42f74822013-05-14 15:18:03 -0700135
James E. Blairb0fcae42012-07-17 11:12:10 -0700136 def test_parallel_changes(self):
137 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700138
James E. Blair791b5392016-08-03 11:25:56 -0700139 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700140 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
141 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
142 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700143 A.addApproval('code-review', 2)
144 B.addApproval('code-review', 2)
145 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700146
James E. Blair8b5408c2016-08-08 15:37:46 -0700147 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
148 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
149 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700150
151 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400152 self.assertEqual(len(self.builds), 1)
153 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700154 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700155
James E. Blair791b5392016-08-03 11:25:56 -0700156 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700157 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400158 self.assertEqual(len(self.builds), 3)
159 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700160 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400161 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700162 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400163 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700164 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700165
James E. Blair791b5392016-08-03 11:25:56 -0700166 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700167 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400168 self.assertEqual(len(self.builds), 5)
169 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700170 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400171 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700172 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700173
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400174 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700175 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400176 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700177 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700178
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400179 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700180 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700181
James E. Blair791b5392016-08-03 11:25:56 -0700182 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700183 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400184 self.assertEqual(len(self.builds), 6)
185 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700186 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400187 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700188 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700189
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400190 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700191 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400192 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700193 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700194
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400195 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700196 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400197 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700198 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700199
James E. Blair791b5392016-08-03 11:25:56 -0700200 self.launch_server.hold_jobs_in_build = False
201 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700202 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400203 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700204
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400205 self.assertEqual(len(self.history), 9)
206 self.assertEqual(A.data['status'], 'MERGED')
207 self.assertEqual(B.data['status'], 'MERGED')
208 self.assertEqual(C.data['status'], 'MERGED')
209 self.assertEqual(A.reported, 2)
210 self.assertEqual(B.reported, 2)
211 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700212
213 def test_failed_changes(self):
214 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700215 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700216
James E. Blairb02a3bb2012-07-30 17:49:55 -0700217 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
218 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700219 A.addApproval('code-review', 2)
220 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700221
James E. Blair08d19992016-08-10 15:25:31 -0700222 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700223
James E. Blair8b5408c2016-08-08 15:37:46 -0700224 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
225 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700226 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700227 self.assertBuilds([dict(name='project-merge', changes='1,1')])
James E. Blaire2819012013-06-28 17:17:26 -0400228
James E. Blair08d19992016-08-10 15:25:31 -0700229 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400230 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700231 # A/project-merge is complete
232 self.assertBuilds([
233 dict(name='project-test1', changes='1,1'),
234 dict(name='project-test2', changes='1,1'),
235 dict(name='project-merge', changes='1,1 2,1'),
236 ])
James E. Blaire2819012013-06-28 17:17:26 -0400237
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700238 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400239 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700240 # A/project-merge is complete
241 # B/project-merge is complete
242 self.assertBuilds([
243 dict(name='project-test1', changes='1,1'),
244 dict(name='project-test2', changes='1,1'),
245 dict(name='project-test1', changes='1,1 2,1'),
246 dict(name='project-test2', changes='1,1 2,1'),
247 ])
248
249 # Release project-test1 for A which will fail. This will
250 # abort both running B jobs and relaunch project-merge for B.
251 self.builds[0].release()
252 self.waitUntilSettled()
253
254 self.orderedRelease()
255 self.assertHistory([
256 dict(name='project-merge', result='SUCCESS', changes='1,1'),
257 dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'),
258 dict(name='project-test1', result='FAILURE', changes='1,1'),
259 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
260 dict(name='project-test2', result='ABORTED', changes='1,1 2,1'),
261 dict(name='project-test2', result='SUCCESS', changes='1,1'),
262 dict(name='project-merge', result='SUCCESS', changes='2,1'),
263 dict(name='project-test1', result='SUCCESS', changes='2,1'),
264 dict(name='project-test2', result='SUCCESS', changes='2,1'),
James E. Blairb536ecc2016-08-31 10:11:42 -0700265 ], ordered=False)
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700266
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400267 self.assertEqual(A.data['status'], 'NEW')
268 self.assertEqual(B.data['status'], 'MERGED')
269 self.assertEqual(A.reported, 2)
270 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700271
272 def test_independent_queues(self):
273 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700274
James E. Blair08d19992016-08-10 15:25:31 -0700275 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900276 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700277 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
278 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700279 A.addApproval('code-review', 2)
280 B.addApproval('code-review', 2)
281 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700282
James E. Blair8b5408c2016-08-08 15:37:46 -0700283 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
284 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
285 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700286
James E. Blairb02a3bb2012-07-30 17:49:55 -0700287 self.waitUntilSettled()
288
289 # There should be one merge job at the head of each queue running
James E. Blair5f0d49e2016-08-19 09:36:50 -0700290 self.assertBuilds([
291 dict(name='project-merge', changes='1,1'),
292 dict(name='project-merge', changes='2,1'),
293 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700294
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700295 # Release the current merge builds
James E. Blair5f0d49e2016-08-19 09:36:50 -0700296 self.builds[0].release()
297 self.waitUntilSettled()
298 self.builds[0].release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700299 self.waitUntilSettled()
300 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700301 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700302 self.waitUntilSettled()
303
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700304 # All the test builds should be running:
James E. Blair5f0d49e2016-08-19 09:36:50 -0700305 self.assertBuilds([
306 dict(name='project-test1', changes='1,1'),
307 dict(name='project-test2', changes='1,1'),
308 dict(name='project-test1', changes='2,1'),
309 dict(name='project-test2', changes='2,1'),
310 dict(name='project-test1', changes='2,1 3,1'),
311 dict(name='project-test2', changes='2,1 3,1'),
312 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700313
James E. Blair5f0d49e2016-08-19 09:36:50 -0700314 self.orderedRelease()
315 self.assertHistory([
316 dict(name='project-merge', result='SUCCESS', changes='1,1'),
317 dict(name='project-merge', result='SUCCESS', changes='2,1'),
318 dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'),
319 dict(name='project-test1', result='SUCCESS', changes='1,1'),
320 dict(name='project-test2', result='SUCCESS', changes='1,1'),
321 dict(name='project-test1', result='SUCCESS', changes='2,1'),
322 dict(name='project-test2', result='SUCCESS', changes='2,1'),
323 dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'),
324 dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'),
325 ])
James E. Blairb02a3bb2012-07-30 17:49:55 -0700326
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400327 self.assertEqual(A.data['status'], 'MERGED')
328 self.assertEqual(B.data['status'], 'MERGED')
329 self.assertEqual(C.data['status'], 'MERGED')
330 self.assertEqual(A.reported, 2)
331 self.assertEqual(B.reported, 2)
332 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700333
334 def test_failed_change_at_head(self):
335 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700336
James E. Blair08d19992016-08-10 15:25:31 -0700337 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700338 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
339 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
340 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700341 A.addApproval('code-review', 2)
342 B.addApproval('code-review', 2)
343 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700344
James E. Blair08d19992016-08-10 15:25:31 -0700345 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700346
James E. Blair8b5408c2016-08-08 15:37:46 -0700347 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
348 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
349 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700350
351 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700352
James E. Blairb536ecc2016-08-31 10:11:42 -0700353 self.assertBuilds([
354 dict(name='project-merge', changes='1,1'),
355 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700356
James E. Blair08d19992016-08-10 15:25:31 -0700357 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700358 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700359 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700360 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700361 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700362 self.waitUntilSettled()
363
James E. Blairb536ecc2016-08-31 10:11:42 -0700364 self.assertBuilds([
365 dict(name='project-test1', changes='1,1'),
366 dict(name='project-test2', changes='1,1'),
367 dict(name='project-test1', changes='1,1 2,1'),
368 dict(name='project-test2', changes='1,1 2,1'),
369 dict(name='project-test1', changes='1,1 2,1 3,1'),
370 dict(name='project-test2', changes='1,1 2,1 3,1'),
371 ])
James E. Blaird466dc42012-07-31 10:42:56 -0700372
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400373 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700374 self.waitUntilSettled()
375
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400376 # project-test2, project-merge for B
James E. Blairb536ecc2016-08-31 10:11:42 -0700377 self.assertBuilds([
378 dict(name='project-test2', changes='1,1'),
379 dict(name='project-merge', changes='2,1'),
380 ])
381 # Unordered history comparison because the aborts can finish
382 # in any order.
383 self.assertHistory([
384 dict(name='project-merge', result='SUCCESS',
385 changes='1,1'),
386 dict(name='project-merge', result='SUCCESS',
387 changes='1,1 2,1'),
388 dict(name='project-merge', result='SUCCESS',
389 changes='1,1 2,1 3,1'),
390 dict(name='project-test1', result='FAILURE',
391 changes='1,1'),
392 dict(name='project-test1', result='ABORTED',
393 changes='1,1 2,1'),
394 dict(name='project-test2', result='ABORTED',
395 changes='1,1 2,1'),
396 dict(name='project-test1', result='ABORTED',
397 changes='1,1 2,1 3,1'),
398 dict(name='project-test2', result='ABORTED',
399 changes='1,1 2,1 3,1'),
400 ], ordered=False)
James E. Blaird466dc42012-07-31 10:42:56 -0700401
James E. Blairb536ecc2016-08-31 10:11:42 -0700402 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700403 self.waitUntilSettled()
James E. Blairb536ecc2016-08-31 10:11:42 -0700404 self.launch_server.release('.*-merge')
405 self.waitUntilSettled()
406 self.orderedRelease()
James E. Blaird466dc42012-07-31 10:42:56 -0700407
James E. Blairb536ecc2016-08-31 10:11:42 -0700408 self.assertBuilds([])
409 self.assertHistory([
410 dict(name='project-merge', result='SUCCESS',
411 changes='1,1'),
412 dict(name='project-merge', result='SUCCESS',
413 changes='1,1 2,1'),
414 dict(name='project-merge', result='SUCCESS',
415 changes='1,1 2,1 3,1'),
416 dict(name='project-test1', result='FAILURE',
417 changes='1,1'),
418 dict(name='project-test1', result='ABORTED',
419 changes='1,1 2,1'),
420 dict(name='project-test2', result='ABORTED',
421 changes='1,1 2,1'),
422 dict(name='project-test1', result='ABORTED',
423 changes='1,1 2,1 3,1'),
424 dict(name='project-test2', result='ABORTED',
425 changes='1,1 2,1 3,1'),
426 dict(name='project-merge', result='SUCCESS',
427 changes='2,1'),
428 dict(name='project-merge', result='SUCCESS',
429 changes='2,1 3,1'),
430 dict(name='project-test2', result='SUCCESS',
431 changes='1,1'),
432 dict(name='project-test1', result='SUCCESS',
433 changes='2,1'),
434 dict(name='project-test2', result='SUCCESS',
435 changes='2,1'),
436 dict(name='project-test1', result='SUCCESS',
437 changes='2,1 3,1'),
438 dict(name='project-test2', result='SUCCESS',
439 changes='2,1 3,1'),
440 ], ordered=False)
441
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400442 self.assertEqual(A.data['status'], 'NEW')
443 self.assertEqual(B.data['status'], 'MERGED')
444 self.assertEqual(C.data['status'], 'MERGED')
445 self.assertEqual(A.reported, 2)
446 self.assertEqual(B.reported, 2)
447 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700448
James E. Blairec056492016-07-22 09:45:56 -0700449 @skip("Disabled for early v3 development")
James E. Blair0aac4872013-08-23 14:02:38 -0700450 def test_failed_change_in_middle(self):
451 "Test a failed change in the middle of the queue"
452
James E. Blair08d19992016-08-10 15:25:31 -0700453 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700454 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
455 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
456 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700457 A.addApproval('code-review', 2)
458 B.addApproval('code-review', 2)
459 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700460
James E. Blair08d19992016-08-10 15:25:31 -0700461 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700462
James E. Blair8b5408c2016-08-08 15:37:46 -0700463 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
464 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
465 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700466
467 self.waitUntilSettled()
468
James E. Blair08d19992016-08-10 15:25:31 -0700469 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700470 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700471 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700472 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700473 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700474 self.waitUntilSettled()
475
476 self.assertEqual(len(self.builds), 6)
477 self.assertEqual(self.builds[0].name, 'project-test1')
478 self.assertEqual(self.builds[1].name, 'project-test2')
479 self.assertEqual(self.builds[2].name, 'project-test1')
480 self.assertEqual(self.builds[3].name, 'project-test2')
481 self.assertEqual(self.builds[4].name, 'project-test1')
482 self.assertEqual(self.builds[5].name, 'project-test2')
483
484 self.release(self.builds[2])
485 self.waitUntilSettled()
486
James E. Blair972e3c72013-08-29 12:04:55 -0700487 # project-test1 and project-test2 for A
488 # project-test2 for B
489 # project-merge for C (without B)
490 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700491 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
492
James E. Blair08d19992016-08-10 15:25:31 -0700493 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700494 self.waitUntilSettled()
495
496 # project-test1 and project-test2 for A
497 # project-test2 for B
498 # project-test1 and project-test2 for C
499 self.assertEqual(len(self.builds), 5)
500
James E. Blair0aac4872013-08-23 14:02:38 -0700501 items = self.sched.layout.pipelines['gate'].getAllItems()
502 builds = items[0].current_build_set.getBuilds()
503 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
504 self.assertEqual(self.countJobResults(builds, None), 2)
505 builds = items[1].current_build_set.getBuilds()
506 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
507 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
508 self.assertEqual(self.countJobResults(builds, None), 1)
509 builds = items[2].current_build_set.getBuilds()
510 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700511 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700512
James E. Blair08d19992016-08-10 15:25:31 -0700513 self.launch_server.hold_jobs_in_build = False
514 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700515 self.waitUntilSettled()
516
517 self.assertEqual(len(self.builds), 0)
518 self.assertEqual(len(self.history), 12)
519 self.assertEqual(A.data['status'], 'MERGED')
520 self.assertEqual(B.data['status'], 'NEW')
521 self.assertEqual(C.data['status'], 'MERGED')
522 self.assertEqual(A.reported, 2)
523 self.assertEqual(B.reported, 2)
524 self.assertEqual(C.reported, 2)
525
James E. Blairec056492016-07-22 09:45:56 -0700526 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700527 def test_failed_change_at_head_with_queue(self):
528 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700529
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700530 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700531 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
532 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
533 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700534 A.addApproval('code-review', 2)
535 B.addApproval('code-review', 2)
536 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700537
James E. Blair08d19992016-08-10 15:25:31 -0700538 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700539
James E. Blair8b5408c2016-08-08 15:37:46 -0700540 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
541 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
542 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700543
544 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700545 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400546 self.assertEqual(len(self.builds), 0)
547 self.assertEqual(len(queue), 1)
548 self.assertEqual(queue[0].name, 'build:project-merge')
549 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700550
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700551 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700552 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700553 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700554 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700555 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700556 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700557 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700558
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400559 self.assertEqual(len(self.builds), 0)
560 self.assertEqual(len(queue), 6)
561 self.assertEqual(queue[0].name, 'build:project-test1')
562 self.assertEqual(queue[1].name, 'build:project-test2')
563 self.assertEqual(queue[2].name, 'build:project-test1')
564 self.assertEqual(queue[3].name, 'build:project-test2')
565 self.assertEqual(queue[4].name, 'build:project-test1')
566 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700567
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700568 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700569 self.waitUntilSettled()
570
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400571 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700572 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400573 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
574 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700575
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700576 self.gearman_server.hold_jobs_in_queue = False
577 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700578 self.waitUntilSettled()
579
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400580 self.assertEqual(len(self.builds), 0)
581 self.assertEqual(len(self.history), 11)
582 self.assertEqual(A.data['status'], 'NEW')
583 self.assertEqual(B.data['status'], 'MERGED')
584 self.assertEqual(C.data['status'], 'MERGED')
585 self.assertEqual(A.reported, 2)
586 self.assertEqual(B.reported, 2)
587 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700588
James E. Blairec056492016-07-22 09:45:56 -0700589 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700590 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700591 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700592 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700593 A.addApproval('code-review', 2)
594 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700595 self.waitUntilSettled()
596 time.sleep(2)
597
598 data = json.loads(self.sched.formatStatusJSON())
599 found_job = None
600 for pipeline in data['pipelines']:
601 if pipeline['name'] != 'gate':
602 continue
603 for queue in pipeline['change_queues']:
604 for head in queue['heads']:
605 for item in head:
606 for job in item['jobs']:
607 if job['name'] == 'project-merge':
608 found_job = job
609 break
610
611 self.assertIsNotNone(found_job)
612 if iteration == 1:
613 self.assertIsNotNone(found_job['estimated_time'])
614 self.assertIsNone(found_job['remaining_time'])
615 else:
616 self.assertIsNotNone(found_job['estimated_time'])
617 self.assertTrue(found_job['estimated_time'] >= 2)
618 self.assertIsNotNone(found_job['remaining_time'])
619
James E. Blair08d19992016-08-10 15:25:31 -0700620 self.launch_server.hold_jobs_in_build = False
621 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700622 self.waitUntilSettled()
623
James E. Blairec056492016-07-22 09:45:56 -0700624 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700625 def test_time_database(self):
626 "Test the time database"
627
628 self._test_time_database(1)
629 self._test_time_database(2)
630
James E. Blairec056492016-07-22 09:45:56 -0700631 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700632 def test_two_failed_changes_at_head(self):
633 "Test that changes are reparented correctly if 2 fail at head"
634
James E. Blair08d19992016-08-10 15:25:31 -0700635 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700636 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
637 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
638 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700639 A.addApproval('code-review', 2)
640 B.addApproval('code-review', 2)
641 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700642
James E. Blair08d19992016-08-10 15:25:31 -0700643 self.launch_server.failJob('project-test1', A)
644 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700645
James E. Blair8b5408c2016-08-08 15:37:46 -0700646 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
647 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
648 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700649 self.waitUntilSettled()
650
James E. Blair08d19992016-08-10 15:25:31 -0700651 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700652 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700653 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700654 self.waitUntilSettled()
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), 6)
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-test1')
662 self.assertEqual(self.builds[3].name, 'project-test2')
663 self.assertEqual(self.builds[4].name, 'project-test1')
664 self.assertEqual(self.builds[5].name, 'project-test2')
665
666 self.assertTrue(self.job_has_changes(self.builds[0], A))
667 self.assertTrue(self.job_has_changes(self.builds[2], A))
668 self.assertTrue(self.job_has_changes(self.builds[2], B))
669 self.assertTrue(self.job_has_changes(self.builds[4], A))
670 self.assertTrue(self.job_has_changes(self.builds[4], B))
671 self.assertTrue(self.job_has_changes(self.builds[4], C))
672
673 # Fail change B first
674 self.release(self.builds[2])
675 self.waitUntilSettled()
676
677 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700678 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700679 self.waitUntilSettled()
680
681 self.assertEqual(len(self.builds), 5)
682 self.assertEqual(self.builds[0].name, 'project-test1')
683 self.assertEqual(self.builds[1].name, 'project-test2')
684 self.assertEqual(self.builds[2].name, 'project-test2')
685 self.assertEqual(self.builds[3].name, 'project-test1')
686 self.assertEqual(self.builds[4].name, 'project-test2')
687
688 self.assertTrue(self.job_has_changes(self.builds[1], A))
689 self.assertTrue(self.job_has_changes(self.builds[2], A))
690 self.assertTrue(self.job_has_changes(self.builds[2], B))
691 self.assertTrue(self.job_has_changes(self.builds[4], A))
692 self.assertFalse(self.job_has_changes(self.builds[4], B))
693 self.assertTrue(self.job_has_changes(self.builds[4], C))
694
695 # Finish running all passing jobs for change A
696 self.release(self.builds[1])
697 self.waitUntilSettled()
698 # Fail and report change A
699 self.release(self.builds[0])
700 self.waitUntilSettled()
701
702 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700703 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700704 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700705 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700706 self.waitUntilSettled()
707
708 self.assertEqual(len(self.builds), 4)
709 self.assertEqual(self.builds[0].name, 'project-test1') # B
710 self.assertEqual(self.builds[1].name, 'project-test2') # B
711 self.assertEqual(self.builds[2].name, 'project-test1') # C
712 self.assertEqual(self.builds[3].name, 'project-test2') # C
713
714 self.assertFalse(self.job_has_changes(self.builds[1], A))
715 self.assertTrue(self.job_has_changes(self.builds[1], B))
716 self.assertFalse(self.job_has_changes(self.builds[1], C))
717
718 self.assertFalse(self.job_has_changes(self.builds[2], A))
719 # After A failed and B and C restarted, B should be back in
720 # C's tests because it has not failed yet.
721 self.assertTrue(self.job_has_changes(self.builds[2], B))
722 self.assertTrue(self.job_has_changes(self.builds[2], C))
723
James E. Blair08d19992016-08-10 15:25:31 -0700724 self.launch_server.hold_jobs_in_build = False
725 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700726 self.waitUntilSettled()
727
728 self.assertEqual(len(self.builds), 0)
729 self.assertEqual(len(self.history), 21)
730 self.assertEqual(A.data['status'], 'NEW')
731 self.assertEqual(B.data['status'], 'NEW')
732 self.assertEqual(C.data['status'], 'MERGED')
733 self.assertEqual(A.reported, 2)
734 self.assertEqual(B.reported, 2)
735 self.assertEqual(C.reported, 2)
736
James E. Blairec056492016-07-22 09:45:56 -0700737 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700738 def test_parse_skip_if(self):
739 job_yaml = """
740jobs:
741 - name: job_name
742 skip-if:
743 - project: ^project_name$
744 branch: ^stable/icehouse$
745 all-files-match-any:
746 - ^filename$
747 - project: ^project2_name$
748 all-files-match-any:
749 - ^filename2$
750 """.strip()
751 data = yaml.load(job_yaml)
752 config_job = data.get('jobs')[0]
753 cm = zuul.change_matcher
754 expected = cm.MatchAny([
755 cm.MatchAll([
756 cm.ProjectMatcher('^project_name$'),
757 cm.BranchMatcher('^stable/icehouse$'),
758 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
759 ]),
760 cm.MatchAll([
761 cm.ProjectMatcher('^project2_name$'),
762 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
763 ]),
764 ])
765 matcher = self.sched._parseSkipIf(config_job)
766 self.assertEqual(expected, matcher)
767
James E. Blairec056492016-07-22 09:45:56 -0700768 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700769 def test_patch_order(self):
770 "Test that dependent patches are tested in the right order"
771 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
772 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
773 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700774 A.addApproval('code-review', 2)
775 B.addApproval('code-review', 2)
776 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700777
778 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
779 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
780 M2.setMerged()
781 M1.setMerged()
782
783 # C -> B -> A -> M1 -> M2
784 # M2 is here to make sure it is never queried. If it is, it
785 # means zuul is walking down the entire history of merged
786 # changes.
787
788 C.setDependsOn(B, 1)
789 B.setDependsOn(A, 1)
790 A.setDependsOn(M1, 1)
791 M1.setDependsOn(M2, 1)
792
James E. Blair8b5408c2016-08-08 15:37:46 -0700793 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700794
795 self.waitUntilSettled()
796
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400797 self.assertEqual(A.data['status'], 'NEW')
798 self.assertEqual(B.data['status'], 'NEW')
799 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700800
James E. Blair8b5408c2016-08-08 15:37:46 -0700801 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
802 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700803
804 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400805 self.assertEqual(M2.queried, 0)
806 self.assertEqual(A.data['status'], 'MERGED')
807 self.assertEqual(B.data['status'], 'MERGED')
808 self.assertEqual(C.data['status'], 'MERGED')
809 self.assertEqual(A.reported, 2)
810 self.assertEqual(B.reported, 2)
811 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700812
James E. Blairec056492016-07-22 09:45:56 -0700813 @skip("Disabled for early v3 development")
James E. Blair063672f2015-01-29 13:09:12 -0800814 def test_needed_changes_enqueue(self):
815 "Test that a needed change is enqueued ahead"
816 # A Given a git tree like this, if we enqueue
817 # / \ change C, we should walk up and down the tree
818 # B G and enqueue changes in the order ABCDEFG.
819 # /|\ This is also the order that you would get if
820 # *C E F you enqueued changes in the order ABCDEFG, so
821 # / the ordering is stable across re-enqueue events.
822 # D
823
824 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
825 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
826 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
827 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
828 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
829 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
830 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
831 B.setDependsOn(A, 1)
832 C.setDependsOn(B, 1)
833 D.setDependsOn(C, 1)
834 E.setDependsOn(B, 1)
835 F.setDependsOn(B, 1)
836 G.setDependsOn(A, 1)
837
James E. Blair8b5408c2016-08-08 15:37:46 -0700838 A.addApproval('code-review', 2)
839 B.addApproval('code-review', 2)
840 C.addApproval('code-review', 2)
841 D.addApproval('code-review', 2)
842 E.addApproval('code-review', 2)
843 F.addApproval('code-review', 2)
844 G.addApproval('code-review', 2)
845 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800846
847 self.waitUntilSettled()
848
849 self.assertEqual(A.data['status'], 'NEW')
850 self.assertEqual(B.data['status'], 'NEW')
851 self.assertEqual(C.data['status'], 'NEW')
852 self.assertEqual(D.data['status'], 'NEW')
853 self.assertEqual(E.data['status'], 'NEW')
854 self.assertEqual(F.data['status'], 'NEW')
855 self.assertEqual(G.data['status'], 'NEW')
856
857 # We're about to add approvals to changes without adding the
858 # triggering events to Zuul, so that we can be sure that it is
859 # enqueing the changes based on dependencies, not because of
860 # triggering events. Since it will have the changes cached
861 # already (without approvals), we need to clear the cache
862 # first.
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100863 for connection in self.connections.values():
864 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800865
James E. Blair08d19992016-08-10 15:25:31 -0700866 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700867 A.addApproval('approved', 1)
868 B.addApproval('approved', 1)
869 D.addApproval('approved', 1)
870 E.addApproval('approved', 1)
871 F.addApproval('approved', 1)
872 G.addApproval('approved', 1)
873 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800874
875 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700876 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800877 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700878 self.launch_server.hold_jobs_in_build = False
879 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800880 self.waitUntilSettled()
881
882 self.assertEqual(A.data['status'], 'MERGED')
883 self.assertEqual(B.data['status'], 'MERGED')
884 self.assertEqual(C.data['status'], 'MERGED')
885 self.assertEqual(D.data['status'], 'MERGED')
886 self.assertEqual(E.data['status'], 'MERGED')
887 self.assertEqual(F.data['status'], 'MERGED')
888 self.assertEqual(G.data['status'], 'MERGED')
889 self.assertEqual(A.reported, 2)
890 self.assertEqual(B.reported, 2)
891 self.assertEqual(C.reported, 2)
892 self.assertEqual(D.reported, 2)
893 self.assertEqual(E.reported, 2)
894 self.assertEqual(F.reported, 2)
895 self.assertEqual(G.reported, 2)
896 self.assertEqual(self.history[6].changes,
897 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
898
James E. Blairec056492016-07-22 09:45:56 -0700899 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100900 def test_source_cache(self):
901 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700902 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700903
904 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
905 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
906 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700907 A.addApproval('code-review', 2)
908 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700909
910 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
911 M1.setMerged()
912
913 B.setDependsOn(A, 1)
914 A.setDependsOn(M1, 1)
915
James E. Blair8b5408c2016-08-08 15:37:46 -0700916 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700917 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
918
919 self.waitUntilSettled()
920
921 for build in self.builds:
922 if build.parameters['ZUUL_PIPELINE'] == 'check':
923 build.release()
924 self.waitUntilSettled()
925 for build in self.builds:
926 if build.parameters['ZUUL_PIPELINE'] == 'check':
927 build.release()
928 self.waitUntilSettled()
929
James E. Blair8b5408c2016-08-08 15:37:46 -0700930 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700931 self.waitUntilSettled()
932
Joshua Hesketh352264b2015-08-11 23:42:08 +1000933 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700934 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000935 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700936
James E. Blair08d19992016-08-10 15:25:31 -0700937 self.launch_server.hold_jobs_in_build = False
938 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700939 self.waitUntilSettled()
940
941 self.assertEqual(A.data['status'], 'MERGED')
942 self.assertEqual(B.data['status'], 'MERGED')
943 self.assertEqual(A.queried, 2) # Initial and isMerged
944 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
945
James E. Blairec056492016-07-22 09:45:56 -0700946 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700947 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700948 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700949 # TODO: move to test_gerrit (this is a unit test!)
950 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairc0dedf82014-08-06 09:37:52 -0700951 source = self.sched.layout.pipelines['gate'].source
952 a = source._getChange(1, 2)
James E. Blaireff88162013-07-01 12:44:14 -0400953 mgr = self.sched.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700954 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700955
James E. Blair8b5408c2016-08-08 15:37:46 -0700956 A.addApproval('code-review', 2)
James E. Blairc0dedf82014-08-06 09:37:52 -0700957 a = source._getChange(1, 2, refresh=True)
958 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700959
James E. Blair8b5408c2016-08-08 15:37:46 -0700960 A.addApproval('approved', 1)
James E. Blairc0dedf82014-08-06 09:37:52 -0700961 a = source._getChange(1, 2, refresh=True)
962 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700963
James E. Blairec056492016-07-22 09:45:56 -0700964 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700965 def test_build_configuration(self):
966 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700967
968 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700969 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
970 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
971 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700972 A.addApproval('code-review', 2)
973 B.addApproval('code-review', 2)
974 C.addApproval('code-review', 2)
975 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
976 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
977 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700978 self.waitUntilSettled()
979
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700980 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700981 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700982 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700983 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700984 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700985 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700986 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700987 ref = self.getParameter(queue[-1], 'ZUUL_REF')
988 self.gearman_server.hold_jobs_in_queue = False
989 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700990 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700991
Monty Taylorbc758832013-06-17 17:22:42 -0400992 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700993 repo = git.Repo(path)
994 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
995 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700996 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400997 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700998
James E. Blairec056492016-07-22 09:45:56 -0700999 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -07001000 def test_build_configuration_conflict(self):
1001 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001002
1003 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -07001004 A = self.fake_gerrit.addFakeChange('org/conflict-project',
1005 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -07001006 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -07001007 B = self.fake_gerrit.addFakeChange('org/conflict-project',
1008 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -07001009 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -07001010 C = self.fake_gerrit.addFakeChange('org/conflict-project',
1011 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001012 A.addApproval('code-review', 2)
1013 B.addApproval('code-review', 2)
1014 C.addApproval('code-review', 2)
1015 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1016 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1017 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -07001018 self.waitUntilSettled()
1019
James E. Blair6736beb2013-07-11 15:18:15 -07001020 self.assertEqual(A.reported, 1)
1021 self.assertEqual(B.reported, 1)
1022 self.assertEqual(C.reported, 1)
1023
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001024 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001025 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001026 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001027 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001028 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -07001029 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -07001030
1031 self.assertEqual(len(self.history), 2) # A and C merge jobs
1032
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001033 self.gearman_server.hold_jobs_in_queue = False
1034 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -07001035 self.waitUntilSettled()
1036
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001037 self.assertEqual(A.data['status'], 'MERGED')
1038 self.assertEqual(B.data['status'], 'NEW')
1039 self.assertEqual(C.data['status'], 'MERGED')
1040 self.assertEqual(A.reported, 2)
1041 self.assertEqual(B.reported, 2)
1042 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001043 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -07001044
James E. Blairec056492016-07-22 09:45:56 -07001045 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -07001046 def test_post(self):
1047 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001048
Zhongyue Luo5d556072012-09-21 02:00:47 +09001049 e = {
1050 "type": "ref-updated",
1051 "submitter": {
1052 "name": "User Name",
1053 },
1054 "refUpdate": {
1055 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1056 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1057 "refName": "master",
1058 "project": "org/project",
1059 }
1060 }
James E. Blairdaabed22012-08-15 15:38:57 -07001061 self.fake_gerrit.addEvent(e)
1062 self.waitUntilSettled()
1063
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001064 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001065 self.assertEqual(len(self.history), 1)
1066 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -07001067
James E. Blairec056492016-07-22 09:45:56 -07001068 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001069 def test_post_ignore_deletes(self):
1070 "Test that deleting refs does not trigger post jobs"
1071
1072 e = {
1073 "type": "ref-updated",
1074 "submitter": {
1075 "name": "User Name",
1076 },
1077 "refUpdate": {
1078 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1079 "newRev": "0000000000000000000000000000000000000000",
1080 "refName": "master",
1081 "project": "org/project",
1082 }
1083 }
1084 self.fake_gerrit.addEvent(e)
1085 self.waitUntilSettled()
1086
1087 job_names = [x.name for x in self.history]
1088 self.assertEqual(len(self.history), 0)
1089 self.assertNotIn('project-post', job_names)
1090
James E. Blairec056492016-07-22 09:45:56 -07001091 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001092 def test_post_ignore_deletes_negative(self):
1093 "Test that deleting refs does trigger post jobs"
1094
James E. Blairf84026c2015-12-08 16:11:46 -08001095 self.updateConfigLayout(
1096 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001097 self.sched.reconfigure(self.config)
1098
1099 e = {
1100 "type": "ref-updated",
1101 "submitter": {
1102 "name": "User Name",
1103 },
1104 "refUpdate": {
1105 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1106 "newRev": "0000000000000000000000000000000000000000",
1107 "refName": "master",
1108 "project": "org/project",
1109 }
1110 }
1111 self.fake_gerrit.addEvent(e)
1112 self.waitUntilSettled()
1113
1114 job_names = [x.name for x in self.history]
1115 self.assertEqual(len(self.history), 1)
1116 self.assertIn('project-post', job_names)
1117
James E. Blairec056492016-07-22 09:45:56 -07001118 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001119 def test_build_configuration_branch(self):
1120 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001121
1122 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001123 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1124 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1125 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001126 A.addApproval('code-review', 2)
1127 B.addApproval('code-review', 2)
1128 C.addApproval('code-review', 2)
1129 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1130 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1131 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001132 self.waitUntilSettled()
1133
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001134 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001135 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001136 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001137 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001138 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001139 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001140 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001141 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1142 self.gearman_server.hold_jobs_in_queue = False
1143 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001144 self.waitUntilSettled()
1145
Monty Taylorbc758832013-06-17 17:22:42 -04001146 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001147 repo = git.Repo(path)
1148 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1149 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001150 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001151 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001152
James E. Blairec056492016-07-22 09:45:56 -07001153 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001154 def test_build_configuration_branch_interaction(self):
1155 "Test that switching between branches works"
1156 self.test_build_configuration()
1157 self.test_build_configuration_branch()
1158 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001159 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001160 repo = git.Repo(path)
1161 repo.heads.master.commit = repo.commit('init')
1162 self.test_build_configuration()
1163
James E. Blairec056492016-07-22 09:45:56 -07001164 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001165 def test_build_configuration_multi_branch(self):
1166 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001167
1168 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001169 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1170 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1171 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001172 A.addApproval('code-review', 2)
1173 B.addApproval('code-review', 2)
1174 C.addApproval('code-review', 2)
1175 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1176 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1177 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001178 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001179 queue = self.gearman_server.getQueue()
1180 job_A = None
1181 for job in queue:
1182 if 'project-merge' in job.name:
1183 job_A = job
1184 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1185 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1186 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1187 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001188
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001189 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001190 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001191 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001192 job_B = None
1193 for job in queue:
1194 if 'project-merge' in job.name:
1195 job_B = job
1196 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001197 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001198 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001199 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1200
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001201 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001202 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001203 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001204 for job in queue:
1205 if 'project-merge' in job.name:
1206 job_C = job
1207 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001208 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001209 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001210 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001211 self.gearman_server.hold_jobs_in_queue = False
1212 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001213 self.waitUntilSettled()
1214
Monty Taylorbc758832013-06-17 17:22:42 -04001215 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001216 repo = git.Repo(path)
1217
1218 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001219 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001220 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001221 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001222 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001223 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001224 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001225 # Ensure ZUUL_REF -> ZUUL_COMMIT
1226 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001227
1228 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001229 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001230 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001231 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001232 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001233 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001234 self.assertEqual(repo_shas[0], commit_B)
1235
1236 repo_messages = [c.message.strip()
1237 for c in repo.iter_commits(ref_A)]
1238 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1239 repo_messages.reverse()
1240 correct_messages = ['initial commit', 'A-1']
1241 self.assertEqual(repo_messages, correct_messages)
1242 self.assertEqual(repo_shas[0], commit_A)
1243
1244 self.assertNotEqual(ref_A, ref_B, ref_C)
1245 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001246
James E. Blairec056492016-07-22 09:45:56 -07001247 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001248 def test_one_job_project(self):
1249 "Test that queueing works with one job"
1250 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1251 'master', 'A')
1252 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1253 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001254 A.addApproval('code-review', 2)
1255 B.addApproval('code-review', 2)
1256 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1257 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001258 self.waitUntilSettled()
1259
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001260 self.assertEqual(A.data['status'], 'MERGED')
1261 self.assertEqual(A.reported, 2)
1262 self.assertEqual(B.data['status'], 'MERGED')
1263 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001264
James E. Blairec056492016-07-22 09:45:56 -07001265 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001266 def test_job_from_templates_launched(self):
1267 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001268
Antoine Musso80edd5a2013-02-13 15:37:53 +01001269 A = self.fake_gerrit.addFakeChange(
1270 'org/templated-project', 'master', 'A')
1271 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1272 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001273
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001274 self.assertEqual(self.getJobFromHistory('project-test1').result,
1275 'SUCCESS')
1276 self.assertEqual(self.getJobFromHistory('project-test2').result,
1277 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001278
James E. Blairec056492016-07-22 09:45:56 -07001279 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001280 def test_layered_templates(self):
1281 "Test whether a job generated via a template can be launched"
1282
1283 A = self.fake_gerrit.addFakeChange(
1284 'org/layered-project', 'master', 'A')
1285 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1286 self.waitUntilSettled()
1287
1288 self.assertEqual(self.getJobFromHistory('project-test1').result,
1289 'SUCCESS')
1290 self.assertEqual(self.getJobFromHistory('project-test2').result,
1291 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001292 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1293 ).result, 'SUCCESS')
1294 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1295 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001296 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1297 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001298 self.assertEqual(self.getJobFromHistory('project-test6').result,
1299 'SUCCESS')
1300
James E. Blairec056492016-07-22 09:45:56 -07001301 @skip("Disabled for early v3 development")
James E. Blaircaec0c52012-08-22 14:52:22 -07001302 def test_dependent_changes_dequeue(self):
1303 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001304
James E. Blaircaec0c52012-08-22 14:52:22 -07001305 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1306 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1307 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001308 A.addApproval('code-review', 2)
1309 B.addApproval('code-review', 2)
1310 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001311
1312 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1313 M1.setMerged()
1314
1315 # C -> B -> A -> M1
1316
1317 C.setDependsOn(B, 1)
1318 B.setDependsOn(A, 1)
1319 A.setDependsOn(M1, 1)
1320
James E. Blair08d19992016-08-10 15:25:31 -07001321 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001322
James E. Blair8b5408c2016-08-08 15:37:46 -07001323 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1324 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1325 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001326
1327 self.waitUntilSettled()
1328
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001329 self.assertEqual(A.data['status'], 'NEW')
1330 self.assertEqual(A.reported, 2)
1331 self.assertEqual(B.data['status'], 'NEW')
1332 self.assertEqual(B.reported, 2)
1333 self.assertEqual(C.data['status'], 'NEW')
1334 self.assertEqual(C.reported, 2)
1335 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001336
James E. Blairec056492016-07-22 09:45:56 -07001337 @skip("Disabled for early v3 development")
James E. Blair972e3c72013-08-29 12:04:55 -07001338 def test_failing_dependent_changes(self):
1339 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001340 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001341 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1342 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1343 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1344 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1345 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001346 A.addApproval('code-review', 2)
1347 B.addApproval('code-review', 2)
1348 C.addApproval('code-review', 2)
1349 D.addApproval('code-review', 2)
1350 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001351
1352 # E, D -> C -> B, A
1353
1354 D.setDependsOn(C, 1)
1355 C.setDependsOn(B, 1)
1356
James E. Blair08d19992016-08-10 15:25:31 -07001357 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001358
James E. Blair8b5408c2016-08-08 15:37:46 -07001359 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1360 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1361 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1362 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1363 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001364
1365 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001366 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001367 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001368 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001369 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001370 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001371 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001372 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001373 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001374 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001375 self.waitUntilSettled()
1376
James E. Blair08d19992016-08-10 15:25:31 -07001377 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001378 for build in self.builds:
1379 if build.parameters['ZUUL_CHANGE'] != '1':
1380 build.release()
1381 self.waitUntilSettled()
1382
James E. Blair08d19992016-08-10 15:25:31 -07001383 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001384 self.waitUntilSettled()
1385
1386 self.assertEqual(A.data['status'], 'MERGED')
1387 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001388 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001389 self.assertEqual(B.data['status'], 'NEW')
1390 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001391 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001392 self.assertEqual(C.data['status'], 'NEW')
1393 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001394 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001395 self.assertEqual(D.data['status'], 'NEW')
1396 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001397 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001398 self.assertEqual(E.data['status'], 'MERGED')
1399 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001400 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001401 self.assertEqual(len(self.history), 18)
1402
James E. Blairec056492016-07-22 09:45:56 -07001403 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001404 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001405 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001406 # If it's dequeued more than once, we should see extra
1407 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001408
James E. Blair08d19992016-08-10 15:25:31 -07001409 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001410 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1411 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1412 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001413 A.addApproval('code-review', 2)
1414 B.addApproval('code-review', 2)
1415 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001416
James E. Blair08d19992016-08-10 15:25:31 -07001417 self.launch_server.failJob('project1-test1', A)
1418 self.launch_server.failJob('project1-test2', A)
1419 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001420
James E. Blair8b5408c2016-08-08 15:37:46 -07001421 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1422 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1423 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001424
1425 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001426
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001427 self.assertEqual(len(self.builds), 1)
1428 self.assertEqual(self.builds[0].name, 'project1-merge')
1429 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001430
James E. Blair08d19992016-08-10 15:25:31 -07001431 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001432 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001433 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001434 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001435 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001436 self.waitUntilSettled()
1437
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001438 self.assertEqual(len(self.builds), 9)
1439 self.assertEqual(self.builds[0].name, 'project1-test1')
1440 self.assertEqual(self.builds[1].name, 'project1-test2')
1441 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1442 self.assertEqual(self.builds[3].name, 'project1-test1')
1443 self.assertEqual(self.builds[4].name, 'project1-test2')
1444 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1445 self.assertEqual(self.builds[6].name, 'project1-test1')
1446 self.assertEqual(self.builds[7].name, 'project1-test2')
1447 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001448
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001449 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001450 self.waitUntilSettled()
1451
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001452 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1453 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001454
James E. Blair08d19992016-08-10 15:25:31 -07001455 self.launch_server.hold_jobs_in_build = False
1456 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001457 self.waitUntilSettled()
1458
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001459 self.assertEqual(len(self.builds), 0)
1460 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001461
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001462 self.assertEqual(A.data['status'], 'NEW')
1463 self.assertEqual(B.data['status'], 'MERGED')
1464 self.assertEqual(C.data['status'], 'MERGED')
1465 self.assertEqual(A.reported, 2)
1466 self.assertEqual(B.reported, 2)
1467 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001468
James E. Blairec056492016-07-22 09:45:56 -07001469 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001470 def test_nonvoting_job(self):
1471 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001472
James E. Blair4ec821f2012-08-23 15:28:28 -07001473 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1474 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001475 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001476 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001477 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001478
1479 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001480
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001481 self.assertEqual(A.data['status'], 'MERGED')
1482 self.assertEqual(A.reported, 2)
1483 self.assertEqual(
1484 self.getJobFromHistory('nonvoting-project-merge').result,
1485 'SUCCESS')
1486 self.assertEqual(
1487 self.getJobFromHistory('nonvoting-project-test1').result,
1488 'SUCCESS')
1489 self.assertEqual(
1490 self.getJobFromHistory('nonvoting-project-test2').result,
1491 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001492
James E. Blair5821bd92015-09-16 08:48:15 -07001493 for build in self.builds:
1494 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1495
James E. Blairec056492016-07-22 09:45:56 -07001496 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001497 def test_check_queue_success(self):
1498 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001499
James E. Blaire0487072012-08-29 17:38:31 -07001500 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1501 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1502
1503 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001504
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001505 self.assertEqual(A.data['status'], 'NEW')
1506 self.assertEqual(A.reported, 1)
1507 self.assertEqual(self.getJobFromHistory('project-merge').result,
1508 'SUCCESS')
1509 self.assertEqual(self.getJobFromHistory('project-test1').result,
1510 'SUCCESS')
1511 self.assertEqual(self.getJobFromHistory('project-test2').result,
1512 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001513
James E. Blairec056492016-07-22 09:45:56 -07001514 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001515 def test_check_queue_failure(self):
1516 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001517
James E. Blaire0487072012-08-29 17:38:31 -07001518 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001519 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001520 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1521
1522 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001523
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001524 self.assertEqual(A.data['status'], 'NEW')
1525 self.assertEqual(A.reported, 1)
1526 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001527 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001528 self.assertEqual(self.getJobFromHistory('project-test1').result,
1529 'SUCCESS')
1530 self.assertEqual(self.getJobFromHistory('project-test2').result,
1531 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001532
James E. Blairec056492016-07-22 09:45:56 -07001533 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001534 def test_dependent_behind_dequeue(self):
1535 "test that dependent changes behind dequeued changes work"
1536 # This complicated test is a reproduction of a real life bug
1537 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001538
James E. Blair08d19992016-08-10 15:25:31 -07001539 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001540 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1541 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1542 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1543 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1544 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1545 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1546 D.setDependsOn(C, 1)
1547 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001548 A.addApproval('code-review', 2)
1549 B.addApproval('code-review', 2)
1550 C.addApproval('code-review', 2)
1551 D.addApproval('code-review', 2)
1552 E.addApproval('code-review', 2)
1553 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001554
1555 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001556
1557 # Change object re-use in the gerrit trigger is hidden if
1558 # changes are added in quick succession; waiting makes it more
1559 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001560 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001561 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001562 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001563 self.waitUntilSettled()
1564
James E. Blair08d19992016-08-10 15:25:31 -07001565 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001566 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001567 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001568 self.waitUntilSettled()
1569
James E. Blair8b5408c2016-08-08 15:37:46 -07001570 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001571 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001572 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001573 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001574 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001575 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001576 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001577 self.waitUntilSettled()
1578
James E. Blair08d19992016-08-10 15:25:31 -07001579 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001580 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001581 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001582 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001583 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001584 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001585 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001586 self.waitUntilSettled()
1587
1588 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001589
1590 # Grab pointers to the jobs we want to release before
1591 # releasing any, because list indexes may change as
1592 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001593 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001594 a.release()
1595 b.release()
1596 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001597 self.waitUntilSettled()
1598
James E. Blair08d19992016-08-10 15:25:31 -07001599 self.launch_server.hold_jobs_in_build = False
1600 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001601 self.waitUntilSettled()
1602
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001603 self.assertEqual(A.data['status'], 'NEW')
1604 self.assertEqual(B.data['status'], 'MERGED')
1605 self.assertEqual(C.data['status'], 'MERGED')
1606 self.assertEqual(D.data['status'], 'MERGED')
1607 self.assertEqual(E.data['status'], 'MERGED')
1608 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001609
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001610 self.assertEqual(A.reported, 2)
1611 self.assertEqual(B.reported, 2)
1612 self.assertEqual(C.reported, 2)
1613 self.assertEqual(D.reported, 2)
1614 self.assertEqual(E.reported, 2)
1615 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001616
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001617 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1618 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001619
James E. Blairec056492016-07-22 09:45:56 -07001620 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001621 def test_merger_repack(self):
1622 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001623
James E. Blair05fed602012-09-07 12:45:24 -07001624 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001625 A.addApproval('code-review', 2)
1626 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001627 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001628 self.assertEqual(self.getJobFromHistory('project-merge').result,
1629 'SUCCESS')
1630 self.assertEqual(self.getJobFromHistory('project-test1').result,
1631 'SUCCESS')
1632 self.assertEqual(self.getJobFromHistory('project-test2').result,
1633 'SUCCESS')
1634 self.assertEqual(A.data['status'], 'MERGED')
1635 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001636 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001637 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001638
Monty Taylorbc758832013-06-17 17:22:42 -04001639 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001640 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001641
1642 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001643 A.addApproval('code-review', 2)
1644 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001645 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001646 self.assertEqual(self.getJobFromHistory('project-merge').result,
1647 'SUCCESS')
1648 self.assertEqual(self.getJobFromHistory('project-test1').result,
1649 'SUCCESS')
1650 self.assertEqual(self.getJobFromHistory('project-test2').result,
1651 'SUCCESS')
1652 self.assertEqual(A.data['status'], 'MERGED')
1653 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001654
James E. Blairec056492016-07-22 09:45:56 -07001655 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001656 def test_merger_repack_large_change(self):
1657 "Test that the merger works with large changes after a repack"
1658 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001659 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001660 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001661 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001662 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001663 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1664 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001665 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001666 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001667 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001668 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001669
James E. Blair8b5408c2016-08-08 15:37:46 -07001670 A.addApproval('code-review', 2)
1671 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001672 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001673 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1674 'SUCCESS')
1675 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1676 'SUCCESS')
1677 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1678 'SUCCESS')
1679 self.assertEqual(A.data['status'], 'MERGED')
1680 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001681
James E. Blairec056492016-07-22 09:45:56 -07001682 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001683 def test_nonexistent_job(self):
1684 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001685 # Set to the state immediately after a restart
1686 self.resetGearmanServer()
1687 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001688
1689 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001690 A.addApproval('code-review', 2)
1691 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001692 # There may be a thread about to report a lost change
1693 while A.reported < 2:
1694 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001695 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001696 self.assertFalse(job_names)
1697 self.assertEqual(A.data['status'], 'NEW')
1698 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001699 self.assertEmptyQueues()
1700
1701 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001702 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001703 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001704 A.addApproval('code-review', 2)
1705 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001706 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001707 self.assertEqual(self.getJobFromHistory('project-merge').result,
1708 'SUCCESS')
1709 self.assertEqual(self.getJobFromHistory('project-test1').result,
1710 'SUCCESS')
1711 self.assertEqual(self.getJobFromHistory('project-test2').result,
1712 'SUCCESS')
1713 self.assertEqual(A.data['status'], 'MERGED')
1714 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001715
James E. Blairec056492016-07-22 09:45:56 -07001716 @skip("Disabled for early v3 development")
James E. Blairf62d4282012-12-31 17:01:50 -08001717 def test_single_nonexistent_post_job(self):
1718 "Test launching a single post job that doesn't exist"
James E. Blairf62d4282012-12-31 17:01:50 -08001719 e = {
1720 "type": "ref-updated",
1721 "submitter": {
1722 "name": "User Name",
1723 },
1724 "refUpdate": {
1725 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1726 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1727 "refName": "master",
1728 "project": "org/project",
1729 }
1730 }
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001731 # Set to the state immediately after a restart
1732 self.resetGearmanServer()
1733 self.launcher.negative_function_cache_ttl = 0
1734
James E. Blairf62d4282012-12-31 17:01:50 -08001735 self.fake_gerrit.addEvent(e)
1736 self.waitUntilSettled()
1737
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001738 self.assertEqual(len(self.history), 0)
James E. Blair2fa50962013-01-30 21:50:41 -08001739
James E. Blairec056492016-07-22 09:45:56 -07001740 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001741 def test_new_patchset_dequeues_old(self):
1742 "Test that a new patchset causes the old to be dequeued"
1743 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001744 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001745 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1746 M.setMerged()
1747
1748 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1749 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1750 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1751 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001752 A.addApproval('code-review', 2)
1753 B.addApproval('code-review', 2)
1754 C.addApproval('code-review', 2)
1755 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001756
1757 C.setDependsOn(B, 1)
1758 B.setDependsOn(A, 1)
1759 A.setDependsOn(M, 1)
1760
James E. Blair8b5408c2016-08-08 15:37:46 -07001761 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1762 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1763 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1764 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001765 self.waitUntilSettled()
1766
1767 B.addPatchset()
1768 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1769 self.waitUntilSettled()
1770
James E. Blair08d19992016-08-10 15:25:31 -07001771 self.launch_server.hold_jobs_in_build = False
1772 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001773 self.waitUntilSettled()
1774
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001775 self.assertEqual(A.data['status'], 'MERGED')
1776 self.assertEqual(A.reported, 2)
1777 self.assertEqual(B.data['status'], 'NEW')
1778 self.assertEqual(B.reported, 2)
1779 self.assertEqual(C.data['status'], 'NEW')
1780 self.assertEqual(C.reported, 2)
1781 self.assertEqual(D.data['status'], 'MERGED')
1782 self.assertEqual(D.reported, 2)
1783 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001784
James E. Blairec056492016-07-22 09:45:56 -07001785 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001786 def test_new_patchset_check(self):
1787 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001788
James E. Blair08d19992016-08-10 15:25:31 -07001789 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001790
1791 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001792 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1793 check_pipeline = self.sched.layout.pipelines['check']
1794
1795 # Add two git-dependent changes
1796 B.setDependsOn(A, 1)
1797 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1798 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001799 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1800 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001801
1802 # A live item, and a non-live/live pair
1803 items = check_pipeline.getAllItems()
1804 self.assertEqual(len(items), 3)
1805
1806 self.assertEqual(items[0].change.number, '1')
1807 self.assertEqual(items[0].change.patchset, '1')
1808 self.assertFalse(items[0].live)
1809
1810 self.assertEqual(items[1].change.number, '2')
1811 self.assertEqual(items[1].change.patchset, '1')
1812 self.assertTrue(items[1].live)
1813
1814 self.assertEqual(items[2].change.number, '1')
1815 self.assertEqual(items[2].change.patchset, '1')
1816 self.assertTrue(items[2].live)
1817
1818 # Add a new patchset to A
1819 A.addPatchset()
1820 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1821 self.waitUntilSettled()
1822
1823 # The live copy of A,1 should be gone, but the non-live and B
1824 # should continue, and we should have a new A,2
1825 items = check_pipeline.getAllItems()
1826 self.assertEqual(len(items), 3)
1827
1828 self.assertEqual(items[0].change.number, '1')
1829 self.assertEqual(items[0].change.patchset, '1')
1830 self.assertFalse(items[0].live)
1831
1832 self.assertEqual(items[1].change.number, '2')
1833 self.assertEqual(items[1].change.patchset, '1')
1834 self.assertTrue(items[1].live)
1835
1836 self.assertEqual(items[2].change.number, '1')
1837 self.assertEqual(items[2].change.patchset, '2')
1838 self.assertTrue(items[2].live)
1839
1840 # Add a new patchset to B
1841 B.addPatchset()
1842 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1843 self.waitUntilSettled()
1844
1845 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1846 # but we should have a new B,2 (still based on A,1)
1847 items = check_pipeline.getAllItems()
1848 self.assertEqual(len(items), 3)
1849
1850 self.assertEqual(items[0].change.number, '1')
1851 self.assertEqual(items[0].change.patchset, '2')
1852 self.assertTrue(items[0].live)
1853
1854 self.assertEqual(items[1].change.number, '1')
1855 self.assertEqual(items[1].change.patchset, '1')
1856 self.assertFalse(items[1].live)
1857
1858 self.assertEqual(items[2].change.number, '2')
1859 self.assertEqual(items[2].change.patchset, '2')
1860 self.assertTrue(items[2].live)
1861
1862 self.builds[0].release()
1863 self.waitUntilSettled()
1864 self.builds[0].release()
1865 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001866 self.launch_server.hold_jobs_in_build = False
1867 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001868 self.waitUntilSettled()
1869
1870 self.assertEqual(A.reported, 1)
1871 self.assertEqual(B.reported, 1)
1872 self.assertEqual(self.history[0].result, 'ABORTED')
1873 self.assertEqual(self.history[0].changes, '1,1')
1874 self.assertEqual(self.history[1].result, 'ABORTED')
1875 self.assertEqual(self.history[1].changes, '1,1 2,1')
1876 self.assertEqual(self.history[2].result, 'SUCCESS')
1877 self.assertEqual(self.history[2].changes, '1,2')
1878 self.assertEqual(self.history[3].result, 'SUCCESS')
1879 self.assertEqual(self.history[3].changes, '1,1 2,2')
1880
1881 def test_abandoned_gate(self):
1882 "Test that an abandoned change is dequeued from gate"
1883
James E. Blair08d19992016-08-10 15:25:31 -07001884 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001885
1886 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001887 A.addApproval('code-review', 2)
1888 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001889 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001890 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1891 self.assertEqual(self.builds[0].name, 'project-merge')
1892
1893 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1894 self.waitUntilSettled()
1895
James E. Blair08d19992016-08-10 15:25:31 -07001896 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001897 self.waitUntilSettled()
1898
Arie5b4048c2016-10-05 16:12:06 +03001899 self.assertBuilds([])
1900 self.assertHistory([
1901 dict(name='project-merge', result='ABORTED', changes='1,1')],
1902 ordered=False)
James E. Blairba437362015-02-07 11:41:52 -08001903 self.assertEqual(A.reported, 1,
1904 "Abandoned gate change should report only start")
1905
James E. Blairec056492016-07-22 09:45:56 -07001906 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001907 def test_abandoned_check(self):
1908 "Test that an abandoned change is dequeued from check"
1909
James E. Blair08d19992016-08-10 15:25:31 -07001910 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001911
1912 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1913 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1914 check_pipeline = self.sched.layout.pipelines['check']
1915
1916 # Add two git-dependent changes
1917 B.setDependsOn(A, 1)
1918 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1919 self.waitUntilSettled()
1920 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1921 self.waitUntilSettled()
1922 # A live item, and a non-live/live pair
1923 items = check_pipeline.getAllItems()
1924 self.assertEqual(len(items), 3)
1925
1926 self.assertEqual(items[0].change.number, '1')
1927 self.assertFalse(items[0].live)
1928
1929 self.assertEqual(items[1].change.number, '2')
1930 self.assertTrue(items[1].live)
1931
1932 self.assertEqual(items[2].change.number, '1')
1933 self.assertTrue(items[2].live)
1934
1935 # Abandon A
1936 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1937 self.waitUntilSettled()
1938
1939 # The live copy of A should be gone, but the non-live and B
1940 # should continue
1941 items = check_pipeline.getAllItems()
1942 self.assertEqual(len(items), 2)
1943
1944 self.assertEqual(items[0].change.number, '1')
1945 self.assertFalse(items[0].live)
1946
1947 self.assertEqual(items[1].change.number, '2')
1948 self.assertTrue(items[1].live)
1949
James E. Blair08d19992016-08-10 15:25:31 -07001950 self.launch_server.hold_jobs_in_build = False
1951 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001952 self.waitUntilSettled()
1953
1954 self.assertEqual(len(self.history), 4)
1955 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001956 'Build should have been aborted')
1957 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001958 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001959
James E. Blairec056492016-07-22 09:45:56 -07001960 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001961 def test_abandoned_not_timer(self):
1962 "Test that an abandoned change does not cancel timer jobs"
1963
James E. Blair08d19992016-08-10 15:25:31 -07001964 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001965
1966 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001967 self.updateConfigLayout(
1968 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001969 self.sched.reconfigure(self.config)
1970 self.registerJobs()
1971 # The pipeline triggers every second, so we should have seen
1972 # several by now.
1973 time.sleep(5)
1974 self.waitUntilSettled()
1975 # Stop queuing timer triggered jobs so that the assertions
1976 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001977 self.updateConfigLayout(
1978 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001979 self.sched.reconfigure(self.config)
1980 self.registerJobs()
1981 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1982
1983 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1984 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1985 self.waitUntilSettled()
1986 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1987
1988 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1989 self.waitUntilSettled()
1990
1991 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1992
James E. Blair08d19992016-08-10 15:25:31 -07001993 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001994 self.waitUntilSettled()
1995
James E. Blairec056492016-07-22 09:45:56 -07001996 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001997 def test_zuul_url_return(self):
1998 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001999 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07002000 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02002001
2002 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002003 A.addApproval('code-review', 2)
2004 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02002005 self.waitUntilSettled()
2006
2007 self.assertEqual(len(self.builds), 1)
2008 for build in self.builds:
2009 self.assertTrue('ZUUL_URL' in build.parameters)
2010
James E. Blair08d19992016-08-10 15:25:31 -07002011 self.launch_server.hold_jobs_in_build = False
2012 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02002013 self.waitUntilSettled()
2014
James E. Blairec056492016-07-22 09:45:56 -07002015 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002016 def test_new_patchset_dequeues_old_on_head(self):
2017 "Test that a new patchset causes the old to be dequeued (at head)"
2018 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07002019 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002020 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
2021 M.setMerged()
2022 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2023 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2024 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2025 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002026 A.addApproval('code-review', 2)
2027 B.addApproval('code-review', 2)
2028 C.addApproval('code-review', 2)
2029 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002030
2031 C.setDependsOn(B, 1)
2032 B.setDependsOn(A, 1)
2033 A.setDependsOn(M, 1)
2034
James E. Blair8b5408c2016-08-08 15:37:46 -07002035 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2036 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2037 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2038 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002039 self.waitUntilSettled()
2040
2041 A.addPatchset()
2042 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2043 self.waitUntilSettled()
2044
James E. Blair08d19992016-08-10 15:25:31 -07002045 self.launch_server.hold_jobs_in_build = False
2046 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002047 self.waitUntilSettled()
2048
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002049 self.assertEqual(A.data['status'], 'NEW')
2050 self.assertEqual(A.reported, 2)
2051 self.assertEqual(B.data['status'], 'NEW')
2052 self.assertEqual(B.reported, 2)
2053 self.assertEqual(C.data['status'], 'NEW')
2054 self.assertEqual(C.reported, 2)
2055 self.assertEqual(D.data['status'], 'MERGED')
2056 self.assertEqual(D.reported, 2)
2057 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002058
James E. Blairec056492016-07-22 09:45:56 -07002059 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002060 def test_new_patchset_dequeues_old_without_dependents(self):
2061 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002062 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002063 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2064 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2065 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002066 A.addApproval('code-review', 2)
2067 B.addApproval('code-review', 2)
2068 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002069
James E. Blair8b5408c2016-08-08 15:37:46 -07002070 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2071 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2072 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002073 self.waitUntilSettled()
2074
2075 B.addPatchset()
2076 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2077 self.waitUntilSettled()
2078
James E. Blair08d19992016-08-10 15:25:31 -07002079 self.launch_server.hold_jobs_in_build = False
2080 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002081 self.waitUntilSettled()
2082
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002083 self.assertEqual(A.data['status'], 'MERGED')
2084 self.assertEqual(A.reported, 2)
2085 self.assertEqual(B.data['status'], 'NEW')
2086 self.assertEqual(B.reported, 2)
2087 self.assertEqual(C.data['status'], 'MERGED')
2088 self.assertEqual(C.reported, 2)
2089 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002090
James E. Blairec056492016-07-22 09:45:56 -07002091 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002092 def test_new_patchset_dequeues_old_independent_queue(self):
2093 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002094 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002095 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2096 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2097 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2098 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2099 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2100 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2101 self.waitUntilSettled()
2102
2103 B.addPatchset()
2104 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2105 self.waitUntilSettled()
2106
James E. Blair08d19992016-08-10 15:25:31 -07002107 self.launch_server.hold_jobs_in_build = False
2108 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002109 self.waitUntilSettled()
2110
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002111 self.assertEqual(A.data['status'], 'NEW')
2112 self.assertEqual(A.reported, 1)
2113 self.assertEqual(B.data['status'], 'NEW')
2114 self.assertEqual(B.reported, 1)
2115 self.assertEqual(C.data['status'], 'NEW')
2116 self.assertEqual(C.reported, 1)
2117 self.assertEqual(len(self.history), 10)
2118 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002119
James E. Blairec056492016-07-22 09:45:56 -07002120 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002121 def test_noop_job(self):
2122 "Test that the internal noop job works"
2123 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002124 A.addApproval('code-review', 2)
2125 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002126 self.waitUntilSettled()
2127
2128 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2129 self.assertTrue(self.sched._areAllBuildsComplete())
2130 self.assertEqual(len(self.history), 0)
2131 self.assertEqual(A.data['status'], 'MERGED')
2132 self.assertEqual(A.reported, 2)
2133
James E. Blairec056492016-07-22 09:45:56 -07002134 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002135 def test_no_job_project(self):
2136 "Test that reports with no jobs don't get sent"
2137 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2138 'master', 'A')
2139 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2140 self.waitUntilSettled()
2141
2142 # Change wasn't reported to
2143 self.assertEqual(A.reported, False)
2144
2145 # Check queue is empty afterwards
2146 check_pipeline = self.sched.layout.pipelines['check']
2147 items = check_pipeline.getAllItems()
2148 self.assertEqual(len(items), 0)
2149
2150 self.assertEqual(len(self.history), 0)
2151
James E. Blairec056492016-07-22 09:45:56 -07002152 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002153 def test_zuul_refs(self):
2154 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002155 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002156 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2157 M1.setMerged()
2158 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2159 M2.setMerged()
2160
2161 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2162 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2163 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2164 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002165 A.addApproval('code-review', 2)
2166 B.addApproval('code-review', 2)
2167 C.addApproval('code-review', 2)
2168 D.addApproval('code-review', 2)
2169 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2170 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2171 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2172 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002173
2174 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002175 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002176 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002177 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002178 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002179 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002180 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002181 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002182 self.waitUntilSettled()
2183
James E. Blair7d0dedc2013-02-21 17:26:09 -08002184 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002185 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002186 if x.parameters['ZUUL_CHANGE'] == '3':
2187 a_zref = x.parameters['ZUUL_REF']
2188 if x.parameters['ZUUL_CHANGE'] == '4':
2189 b_zref = x.parameters['ZUUL_REF']
2190 if x.parameters['ZUUL_CHANGE'] == '5':
2191 c_zref = x.parameters['ZUUL_REF']
2192 if x.parameters['ZUUL_CHANGE'] == '6':
2193 d_zref = x.parameters['ZUUL_REF']
2194
2195 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002196 self.assertIsNotNone(a_zref)
2197 self.assertIsNotNone(b_zref)
2198 self.assertIsNotNone(c_zref)
2199 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002200
2201 # And they should all be different
2202 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002203 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002204
2205 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002206 self.assertTrue(self.ref_has_change(a_zref, A))
2207 self.assertFalse(self.ref_has_change(a_zref, B))
2208 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002209
2210 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002211 self.assertTrue(self.ref_has_change(b_zref, A))
2212 self.assertTrue(self.ref_has_change(b_zref, B))
2213 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002214
2215 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002216 self.assertTrue(self.ref_has_change(c_zref, A))
2217 self.assertTrue(self.ref_has_change(c_zref, B))
2218 self.assertTrue(self.ref_has_change(c_zref, C))
2219 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002220
2221 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002222 self.assertTrue(self.ref_has_change(d_zref, A))
2223 self.assertTrue(self.ref_has_change(d_zref, B))
2224 self.assertTrue(self.ref_has_change(d_zref, C))
2225 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002226
James E. Blair08d19992016-08-10 15:25:31 -07002227 self.launch_server.hold_jobs_in_build = False
2228 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002229 self.waitUntilSettled()
2230
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002231 self.assertEqual(A.data['status'], 'MERGED')
2232 self.assertEqual(A.reported, 2)
2233 self.assertEqual(B.data['status'], 'MERGED')
2234 self.assertEqual(B.reported, 2)
2235 self.assertEqual(C.data['status'], 'MERGED')
2236 self.assertEqual(C.reported, 2)
2237 self.assertEqual(D.data['status'], 'MERGED')
2238 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002239
James E. Blairec056492016-07-22 09:45:56 -07002240 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002241 def test_rerun_on_error(self):
2242 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002243 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002244 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002245 A.addApproval('code-review', 2)
2246 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002247 self.waitUntilSettled()
2248
2249 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002250 self.launch_server.hold_jobs_in_build = False
2251 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002252 self.waitUntilSettled()
2253 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2254 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2255
James E. Blairec056492016-07-22 09:45:56 -07002256 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002257 def test_statsd(self):
2258 "Test each of the statsd methods used in the scheduler"
2259 import extras
2260 statsd = extras.try_import('statsd.statsd')
2261 statsd.incr('test-incr')
2262 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002263 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002264 self.assertReportedStat('test-incr', '1|c')
2265 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002266 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002267
James E. Blairec056492016-07-22 09:45:56 -07002268 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002269 def test_stuck_job_cleanup(self):
2270 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002271 # This job won't be registered at startup because it is not in
2272 # the standard layout, but we need it to already be registerd
2273 # for when we reconfigure, as that is when Zuul will attempt
2274 # to run the new job.
2275 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002276 self.gearman_server.hold_jobs_in_queue = True
2277 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002278 A.addApproval('code-review', 2)
2279 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002280 self.waitUntilSettled()
2281 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2282
James E. Blairf84026c2015-12-08 16:11:46 -08002283 self.updateConfigLayout(
2284 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002285 self.sched.reconfigure(self.config)
2286 self.waitUntilSettled()
2287
James E. Blair18c64442014-03-18 10:14:45 -07002288 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002289 self.waitUntilSettled()
2290 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2291 self.assertTrue(self.sched._areAllBuildsComplete())
2292
2293 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002294 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002295 self.assertEqual(self.history[0].result, 'SUCCESS')
2296
James E. Blairec056492016-07-22 09:45:56 -07002297 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002298 def test_file_head(self):
2299 # This is a regression test for an observed bug. A change
2300 # with a file named "HEAD" in the root directory of the repo
2301 # was processed by a merger. It then was unable to reset the
2302 # repo because of:
2303 # GitCommandError: 'git reset --hard HEAD' returned
2304 # with exit code 128
2305 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2306 # and filename
2307 # Use '--' to separate filenames from revisions'
2308
2309 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2310 A.addPatchset(['HEAD'])
2311 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2312
2313 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2314 self.waitUntilSettled()
2315
2316 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2317 self.waitUntilSettled()
2318
2319 self.assertIn('Build succeeded', A.messages[0])
2320 self.assertIn('Build succeeded', B.messages[0])
2321
James E. Blairec056492016-07-22 09:45:56 -07002322 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002323 def test_file_jobs(self):
2324 "Test that file jobs run only when appropriate"
2325 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2326 A.addPatchset(['pip-requires'])
2327 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002328 A.addApproval('code-review', 2)
2329 B.addApproval('code-review', 2)
2330 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2331 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002332 self.waitUntilSettled()
2333
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002334 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002335 if x.name == 'project-testfile']
2336
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002337 self.assertEqual(len(testfile_jobs), 1)
2338 self.assertEqual(testfile_jobs[0].changes, '1,2')
2339 self.assertEqual(A.data['status'], 'MERGED')
2340 self.assertEqual(A.reported, 2)
2341 self.assertEqual(B.data['status'], 'MERGED')
2342 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002343
James E. Blairec056492016-07-22 09:45:56 -07002344 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002345 def _test_skip_if_jobs(self, branch, should_skip):
2346 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002347 self.updateConfigLayout(
2348 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002349 self.sched.reconfigure(self.config)
2350 self.registerJobs()
2351
2352 change = self.fake_gerrit.addFakeChange('org/project',
2353 branch,
2354 'test skip-if')
2355 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2356 self.waitUntilSettled()
2357
2358 tested_change_ids = [x.changes[0] for x in self.history
2359 if x.name == 'project-test-skip-if']
2360
2361 if should_skip:
2362 self.assertEqual([], tested_change_ids)
2363 else:
2364 self.assertIn(change.data['number'], tested_change_ids)
2365
James E. Blairec056492016-07-22 09:45:56 -07002366 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002367 def test_skip_if_match_skips_job(self):
2368 self._test_skip_if_jobs(branch='master', should_skip=True)
2369
James E. Blairec056492016-07-22 09:45:56 -07002370 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002371 def test_skip_if_no_match_runs_job(self):
2372 self._test_skip_if_jobs(branch='mp', should_skip=False)
2373
James E. Blairec056492016-07-22 09:45:56 -07002374 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002375 def test_test_config(self):
2376 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002377 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002378 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002379
James E. Blairec056492016-07-22 09:45:56 -07002380 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002381 def test_queue_names(self):
2382 "Test shared change queue names"
2383 project1 = self.sched.layout.projects['org/project1']
2384 project2 = self.sched.layout.projects['org/project2']
2385 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2386 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2387 self.assertEqual(q1.name, 'integration')
2388 self.assertEqual(q2.name, 'integration')
2389
James E. Blairf84026c2015-12-08 16:11:46 -08002390 self.updateConfigLayout(
2391 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002392 with testtools.ExpectedException(
2393 Exception, "More than one name assigned to change queue"):
2394 self.sched.reconfigure(self.config)
2395
James E. Blairec056492016-07-22 09:45:56 -07002396 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002397 def test_queue_precedence(self):
2398 "Test that queue precedence works"
2399
2400 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002401 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002402 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2403 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002404 A.addApproval('code-review', 2)
2405 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002406
2407 self.waitUntilSettled()
2408 self.gearman_server.hold_jobs_in_queue = False
2409 self.gearman_server.release()
2410 self.waitUntilSettled()
2411
James E. Blair8de58bd2013-07-18 16:23:33 -07002412 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002413 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002414 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002415 self.waitUntilSettled()
2416
James E. Blair64ed6f22013-07-10 14:07:23 -07002417 self.log.debug(self.history)
2418 self.assertEqual(self.history[0].pipeline, 'gate')
2419 self.assertEqual(self.history[1].pipeline, 'check')
2420 self.assertEqual(self.history[2].pipeline, 'gate')
2421 self.assertEqual(self.history[3].pipeline, 'gate')
2422 self.assertEqual(self.history[4].pipeline, 'check')
2423 self.assertEqual(self.history[5].pipeline, 'check')
2424
James E. Blairec056492016-07-22 09:45:56 -07002425 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002426 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002427 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002428 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002429 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002430 A.addApproval('code-review', 2)
2431 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002432 self.waitUntilSettled()
2433
James E. Blair08d19992016-08-10 15:25:31 -07002434 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002435 self.waitUntilSettled()
2436
James E. Blair1843a552013-07-03 14:19:52 -07002437 port = self.webapp.server.socket.getsockname()[1]
2438
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002439 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2440 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002441 headers = f.info()
2442 self.assertIn('Content-Length', headers)
2443 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002444 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2445 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002446 self.assertIn('Access-Control-Allow-Origin', headers)
2447 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002448 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002449 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002450 data = f.read()
2451
James E. Blair08d19992016-08-10 15:25:31 -07002452 self.launch_server.hold_jobs_in_build = False
2453 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002454 self.waitUntilSettled()
2455
2456 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002457 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002458 for p in data['pipelines']:
2459 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002460 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002461 self.assertEqual(q['window'], 20)
2462 else:
2463 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002464 for head in q['heads']:
2465 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002466 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002467 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002468 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002469 status_jobs.append(job)
2470 self.assertEqual('project-merge', status_jobs[0]['name'])
2471 self.assertEqual('https://server/job/project-merge/0/',
2472 status_jobs[0]['url'])
2473 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2474 status_jobs[0]['report_url'])
2475
2476 self.assertEqual('project-test1', status_jobs[1]['name'])
2477 self.assertEqual('https://server/job/project-test1/1/',
2478 status_jobs[1]['url'])
2479 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2480 status_jobs[1]['report_url'])
2481
2482 self.assertEqual('project-test2', status_jobs[2]['name'])
2483 self.assertEqual('https://server/job/project-test2/2/',
2484 status_jobs[2]['url'])
2485 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2486 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002487
James E. Blairec056492016-07-22 09:45:56 -07002488 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002489 def test_merging_queues(self):
2490 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002491 self.updateConfigLayout(
2492 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002493 self.sched.reconfigure(self.config)
2494 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2495
James E. Blairec056492016-07-22 09:45:56 -07002496 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002497 def test_mutex(self):
2498 "Test job mutexes"
2499 self.config.set('zuul', 'layout_config',
2500 'tests/fixtures/layout-mutex.yaml')
2501 self.sched.reconfigure(self.config)
2502
James E. Blair08d19992016-08-10 15:25:31 -07002503 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002504 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2505 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2506 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2507
2508 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2509 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2510 self.waitUntilSettled()
2511 self.assertEqual(len(self.builds), 3)
2512 self.assertEqual(self.builds[0].name, 'project-test1')
2513 self.assertEqual(self.builds[1].name, 'mutex-one')
2514 self.assertEqual(self.builds[2].name, 'project-test1')
2515
James E. Blair08d19992016-08-10 15:25:31 -07002516 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002517 self.waitUntilSettled()
2518
2519 self.assertEqual(len(self.builds), 3)
2520 self.assertEqual(self.builds[0].name, 'project-test1')
2521 self.assertEqual(self.builds[1].name, 'project-test1')
2522 self.assertEqual(self.builds[2].name, 'mutex-two')
2523 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2524
James E. Blair08d19992016-08-10 15:25:31 -07002525 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002526 self.waitUntilSettled()
2527
2528 self.assertEqual(len(self.builds), 3)
2529 self.assertEqual(self.builds[0].name, 'project-test1')
2530 self.assertEqual(self.builds[1].name, 'project-test1')
2531 self.assertEqual(self.builds[2].name, 'mutex-one')
2532 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2533
James E. Blair08d19992016-08-10 15:25:31 -07002534 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002535 self.waitUntilSettled()
2536
2537 self.assertEqual(len(self.builds), 3)
2538 self.assertEqual(self.builds[0].name, 'project-test1')
2539 self.assertEqual(self.builds[1].name, 'project-test1')
2540 self.assertEqual(self.builds[2].name, 'mutex-two')
2541 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2542
James E. Blair08d19992016-08-10 15:25:31 -07002543 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002544 self.waitUntilSettled()
2545
2546 self.assertEqual(len(self.builds), 2)
2547 self.assertEqual(self.builds[0].name, 'project-test1')
2548 self.assertEqual(self.builds[1].name, 'project-test1')
2549 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2550
James E. Blair08d19992016-08-10 15:25:31 -07002551 self.launch_server.hold_jobs_in_build = False
2552 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002553
2554 self.waitUntilSettled()
2555 self.assertEqual(len(self.builds), 0)
2556
2557 self.assertEqual(A.reported, 1)
2558 self.assertEqual(B.reported, 1)
2559 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2560
James E. Blairec056492016-07-22 09:45:56 -07002561 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002562 def test_node_label(self):
2563 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002564 self.worker.registerFunction('build:node-project-test1:debian')
2565
2566 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002567 A.addApproval('code-review', 2)
2568 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002569 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002570
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002571 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2572 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2573 'debian')
2574 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002575
James E. Blairec056492016-07-22 09:45:56 -07002576 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002577 def test_live_reconfiguration(self):
2578 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002579 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002580 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002581 A.addApproval('code-review', 2)
2582 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002583 self.waitUntilSettled()
2584
2585 self.sched.reconfigure(self.config)
2586
James E. Blair08d19992016-08-10 15:25:31 -07002587 self.launch_server.hold_jobs_in_build = False
2588 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002589 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002590 self.assertEqual(self.getJobFromHistory('project-merge').result,
2591 'SUCCESS')
2592 self.assertEqual(self.getJobFromHistory('project-test1').result,
2593 'SUCCESS')
2594 self.assertEqual(self.getJobFromHistory('project-test2').result,
2595 'SUCCESS')
2596 self.assertEqual(A.data['status'], 'MERGED')
2597 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002598
James E. Blairec056492016-07-22 09:45:56 -07002599 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002600 def test_live_reconfiguration_merge_conflict(self):
2601 # A real-world bug: a change in a gate queue has a merge
2602 # conflict and a job is added to its project while it's
2603 # sitting in the queue. The job gets added to the change and
2604 # enqueued and the change gets stuck.
2605 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002606 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002607
2608 # This change is fine. It's here to stop the queue long
2609 # enough for the next change to be subject to the
2610 # reconfiguration, as well as to provide a conflict for the
2611 # next change. This change will succeed and merge.
2612 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2613 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002614 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002615
2616 # This change will be in merge conflict. During the
2617 # reconfiguration, we will add a job. We want to make sure
2618 # that doesn't cause it to get stuck.
2619 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2620 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002621 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002622
James E. Blair8b5408c2016-08-08 15:37:46 -07002623 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2624 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002625
2626 self.waitUntilSettled()
2627
2628 # No jobs have run yet
2629 self.assertEqual(A.data['status'], 'NEW')
2630 self.assertEqual(A.reported, 1)
2631 self.assertEqual(B.data['status'], 'NEW')
2632 self.assertEqual(B.reported, 1)
2633 self.assertEqual(len(self.history), 0)
2634
2635 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002636 self.updateConfigLayout(
2637 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002638 self.sched.reconfigure(self.config)
2639 self.waitUntilSettled()
2640
James E. Blair08d19992016-08-10 15:25:31 -07002641 self.launch_server.hold_jobs_in_build = False
2642 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002643 self.waitUntilSettled()
2644
2645 self.assertEqual(A.data['status'], 'MERGED')
2646 self.assertEqual(A.reported, 2)
2647 self.assertEqual(B.data['status'], 'NEW')
2648 self.assertEqual(B.reported, 2)
2649 self.assertEqual(self.getJobFromHistory('project-merge').result,
2650 'SUCCESS')
2651 self.assertEqual(self.getJobFromHistory('project-test1').result,
2652 'SUCCESS')
2653 self.assertEqual(self.getJobFromHistory('project-test2').result,
2654 'SUCCESS')
2655 self.assertEqual(self.getJobFromHistory('project-test3').result,
2656 'SUCCESS')
2657 self.assertEqual(len(self.history), 4)
2658
James E. Blairec056492016-07-22 09:45:56 -07002659 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002660 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002661 # An extrapolation of test_live_reconfiguration_merge_conflict
2662 # that tests a job added to a job tree with a failed root does
2663 # not run.
2664 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002665 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002666
2667 # This change is fine. It's here to stop the queue long
2668 # enough for the next change to be subject to the
2669 # reconfiguration. This change will succeed and merge.
2670 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2671 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002672 A.addApproval('code-review', 2)
2673 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002674 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002675 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002676 self.waitUntilSettled()
2677
2678 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002679 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002680 B.addApproval('code-review', 2)
2681 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002682 self.waitUntilSettled()
2683
James E. Blair08d19992016-08-10 15:25:31 -07002684 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002685 self.waitUntilSettled()
2686
2687 # Both -merge jobs have run, but no others.
2688 self.assertEqual(A.data['status'], 'NEW')
2689 self.assertEqual(A.reported, 1)
2690 self.assertEqual(B.data['status'], 'NEW')
2691 self.assertEqual(B.reported, 1)
2692 self.assertEqual(self.history[0].result, 'SUCCESS')
2693 self.assertEqual(self.history[0].name, 'project-merge')
2694 self.assertEqual(self.history[1].result, 'FAILURE')
2695 self.assertEqual(self.history[1].name, 'project-merge')
2696 self.assertEqual(len(self.history), 2)
2697
2698 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002699 self.updateConfigLayout(
2700 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002701 self.sched.reconfigure(self.config)
2702 self.waitUntilSettled()
2703
James E. Blair08d19992016-08-10 15:25:31 -07002704 self.launch_server.hold_jobs_in_build = False
2705 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002706 self.waitUntilSettled()
2707
2708 self.assertEqual(A.data['status'], 'MERGED')
2709 self.assertEqual(A.reported, 2)
2710 self.assertEqual(B.data['status'], 'NEW')
2711 self.assertEqual(B.reported, 2)
2712 self.assertEqual(self.history[0].result, 'SUCCESS')
2713 self.assertEqual(self.history[0].name, 'project-merge')
2714 self.assertEqual(self.history[1].result, 'FAILURE')
2715 self.assertEqual(self.history[1].name, 'project-merge')
2716 self.assertEqual(self.history[2].result, 'SUCCESS')
2717 self.assertEqual(self.history[3].result, 'SUCCESS')
2718 self.assertEqual(self.history[4].result, 'SUCCESS')
2719 self.assertEqual(len(self.history), 5)
2720
James E. Blairec056492016-07-22 09:45:56 -07002721 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002722 def test_live_reconfiguration_failed_job(self):
2723 # Test that a change with a removed failing job does not
2724 # disrupt reconfiguration. If a change has a failed job and
2725 # that job is removed during a reconfiguration, we observed a
2726 # bug where the code to re-set build statuses would run on
2727 # that build and raise an exception because the job no longer
2728 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002729 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002730
2731 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2732
2733 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002734 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002735
2736 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2737 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002738 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002739 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002740 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002741 self.waitUntilSettled()
2742
2743 self.assertEqual(A.data['status'], 'NEW')
2744 self.assertEqual(A.reported, 0)
2745
2746 self.assertEqual(self.getJobFromHistory('project-merge').result,
2747 'SUCCESS')
2748 self.assertEqual(self.getJobFromHistory('project-test1').result,
2749 'FAILURE')
2750 self.assertEqual(len(self.history), 2)
2751
2752 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002753 self.updateConfigLayout(
2754 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002755 self.sched.reconfigure(self.config)
2756 self.waitUntilSettled()
2757
James E. Blair08d19992016-08-10 15:25:31 -07002758 self.launch_server.hold_jobs_in_build = False
2759 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002760 self.waitUntilSettled()
2761
2762 self.assertEqual(self.getJobFromHistory('project-test2').result,
2763 'SUCCESS')
2764 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2765 'SUCCESS')
2766 self.assertEqual(len(self.history), 4)
2767
2768 self.assertEqual(A.data['status'], 'NEW')
2769 self.assertEqual(A.reported, 1)
2770 self.assertIn('Build succeeded', A.messages[0])
2771 # Ensure the removed job was not included in the report.
2772 self.assertNotIn('project-test1', A.messages[0])
2773
James E. Blairec056492016-07-22 09:45:56 -07002774 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002775 def test_live_reconfiguration_shared_queue(self):
2776 # Test that a change with a failing job which was removed from
2777 # this project but otherwise still exists in the system does
2778 # not disrupt reconfiguration.
2779
James E. Blair08d19992016-08-10 15:25:31 -07002780 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002781
2782 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2783
James E. Blair08d19992016-08-10 15:25:31 -07002784 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002785
2786 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2787 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002788 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002789 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002790 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002791 self.waitUntilSettled()
2792
2793 self.assertEqual(A.data['status'], 'NEW')
2794 self.assertEqual(A.reported, 0)
2795
2796 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2797 'SUCCESS')
2798 self.assertEqual(self.getJobFromHistory(
2799 'project1-project2-integration').result, 'FAILURE')
2800 self.assertEqual(len(self.history), 2)
2801
2802 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002803 self.updateConfigLayout(
2804 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002805 self.sched.reconfigure(self.config)
2806 self.waitUntilSettled()
2807
James E. Blair08d19992016-08-10 15:25:31 -07002808 self.launch_server.hold_jobs_in_build = False
2809 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002810 self.waitUntilSettled()
2811
2812 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2813 'SUCCESS')
2814 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2815 'SUCCESS')
2816 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2817 'SUCCESS')
2818 self.assertEqual(self.getJobFromHistory(
2819 'project1-project2-integration').result, 'FAILURE')
2820 self.assertEqual(len(self.history), 4)
2821
2822 self.assertEqual(A.data['status'], 'NEW')
2823 self.assertEqual(A.reported, 1)
2824 self.assertIn('Build succeeded', A.messages[0])
2825 # Ensure the removed job was not included in the report.
2826 self.assertNotIn('project1-project2-integration', A.messages[0])
2827
James E. Blairec056492016-07-22 09:45:56 -07002828 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002829 def test_double_live_reconfiguration_shared_queue(self):
2830 # This was a real-world regression. A change is added to
2831 # gate; a reconfigure happens, a second change which depends
2832 # on the first is added, and a second reconfiguration happens.
2833 # Ensure that both changes merge.
2834
2835 # A failure may indicate incorrect caching or cleaning up of
2836 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002837 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002838
2839 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2840 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2841 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002842 A.addApproval('code-review', 2)
2843 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002844
2845 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002846 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002847 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002848 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002849 self.waitUntilSettled()
2850
2851 # Reconfigure (with only one change in the pipeline).
2852 self.sched.reconfigure(self.config)
2853 self.waitUntilSettled()
2854
2855 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002856 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002857 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002858 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002859 self.waitUntilSettled()
2860
2861 # Reconfigure (with both in the pipeline).
2862 self.sched.reconfigure(self.config)
2863 self.waitUntilSettled()
2864
James E. Blair08d19992016-08-10 15:25:31 -07002865 self.launch_server.hold_jobs_in_build = False
2866 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002867 self.waitUntilSettled()
2868
2869 self.assertEqual(len(self.history), 8)
2870
2871 self.assertEqual(A.data['status'], 'MERGED')
2872 self.assertEqual(A.reported, 2)
2873 self.assertEqual(B.data['status'], 'MERGED')
2874 self.assertEqual(B.reported, 2)
2875
James E. Blairec056492016-07-22 09:45:56 -07002876 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002877 def test_live_reconfiguration_del_project(self):
2878 # Test project deletion from layout
2879 # while changes are enqueued
2880
James E. Blair08d19992016-08-10 15:25:31 -07002881 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002882 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2883 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2884 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2885
2886 # A Depends-On: B
2887 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2888 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002889 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002890
2891 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2892 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2893 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002894 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002895 self.waitUntilSettled()
2896 self.assertEqual(len(self.builds), 5)
2897
2898 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002899 self.updateConfigLayout(
2900 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002901 self.sched.reconfigure(self.config)
2902 self.waitUntilSettled()
2903
2904 # Builds for C aborted, builds for A succeed,
2905 # and have change B applied ahead
2906 job_c = self.getJobFromHistory('project1-test1')
2907 self.assertEqual(job_c.changes, '3,1')
2908 self.assertEqual(job_c.result, 'ABORTED')
2909
James E. Blair08d19992016-08-10 15:25:31 -07002910 self.launch_server.hold_jobs_in_build = False
2911 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002912 self.waitUntilSettled()
2913
2914 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2915 '2,1 1,1')
2916
2917 self.assertEqual(A.data['status'], 'NEW')
2918 self.assertEqual(B.data['status'], 'NEW')
2919 self.assertEqual(C.data['status'], 'NEW')
2920 self.assertEqual(A.reported, 1)
2921 self.assertEqual(B.reported, 0)
2922 self.assertEqual(C.reported, 0)
2923
2924 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2925 self.assertIn('Build succeeded', A.messages[0])
2926
James E. Blairec056492016-07-22 09:45:56 -07002927 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002928 def test_live_reconfiguration_functions(self):
2929 "Test live reconfiguration with a custom function"
2930 self.worker.registerFunction('build:node-project-test1:debian')
2931 self.worker.registerFunction('build:node-project-test1:wheezy')
2932 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002933 A.addApproval('code-review', 2)
2934 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002935 self.waitUntilSettled()
2936
2937 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2938 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2939 'debian')
2940 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2941
James E. Blairf84026c2015-12-08 16:11:46 -08002942 self.updateConfigLayout(
2943 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002944 self.sched.reconfigure(self.config)
2945 self.worker.build_history = []
2946
2947 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002948 B.addApproval('code-review', 2)
2949 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002950 self.waitUntilSettled()
2951
2952 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2953 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2954 'wheezy')
2955 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2956
James E. Blairec056492016-07-22 09:45:56 -07002957 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002958 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002959 self.updateConfigLayout(
2960 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002961 self.sched.reconfigure(self.config)
2962
2963 self.init_repo("org/new-project")
2964 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2965
James E. Blair8b5408c2016-08-08 15:37:46 -07002966 A.addApproval('code-review', 2)
2967 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002968 self.waitUntilSettled()
2969 self.assertEqual(self.getJobFromHistory('project-merge').result,
2970 'SUCCESS')
2971 self.assertEqual(self.getJobFromHistory('project-test1').result,
2972 'SUCCESS')
2973 self.assertEqual(self.getJobFromHistory('project-test2').result,
2974 'SUCCESS')
2975 self.assertEqual(A.data['status'], 'MERGED')
2976 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002977
James E. Blairec056492016-07-22 09:45:56 -07002978 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002979 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002980 self.updateConfigLayout(
2981 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002982 self.sched.reconfigure(self.config)
2983
2984 self.init_repo("org/delete-project")
2985 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2986
James E. Blair8b5408c2016-08-08 15:37:46 -07002987 A.addApproval('code-review', 2)
2988 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002989 self.waitUntilSettled()
2990 self.assertEqual(self.getJobFromHistory('project-merge').result,
2991 'SUCCESS')
2992 self.assertEqual(self.getJobFromHistory('project-test1').result,
2993 'SUCCESS')
2994 self.assertEqual(self.getJobFromHistory('project-test2').result,
2995 'SUCCESS')
2996 self.assertEqual(A.data['status'], 'MERGED')
2997 self.assertEqual(A.reported, 2)
2998
2999 # Delete org/new-project zuul repo. Should be recloned.
3000 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
3001
3002 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
3003
James E. Blair8b5408c2016-08-08 15:37:46 -07003004 B.addApproval('code-review', 2)
3005 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07003006 self.waitUntilSettled()
3007 self.assertEqual(self.getJobFromHistory('project-merge').result,
3008 'SUCCESS')
3009 self.assertEqual(self.getJobFromHistory('project-test1').result,
3010 'SUCCESS')
3011 self.assertEqual(self.getJobFromHistory('project-test2').result,
3012 'SUCCESS')
3013 self.assertEqual(B.data['status'], 'MERGED')
3014 self.assertEqual(B.reported, 2)
3015
James E. Blairec056492016-07-22 09:45:56 -07003016 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08003017 def test_tags(self):
3018 "Test job tags"
3019 self.config.set('zuul', 'layout_config',
3020 'tests/fixtures/layout-tags.yaml')
3021 self.sched.reconfigure(self.config)
3022
3023 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3024 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3025 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3026 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
3027 self.waitUntilSettled()
3028
3029 results = {'project1-merge': 'extratag merge project1',
3030 'project2-merge': 'merge'}
3031
3032 for build in self.history:
3033 self.assertEqual(results.get(build.name, ''),
3034 build.parameters.get('BUILD_TAGS'))
3035
James E. Blairec056492016-07-22 09:45:56 -07003036 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07003037 def test_timer(self):
3038 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003039 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003040 self.updateConfigLayout(
3041 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07003042 self.sched.reconfigure(self.config)
3043 self.registerJobs()
3044
Clark Boylan3ee090a2014-04-03 20:55:09 -07003045 # The pipeline triggers every second, so we should have seen
3046 # several by now.
3047 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003048 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003049
3050 self.assertEqual(len(self.builds), 2)
3051
James E. Blair63bb0ef2013-07-29 17:14:51 -07003052 port = self.webapp.server.socket.getsockname()[1]
3053
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003054 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3055 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003056 data = f.read()
3057
James E. Blair08d19992016-08-10 15:25:31 -07003058 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003059 # Stop queuing timer triggered jobs so that the assertions
3060 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003061 self.updateConfigLayout(
3062 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003063 self.sched.reconfigure(self.config)
3064 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003065 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003066 self.waitUntilSettled()
3067
3068 self.assertEqual(self.getJobFromHistory(
3069 'project-bitrot-stable-old').result, 'SUCCESS')
3070 self.assertEqual(self.getJobFromHistory(
3071 'project-bitrot-stable-older').result, 'SUCCESS')
3072
3073 data = json.loads(data)
3074 status_jobs = set()
3075 for p in data['pipelines']:
3076 for q in p['change_queues']:
3077 for head in q['heads']:
3078 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003079 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003080 for job in change['jobs']:
3081 status_jobs.add(job['name'])
3082 self.assertIn('project-bitrot-stable-old', status_jobs)
3083 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003084
James E. Blairec056492016-07-22 09:45:56 -07003085 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003086 def test_idle(self):
3087 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003088 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003089
Clark Boylan3ee090a2014-04-03 20:55:09 -07003090 for x in range(1, 3):
3091 # Test that timer triggers periodic jobs even across
3092 # layout config reloads.
3093 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003094 self.updateConfigLayout(
3095 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003096 self.sched.reconfigure(self.config)
3097 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003098 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003099
Clark Boylan3ee090a2014-04-03 20:55:09 -07003100 # The pipeline triggers every second, so we should have seen
3101 # several by now.
3102 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003103
3104 # Stop queuing timer triggered jobs so that the assertions
3105 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003106 self.updateConfigLayout(
3107 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003108 self.sched.reconfigure(self.config)
3109 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003110 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003111
3112 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003113 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003114 self.waitUntilSettled()
3115 self.assertEqual(len(self.builds), 0)
3116 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003117
James E. Blairec056492016-07-22 09:45:56 -07003118 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003119 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003120 self.updateConfigLayout(
3121 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003122 self.sched.reconfigure(self.config)
3123
3124 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3125 self.waitUntilSettled()
3126
3127 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3128 self.waitUntilSettled()
3129
James E. Blairff80a2f2013-12-27 13:24:06 -08003130 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003131
3132 # A.messages only holds what FakeGerrit places in it. Thus we
3133 # work on the knowledge of what the first message should be as
3134 # it is only configured to go to SMTP.
3135
3136 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003137 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003138 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003139 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003140 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003141 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003142
3143 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003144 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003145 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003146 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003147 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003148 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003149
James E. Blairec056492016-07-22 09:45:56 -07003150 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003151 def test_timer_smtp(self):
3152 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003153 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003154 self.updateConfigLayout(
3155 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003156 self.sched.reconfigure(self.config)
3157 self.registerJobs()
3158
Clark Boylan3ee090a2014-04-03 20:55:09 -07003159 # The pipeline triggers every second, so we should have seen
3160 # several by now.
3161 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003162 self.waitUntilSettled()
3163
Clark Boylan3ee090a2014-04-03 20:55:09 -07003164 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003165 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003166 self.waitUntilSettled()
3167 self.assertEqual(len(self.history), 2)
3168
James E. Blaire5910202013-12-27 09:50:31 -08003169 self.assertEqual(self.getJobFromHistory(
3170 'project-bitrot-stable-old').result, 'SUCCESS')
3171 self.assertEqual(self.getJobFromHistory(
3172 'project-bitrot-stable-older').result, 'SUCCESS')
3173
James E. Blairff80a2f2013-12-27 13:24:06 -08003174 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003175
3176 # A.messages only holds what FakeGerrit places in it. Thus we
3177 # work on the knowledge of what the first message should be as
3178 # it is only configured to go to SMTP.
3179
3180 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003181 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003182 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003183 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003184 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003185 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003186
Clark Boylan3ee090a2014-04-03 20:55:09 -07003187 # Stop queuing timer triggered jobs and let any that may have
3188 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003189 self.updateConfigLayout(
3190 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003191 self.sched.reconfigure(self.config)
3192 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003193 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003194 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003195 self.waitUntilSettled()
3196
James E. Blairec056492016-07-22 09:45:56 -07003197 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003198 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003199 "Test that the RPC client can enqueue a change"
3200 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003201 A.addApproval('code-review', 2)
3202 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003203
3204 client = zuul.rpcclient.RPCClient('127.0.0.1',
3205 self.gearman_server.port)
3206 r = client.enqueue(pipeline='gate',
3207 project='org/project',
3208 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003209 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003210 self.waitUntilSettled()
3211 self.assertEqual(self.getJobFromHistory('project-merge').result,
3212 'SUCCESS')
3213 self.assertEqual(self.getJobFromHistory('project-test1').result,
3214 'SUCCESS')
3215 self.assertEqual(self.getJobFromHistory('project-test2').result,
3216 'SUCCESS')
3217 self.assertEqual(A.data['status'], 'MERGED')
3218 self.assertEqual(A.reported, 2)
3219 self.assertEqual(r, True)
3220
James E. Blairec056492016-07-22 09:45:56 -07003221 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003222 def test_client_enqueue_ref(self):
3223 "Test that the RPC client can enqueue a ref"
3224
3225 client = zuul.rpcclient.RPCClient('127.0.0.1',
3226 self.gearman_server.port)
3227 r = client.enqueue_ref(
3228 pipeline='post',
3229 project='org/project',
3230 trigger='gerrit',
3231 ref='master',
3232 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3233 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3234 self.waitUntilSettled()
3235 job_names = [x.name for x in self.history]
3236 self.assertEqual(len(self.history), 1)
3237 self.assertIn('project-post', job_names)
3238 self.assertEqual(r, True)
3239
James E. Blairec056492016-07-22 09:45:56 -07003240 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003241 def test_client_enqueue_negative(self):
3242 "Test that the RPC client returns errors"
3243 client = zuul.rpcclient.RPCClient('127.0.0.1',
3244 self.gearman_server.port)
3245 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3246 "Invalid project"):
3247 r = client.enqueue(pipeline='gate',
3248 project='project-does-not-exist',
3249 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003250 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003251 client.shutdown()
3252 self.assertEqual(r, False)
3253
3254 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3255 "Invalid pipeline"):
3256 r = client.enqueue(pipeline='pipeline-does-not-exist',
3257 project='org/project',
3258 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003259 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003260 client.shutdown()
3261 self.assertEqual(r, False)
3262
3263 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3264 "Invalid trigger"):
3265 r = client.enqueue(pipeline='gate',
3266 project='org/project',
3267 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003268 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003269 client.shutdown()
3270 self.assertEqual(r, False)
3271
3272 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3273 "Invalid change"):
3274 r = client.enqueue(pipeline='gate',
3275 project='org/project',
3276 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003277 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003278 client.shutdown()
3279 self.assertEqual(r, False)
3280
3281 self.waitUntilSettled()
3282 self.assertEqual(len(self.history), 0)
3283 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003284
James E. Blairec056492016-07-22 09:45:56 -07003285 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003286 def test_client_promote(self):
3287 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003288 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003289 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3290 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3291 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003292 A.addApproval('code-review', 2)
3293 B.addApproval('code-review', 2)
3294 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003295
James E. Blair8b5408c2016-08-08 15:37:46 -07003296 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3297 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3298 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003299
3300 self.waitUntilSettled()
3301
Sean Daguef39b9ca2014-01-10 21:34:35 -05003302 items = self.sched.layout.pipelines['gate'].getAllItems()
3303 enqueue_times = {}
3304 for item in items:
3305 enqueue_times[str(item.change)] = item.enqueue_time
3306
James E. Blair36658cf2013-12-06 17:53:48 -08003307 client = zuul.rpcclient.RPCClient('127.0.0.1',
3308 self.gearman_server.port)
3309 r = client.promote(pipeline='gate',
3310 change_ids=['2,1', '3,1'])
3311
Sean Daguef39b9ca2014-01-10 21:34:35 -05003312 # ensure that enqueue times are durable
3313 items = self.sched.layout.pipelines['gate'].getAllItems()
3314 for item in items:
3315 self.assertEqual(
3316 enqueue_times[str(item.change)], item.enqueue_time)
3317
James E. Blair78acec92014-02-06 07:11:32 -08003318 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003319 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003320 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003321 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003322 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003323 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003324 self.waitUntilSettled()
3325
3326 self.assertEqual(len(self.builds), 6)
3327 self.assertEqual(self.builds[0].name, 'project-test1')
3328 self.assertEqual(self.builds[1].name, 'project-test2')
3329 self.assertEqual(self.builds[2].name, 'project-test1')
3330 self.assertEqual(self.builds[3].name, 'project-test2')
3331 self.assertEqual(self.builds[4].name, 'project-test1')
3332 self.assertEqual(self.builds[5].name, 'project-test2')
3333
3334 self.assertTrue(self.job_has_changes(self.builds[0], B))
3335 self.assertFalse(self.job_has_changes(self.builds[0], A))
3336 self.assertFalse(self.job_has_changes(self.builds[0], C))
3337
3338 self.assertTrue(self.job_has_changes(self.builds[2], B))
3339 self.assertTrue(self.job_has_changes(self.builds[2], C))
3340 self.assertFalse(self.job_has_changes(self.builds[2], A))
3341
3342 self.assertTrue(self.job_has_changes(self.builds[4], B))
3343 self.assertTrue(self.job_has_changes(self.builds[4], C))
3344 self.assertTrue(self.job_has_changes(self.builds[4], A))
3345
James E. Blair08d19992016-08-10 15:25:31 -07003346 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003347 self.waitUntilSettled()
3348
3349 self.assertEqual(A.data['status'], 'MERGED')
3350 self.assertEqual(A.reported, 2)
3351 self.assertEqual(B.data['status'], 'MERGED')
3352 self.assertEqual(B.reported, 2)
3353 self.assertEqual(C.data['status'], 'MERGED')
3354 self.assertEqual(C.reported, 2)
3355
3356 client.shutdown()
3357 self.assertEqual(r, True)
3358
James E. Blairec056492016-07-22 09:45:56 -07003359 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003360 def test_client_promote_dependent(self):
3361 "Test that the RPC client can promote a dependent change"
3362 # C (depends on B) -> B -> A ; then promote C to get:
3363 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003364 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003365 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3366 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3367 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3368
3369 C.setDependsOn(B, 1)
3370
James E. Blair8b5408c2016-08-08 15:37:46 -07003371 A.addApproval('code-review', 2)
3372 B.addApproval('code-review', 2)
3373 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003374
James E. Blair8b5408c2016-08-08 15:37:46 -07003375 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3376 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3377 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003378
3379 self.waitUntilSettled()
3380
3381 client = zuul.rpcclient.RPCClient('127.0.0.1',
3382 self.gearman_server.port)
3383 r = client.promote(pipeline='gate',
3384 change_ids=['3,1'])
3385
James E. Blair78acec92014-02-06 07:11:32 -08003386 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003387 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003388 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003389 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003390 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003391 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003392 self.waitUntilSettled()
3393
3394 self.assertEqual(len(self.builds), 6)
3395 self.assertEqual(self.builds[0].name, 'project-test1')
3396 self.assertEqual(self.builds[1].name, 'project-test2')
3397 self.assertEqual(self.builds[2].name, 'project-test1')
3398 self.assertEqual(self.builds[3].name, 'project-test2')
3399 self.assertEqual(self.builds[4].name, 'project-test1')
3400 self.assertEqual(self.builds[5].name, 'project-test2')
3401
3402 self.assertTrue(self.job_has_changes(self.builds[0], B))
3403 self.assertFalse(self.job_has_changes(self.builds[0], A))
3404 self.assertFalse(self.job_has_changes(self.builds[0], C))
3405
3406 self.assertTrue(self.job_has_changes(self.builds[2], B))
3407 self.assertTrue(self.job_has_changes(self.builds[2], C))
3408 self.assertFalse(self.job_has_changes(self.builds[2], A))
3409
3410 self.assertTrue(self.job_has_changes(self.builds[4], B))
3411 self.assertTrue(self.job_has_changes(self.builds[4], C))
3412 self.assertTrue(self.job_has_changes(self.builds[4], A))
3413
James E. Blair08d19992016-08-10 15:25:31 -07003414 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003415 self.waitUntilSettled()
3416
3417 self.assertEqual(A.data['status'], 'MERGED')
3418 self.assertEqual(A.reported, 2)
3419 self.assertEqual(B.data['status'], 'MERGED')
3420 self.assertEqual(B.reported, 2)
3421 self.assertEqual(C.data['status'], 'MERGED')
3422 self.assertEqual(C.reported, 2)
3423
3424 client.shutdown()
3425 self.assertEqual(r, True)
3426
James E. Blairec056492016-07-22 09:45:56 -07003427 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003428 def test_client_promote_negative(self):
3429 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003430 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003431 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003432 A.addApproval('code-review', 2)
3433 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003434 self.waitUntilSettled()
3435
3436 client = zuul.rpcclient.RPCClient('127.0.0.1',
3437 self.gearman_server.port)
3438
3439 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3440 r = client.promote(pipeline='nonexistent',
3441 change_ids=['2,1', '3,1'])
3442 client.shutdown()
3443 self.assertEqual(r, False)
3444
3445 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3446 r = client.promote(pipeline='gate',
3447 change_ids=['4,1'])
3448 client.shutdown()
3449 self.assertEqual(r, False)
3450
James E. Blair08d19992016-08-10 15:25:31 -07003451 self.launch_server.hold_jobs_in_build = False
3452 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003453 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003454
James E. Blairec056492016-07-22 09:45:56 -07003455 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003456 def test_queue_rate_limiting(self):
3457 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003458 self.updateConfigLayout(
3459 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003460 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003461 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003462 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3463 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3464 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3465
3466 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003467 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003468
James E. Blair8b5408c2016-08-08 15:37:46 -07003469 A.addApproval('code-review', 2)
3470 B.addApproval('code-review', 2)
3471 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003472
James E. Blair8b5408c2016-08-08 15:37:46 -07003473 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3474 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3475 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003476 self.waitUntilSettled()
3477
3478 # Only A and B will have their merge jobs queued because
3479 # window is 2.
3480 self.assertEqual(len(self.builds), 2)
3481 self.assertEqual(self.builds[0].name, 'project-merge')
3482 self.assertEqual(self.builds[1].name, 'project-merge')
3483
James E. Blair08d19992016-08-10 15:25:31 -07003484 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003485 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003486 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003487 self.waitUntilSettled()
3488
3489 # Only A and B will have their test jobs queued because
3490 # window is 2.
3491 self.assertEqual(len(self.builds), 4)
3492 self.assertEqual(self.builds[0].name, 'project-test1')
3493 self.assertEqual(self.builds[1].name, 'project-test2')
3494 self.assertEqual(self.builds[2].name, 'project-test1')
3495 self.assertEqual(self.builds[3].name, 'project-test2')
3496
James E. Blair08d19992016-08-10 15:25:31 -07003497 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003498 self.waitUntilSettled()
3499
3500 queue = self.sched.layout.pipelines['gate'].queues[0]
3501 # A failed so window is reduced by 1 to 1.
3502 self.assertEqual(queue.window, 1)
3503 self.assertEqual(queue.window_floor, 1)
3504 self.assertEqual(A.data['status'], 'NEW')
3505
3506 # Gate is reset and only B's merge job is queued because
3507 # window shrunk to 1.
3508 self.assertEqual(len(self.builds), 1)
3509 self.assertEqual(self.builds[0].name, 'project-merge')
3510
James E. Blair08d19992016-08-10 15:25:31 -07003511 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003512 self.waitUntilSettled()
3513
3514 # Only B's test jobs are queued because window is still 1.
3515 self.assertEqual(len(self.builds), 2)
3516 self.assertEqual(self.builds[0].name, 'project-test1')
3517 self.assertEqual(self.builds[1].name, 'project-test2')
3518
James E. Blair08d19992016-08-10 15:25:31 -07003519 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003520 self.waitUntilSettled()
3521
3522 # B was successfully merged so window is increased to 2.
3523 self.assertEqual(queue.window, 2)
3524 self.assertEqual(queue.window_floor, 1)
3525 self.assertEqual(B.data['status'], 'MERGED')
3526
3527 # Only C is left and its merge job is queued.
3528 self.assertEqual(len(self.builds), 1)
3529 self.assertEqual(self.builds[0].name, 'project-merge')
3530
James E. Blair08d19992016-08-10 15:25:31 -07003531 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003532 self.waitUntilSettled()
3533
3534 # After successful merge job the test jobs for C are queued.
3535 self.assertEqual(len(self.builds), 2)
3536 self.assertEqual(self.builds[0].name, 'project-test1')
3537 self.assertEqual(self.builds[1].name, 'project-test2')
3538
James E. Blair08d19992016-08-10 15:25:31 -07003539 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003540 self.waitUntilSettled()
3541
3542 # C successfully merged so window is bumped to 3.
3543 self.assertEqual(queue.window, 3)
3544 self.assertEqual(queue.window_floor, 1)
3545 self.assertEqual(C.data['status'], 'MERGED')
3546
James E. Blairec056492016-07-22 09:45:56 -07003547 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003548 def test_queue_rate_limiting_dependent(self):
3549 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003550 self.updateConfigLayout(
3551 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003552 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003553 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003554 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3555 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3556 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3557
3558 B.setDependsOn(A, 1)
3559
James E. Blair08d19992016-08-10 15:25:31 -07003560 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003561
James E. Blair8b5408c2016-08-08 15:37:46 -07003562 A.addApproval('code-review', 2)
3563 B.addApproval('code-review', 2)
3564 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003565
James E. Blair8b5408c2016-08-08 15:37:46 -07003566 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3567 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3568 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003569 self.waitUntilSettled()
3570
3571 # Only A and B will have their merge jobs queued because
3572 # window is 2.
3573 self.assertEqual(len(self.builds), 2)
3574 self.assertEqual(self.builds[0].name, 'project-merge')
3575 self.assertEqual(self.builds[1].name, 'project-merge')
3576
James E. Blair08d19992016-08-10 15:25:31 -07003577 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003578 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003579 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003580 self.waitUntilSettled()
3581
3582 # Only A and B will have their test jobs queued because
3583 # window is 2.
3584 self.assertEqual(len(self.builds), 4)
3585 self.assertEqual(self.builds[0].name, 'project-test1')
3586 self.assertEqual(self.builds[1].name, 'project-test2')
3587 self.assertEqual(self.builds[2].name, 'project-test1')
3588 self.assertEqual(self.builds[3].name, 'project-test2')
3589
James E. Blair08d19992016-08-10 15:25:31 -07003590 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003591 self.waitUntilSettled()
3592
3593 queue = self.sched.layout.pipelines['gate'].queues[0]
3594 # A failed so window is reduced by 1 to 1.
3595 self.assertEqual(queue.window, 1)
3596 self.assertEqual(queue.window_floor, 1)
3597 self.assertEqual(A.data['status'], 'NEW')
3598 self.assertEqual(B.data['status'], 'NEW')
3599
3600 # Gate is reset and only C's merge job is queued because
3601 # window shrunk to 1 and A and B were dequeued.
3602 self.assertEqual(len(self.builds), 1)
3603 self.assertEqual(self.builds[0].name, 'project-merge')
3604
James E. Blair08d19992016-08-10 15:25:31 -07003605 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003606 self.waitUntilSettled()
3607
3608 # Only C's test jobs are queued because window is still 1.
3609 self.assertEqual(len(self.builds), 2)
3610 self.assertEqual(self.builds[0].name, 'project-test1')
3611 self.assertEqual(self.builds[1].name, 'project-test2')
3612
James E. Blair08d19992016-08-10 15:25:31 -07003613 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003614 self.waitUntilSettled()
3615
3616 # C was successfully merged so window is increased to 2.
3617 self.assertEqual(queue.window, 2)
3618 self.assertEqual(queue.window_floor, 1)
3619 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003620
James E. Blairec056492016-07-22 09:45:56 -07003621 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003622 def test_worker_update_metadata(self):
3623 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003624 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003625
3626 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003627 A.addApproval('code-review', 2)
3628 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003629 self.waitUntilSettled()
3630
3631 self.assertEqual(len(self.launcher.builds), 1)
3632
3633 self.log.debug('Current builds:')
3634 self.log.debug(self.launcher.builds)
3635
3636 start = time.time()
3637 while True:
3638 if time.time() - start > 10:
3639 raise Exception("Timeout waiting for gearman server to report "
3640 + "back to the client")
3641 build = self.launcher.builds.values()[0]
3642 if build.worker.name == "My Worker":
3643 break
3644 else:
3645 time.sleep(0)
3646
3647 self.log.debug(build)
3648 self.assertEqual("My Worker", build.worker.name)
3649 self.assertEqual("localhost", build.worker.hostname)
3650 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3651 self.assertEqual("zuul.example.org", build.worker.fqdn)
3652 self.assertEqual("FakeBuilder", build.worker.program)
3653 self.assertEqual("v1.1", build.worker.version)
3654 self.assertEqual({'something': 'else'}, build.worker.extra)
3655
James E. Blair08d19992016-08-10 15:25:31 -07003656 self.launch_server.hold_jobs_in_build = False
3657 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003658 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003659
James E. Blairec056492016-07-22 09:45:56 -07003660 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003661 def test_footer_message(self):
3662 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003663 self.updateConfigLayout(
3664 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003665 self.sched.reconfigure(self.config)
3666 self.registerJobs()
3667
3668 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003669 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003670 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003671 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003672 self.waitUntilSettled()
3673
3674 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003675 B.addApproval('code-review', 2)
3676 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003677 self.waitUntilSettled()
3678
3679 self.assertEqual(2, len(self.smtp_messages))
3680
3681 failure_body = """\
3682Build failed. For information on how to proceed, see \
3683http://wiki.example.org/Test_Failures
3684
3685- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3686- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3687
3688For CI problems and help debugging, contact ci@example.org"""
3689
3690 success_body = """\
3691Build succeeded.
3692
3693- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3694- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3695
3696For CI problems and help debugging, contact ci@example.org"""
3697
3698 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3699 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003700
James E. Blairec056492016-07-22 09:45:56 -07003701 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003702 def test_merge_failure_reporters(self):
3703 """Check that the config is set up correctly"""
3704
James E. Blairf84026c2015-12-08 16:11:46 -08003705 self.updateConfigLayout(
3706 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003707 self.sched.reconfigure(self.config)
3708 self.registerJobs()
3709
3710 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003711 "Merge Failed.\n\nThis change or one of its cross-repo "
3712 "dependencies was unable to be automatically merged with the "
3713 "current state of its repository. Please rebase the change and "
3714 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003715 self.sched.layout.pipelines['check'].merge_failure_message)
3716 self.assertEqual(
3717 "The merge failed! For more information...",
3718 self.sched.layout.pipelines['gate'].merge_failure_message)
3719
3720 self.assertEqual(
3721 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3722 self.assertEqual(
3723 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3724
3725 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003726 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3727 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003728
3729 self.assertTrue(
3730 (
3731 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003732 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003733 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003734 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003735 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003736 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003737 ) or (
3738 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003739 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003740 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003741 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003742 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003743 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003744 )
3745 )
3746
James E. Blairec056492016-07-22 09:45:56 -07003747 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003748 def test_merge_failure_reports(self):
3749 """Check that when a change fails to merge the correct message is sent
3750 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003751 self.updateConfigLayout(
3752 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003753 self.sched.reconfigure(self.config)
3754 self.registerJobs()
3755
3756 # Check a test failure isn't reported to SMTP
3757 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003758 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003759 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003760 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003761 self.waitUntilSettled()
3762
3763 self.assertEqual(3, len(self.history)) # 3 jobs
3764 self.assertEqual(0, len(self.smtp_messages))
3765
3766 # Check a merge failure is reported to SMTP
3767 # B should be merged, but C will conflict with B
3768 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3769 B.addPatchset(['conflict'])
3770 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3771 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003772 B.addApproval('code-review', 2)
3773 C.addApproval('code-review', 2)
3774 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3775 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003776 self.waitUntilSettled()
3777
3778 self.assertEqual(6, len(self.history)) # A and B jobs
3779 self.assertEqual(1, len(self.smtp_messages))
3780 self.assertEqual('The merge failed! For more information...',
3781 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003782
James E. Blairec056492016-07-22 09:45:56 -07003783 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003784 def test_default_merge_failure_reports(self):
3785 """Check that the default merge failure reports are correct."""
3786
3787 # A should report success, B should report merge failure.
3788 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3789 A.addPatchset(['conflict'])
3790 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3791 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003792 A.addApproval('code-review', 2)
3793 B.addApproval('code-review', 2)
3794 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3795 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003796 self.waitUntilSettled()
3797
3798 self.assertEqual(3, len(self.history)) # A jobs
3799 self.assertEqual(A.reported, 2)
3800 self.assertEqual(B.reported, 2)
3801 self.assertEqual(A.data['status'], 'MERGED')
3802 self.assertEqual(B.data['status'], 'NEW')
3803 self.assertIn('Build succeeded', A.messages[1])
3804 self.assertIn('Merge Failed', B.messages[1])
3805 self.assertIn('automatically merged', B.messages[1])
3806 self.assertNotIn('logs.example.com', B.messages[1])
3807 self.assertNotIn('SKIPPED', B.messages[1])
3808
James E. Blairec056492016-07-22 09:45:56 -07003809 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003810 def test_swift_instructions(self):
3811 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003812 self.updateConfigLayout(
3813 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003814 self.sched.reconfigure(self.config)
3815 self.registerJobs()
3816
James E. Blair08d19992016-08-10 15:25:31 -07003817 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003818 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3819
James E. Blair8b5408c2016-08-08 15:37:46 -07003820 A.addApproval('code-review', 2)
3821 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003822 self.waitUntilSettled()
3823
3824 self.assertEqual(
3825 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3826 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003827 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003828 self.assertEqual(5,
3829 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3830 split('\n')))
3831 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3832
3833 self.assertEqual(
3834 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3835 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003836 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003837 self.assertEqual(5,
3838 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3839 split('\n')))
3840 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3841
3842 self.assertEqual(
3843 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3844 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003845 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003846 self.assertEqual(5,
3847 len(self.builds[1].
3848 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3849 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3850
James E. Blair08d19992016-08-10 15:25:31 -07003851 self.launch_server.hold_jobs_in_build = False
3852 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003853 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003854
James E. Blairec056492016-07-22 09:45:56 -07003855 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003856 def test_client_get_running_jobs(self):
3857 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003858 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003859 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003860 A.addApproval('code-review', 2)
3861 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003862 self.waitUntilSettled()
3863
3864 client = zuul.rpcclient.RPCClient('127.0.0.1',
3865 self.gearman_server.port)
3866
3867 # Wait for gearman server to send the initial workData back to zuul
3868 start = time.time()
3869 while True:
3870 if time.time() - start > 10:
3871 raise Exception("Timeout waiting for gearman server to report "
3872 + "back to the client")
3873 build = self.launcher.builds.values()[0]
3874 if build.worker.name == "My Worker":
3875 break
3876 else:
3877 time.sleep(0)
3878
3879 running_items = client.get_running_jobs()
3880
3881 self.assertEqual(1, len(running_items))
3882 running_item = running_items[0]
3883 self.assertEqual([], running_item['failing_reasons'])
3884 self.assertEqual([], running_item['items_behind'])
3885 self.assertEqual('https://hostname/1', running_item['url'])
3886 self.assertEqual(None, running_item['item_ahead'])
3887 self.assertEqual('org/project', running_item['project'])
3888 self.assertEqual(None, running_item['remaining_time'])
3889 self.assertEqual(True, running_item['active'])
3890 self.assertEqual('1,1', running_item['id'])
3891
3892 self.assertEqual(3, len(running_item['jobs']))
3893 for job in running_item['jobs']:
3894 if job['name'] == 'project-merge':
3895 self.assertEqual('project-merge', job['name'])
3896 self.assertEqual('gate', job['pipeline'])
3897 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003898 self.assertEqual('https://server/job/project-merge/0/',
3899 job['url'])
3900 self.assertEqual(7, len(job['worker']))
3901 self.assertEqual(False, job['canceled'])
3902 self.assertEqual(True, job['voting'])
3903 self.assertEqual(None, job['result'])
3904 self.assertEqual('gate', job['pipeline'])
3905 break
3906
James E. Blair08d19992016-08-10 15:25:31 -07003907 self.launch_server.hold_jobs_in_build = False
3908 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003909 self.waitUntilSettled()
3910
3911 running_items = client.get_running_jobs()
3912 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003913
James E. Blairec056492016-07-22 09:45:56 -07003914 @skip("Disabled for early v3 development")
James E. Blairbadc1ad2014-04-28 13:55:14 -07003915 def test_nonvoting_pipeline(self):
3916 "Test that a nonvoting pipeline (experimental) can still report"
3917
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003918 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3919 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003920 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3921 self.waitUntilSettled()
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003922 self.assertEqual(
3923 self.getJobFromHistory('experimental-project-test').result,
3924 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003925 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003926
James E. Blairec056492016-07-22 09:45:56 -07003927 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003928 def test_crd_gate(self):
3929 "Test cross-repo dependencies"
3930 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3931 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003932 A.addApproval('code-review', 2)
3933 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003934
3935 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3936 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3937 AM2.setMerged()
3938 AM1.setMerged()
3939
3940 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3941 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3942 BM2.setMerged()
3943 BM1.setMerged()
3944
3945 # A -> AM1 -> AM2
3946 # B -> BM1 -> BM2
3947 # A Depends-On: B
3948 # M2 is here to make sure it is never queried. If it is, it
3949 # means zuul is walking down the entire history of merged
3950 # changes.
3951
3952 B.setDependsOn(BM1, 1)
3953 BM1.setDependsOn(BM2, 1)
3954
3955 A.setDependsOn(AM1, 1)
3956 AM1.setDependsOn(AM2, 1)
3957
3958 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3959 A.subject, B.data['id'])
3960
James E. Blair8b5408c2016-08-08 15:37:46 -07003961 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003962 self.waitUntilSettled()
3963
3964 self.assertEqual(A.data['status'], 'NEW')
3965 self.assertEqual(B.data['status'], 'NEW')
3966
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003967 for connection in self.connections.values():
3968 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003969
James E. Blair08d19992016-08-10 15:25:31 -07003970 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003971 B.addApproval('approved', 1)
3972 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003973 self.waitUntilSettled()
3974
James E. Blair08d19992016-08-10 15:25:31 -07003975 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003976 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003977 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003978 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003979 self.launch_server.hold_jobs_in_build = False
3980 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003981 self.waitUntilSettled()
3982
3983 self.assertEqual(AM2.queried, 0)
3984 self.assertEqual(BM2.queried, 0)
3985 self.assertEqual(A.data['status'], 'MERGED')
3986 self.assertEqual(B.data['status'], 'MERGED')
3987 self.assertEqual(A.reported, 2)
3988 self.assertEqual(B.reported, 2)
3989
James E. Blair8f78d882015-02-05 08:51:37 -08003990 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3991 '2,1 1,1')
3992
James E. Blairec056492016-07-22 09:45:56 -07003993 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003994 def test_crd_branch(self):
3995 "Test cross-repo dependencies in multiple branches"
3996 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3997 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3998 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3999 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07004000 A.addApproval('code-review', 2)
4001 B.addApproval('code-review', 2)
4002 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004003
4004 # A Depends-On: B+C
4005 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4006 A.subject, B.data['id'])
4007
James E. Blair08d19992016-08-10 15:25:31 -07004008 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004009 B.addApproval('approved', 1)
4010 C.addApproval('approved', 1)
4011 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004012 self.waitUntilSettled()
4013
James E. Blair08d19992016-08-10 15:25:31 -07004014 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004015 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004016 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004017 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004018 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004019 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004020 self.launch_server.hold_jobs_in_build = False
4021 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004022 self.waitUntilSettled()
4023
4024 self.assertEqual(A.data['status'], 'MERGED')
4025 self.assertEqual(B.data['status'], 'MERGED')
4026 self.assertEqual(C.data['status'], 'MERGED')
4027 self.assertEqual(A.reported, 2)
4028 self.assertEqual(B.reported, 2)
4029 self.assertEqual(C.reported, 2)
4030
4031 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4032 '2,1 3,1 1,1')
4033
James E. Blairec056492016-07-22 09:45:56 -07004034 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08004035 def test_crd_multiline(self):
4036 "Test multiple depends-on lines in commit"
4037 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4038 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4039 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07004040 A.addApproval('code-review', 2)
4041 B.addApproval('code-review', 2)
4042 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004043
4044 # A Depends-On: B+C
4045 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
4046 A.subject, B.data['id'], C.data['id'])
4047
James E. Blair08d19992016-08-10 15:25:31 -07004048 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004049 B.addApproval('approved', 1)
4050 C.addApproval('approved', 1)
4051 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004052 self.waitUntilSettled()
4053
James E. Blair08d19992016-08-10 15:25:31 -07004054 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004055 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004056 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004057 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004058 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004059 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004060 self.launch_server.hold_jobs_in_build = False
4061 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004062 self.waitUntilSettled()
4063
4064 self.assertEqual(A.data['status'], 'MERGED')
4065 self.assertEqual(B.data['status'], 'MERGED')
4066 self.assertEqual(C.data['status'], 'MERGED')
4067 self.assertEqual(A.reported, 2)
4068 self.assertEqual(B.reported, 2)
4069 self.assertEqual(C.reported, 2)
4070
4071 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4072 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004073
James E. Blairec056492016-07-22 09:45:56 -07004074 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004075 def test_crd_unshared_gate(self):
4076 "Test cross-repo dependencies in unshared gate queues"
4077 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4078 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004079 A.addApproval('code-review', 2)
4080 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004081
4082 # A Depends-On: B
4083 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4084 A.subject, B.data['id'])
4085
4086 # A and B do not share a queue, make sure that A is unable to
4087 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004088 B.addApproval('approved', 1)
4089 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004090 self.waitUntilSettled()
4091
4092 self.assertEqual(A.data['status'], 'NEW')
4093 self.assertEqual(B.data['status'], 'NEW')
4094 self.assertEqual(A.reported, 0)
4095 self.assertEqual(B.reported, 0)
4096 self.assertEqual(len(self.history), 0)
4097
4098 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004099 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004100 self.waitUntilSettled()
4101
4102 self.assertEqual(B.data['status'], 'MERGED')
4103 self.assertEqual(B.reported, 2)
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))
James E. Blair5ee24252014-12-30 10:12:29 -08004108 self.waitUntilSettled()
4109
4110 self.assertEqual(A.data['status'], 'MERGED')
4111 self.assertEqual(A.reported, 2)
4112
James E. Blairec056492016-07-22 09:45:56 -07004113 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004114 def test_crd_gate_reverse(self):
4115 "Test reverse cross-repo dependencies"
4116 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4117 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004118 A.addApproval('code-review', 2)
4119 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004120
4121 # A Depends-On: B
4122
4123 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4124 A.subject, B.data['id'])
4125
James E. Blair8b5408c2016-08-08 15:37:46 -07004126 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004127 self.waitUntilSettled()
4128
4129 self.assertEqual(A.data['status'], 'NEW')
4130 self.assertEqual(B.data['status'], 'NEW')
4131
James E. Blair08d19992016-08-10 15:25:31 -07004132 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004133 A.addApproval('approved', 1)
4134 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004135 self.waitUntilSettled()
4136
James E. Blair08d19992016-08-10 15:25:31 -07004137 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004138 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004139 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004140 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004141 self.launch_server.hold_jobs_in_build = False
4142 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004143 self.waitUntilSettled()
4144
4145 self.assertEqual(A.data['status'], 'MERGED')
4146 self.assertEqual(B.data['status'], 'MERGED')
4147 self.assertEqual(A.reported, 2)
4148 self.assertEqual(B.reported, 2)
4149
4150 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4151 '2,1 1,1')
4152
James E. Blairec056492016-07-22 09:45:56 -07004153 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004154 def test_crd_cycle(self):
4155 "Test cross-repo dependency cycles"
4156 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4157 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004158 A.addApproval('code-review', 2)
4159 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004160
4161 # A -> B -> A (via commit-depends)
4162
4163 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4164 A.subject, B.data['id'])
4165 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4166 B.subject, A.data['id'])
4167
James E. Blair8b5408c2016-08-08 15:37:46 -07004168 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004169 self.waitUntilSettled()
4170
4171 self.assertEqual(A.reported, 0)
4172 self.assertEqual(B.reported, 0)
4173 self.assertEqual(A.data['status'], 'NEW')
4174 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004175
James E. Blairec056492016-07-22 09:45:56 -07004176 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004177 def test_crd_gate_unknown(self):
4178 "Test unknown projects in dependent pipeline"
4179 self.init_repo("org/unknown")
4180 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4181 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004182 A.addApproval('code-review', 2)
4183 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004184
4185 # A Depends-On: B
4186 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4187 A.subject, B.data['id'])
4188
James E. Blair8b5408c2016-08-08 15:37:46 -07004189 B.addApproval('approved', 1)
4190 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004191 self.waitUntilSettled()
4192
4193 # Unknown projects cannot share a queue with any other
4194 # since they don't have common jobs with any other (they have no jobs).
4195 # Changes which depend on unknown project changes
4196 # should not be processed in dependent pipeline
4197 self.assertEqual(A.data['status'], 'NEW')
4198 self.assertEqual(B.data['status'], 'NEW')
4199 self.assertEqual(A.reported, 0)
4200 self.assertEqual(B.reported, 0)
4201 self.assertEqual(len(self.history), 0)
4202
4203 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004204 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004205 B.setMerged()
4206 self.waitUntilSettled()
4207 self.assertEqual(len(self.history), 0)
4208
4209 # Now that B is merged, A should be able to be enqueued and
4210 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004211 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004212 self.waitUntilSettled()
4213
4214 self.assertEqual(A.data['status'], 'MERGED')
4215 self.assertEqual(A.reported, 2)
4216 self.assertEqual(B.data['status'], 'MERGED')
4217 self.assertEqual(B.reported, 0)
4218
James E. Blairec056492016-07-22 09:45:56 -07004219 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004220 def test_crd_check(self):
4221 "Test cross-repo dependencies in independent pipelines"
4222
4223 self.gearman_server.hold_jobs_in_queue = True
4224 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4225 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4226
4227 # A Depends-On: B
4228 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4229 A.subject, B.data['id'])
4230
4231 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4232 self.waitUntilSettled()
4233
4234 queue = self.gearman_server.getQueue()
4235 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4236 self.gearman_server.hold_jobs_in_queue = False
4237 self.gearman_server.release()
4238 self.waitUntilSettled()
4239
4240 path = os.path.join(self.git_root, "org/project1")
4241 repo = git.Repo(path)
4242 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4243 repo_messages.reverse()
4244 correct_messages = ['initial commit', 'A-1']
4245 self.assertEqual(repo_messages, correct_messages)
4246
4247 path = os.path.join(self.git_root, "org/project2")
4248 repo = git.Repo(path)
4249 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4250 repo_messages.reverse()
4251 correct_messages = ['initial commit', 'B-1']
4252 self.assertEqual(repo_messages, correct_messages)
4253
4254 self.assertEqual(A.data['status'], 'NEW')
4255 self.assertEqual(B.data['status'], 'NEW')
4256 self.assertEqual(A.reported, 1)
4257 self.assertEqual(B.reported, 0)
4258
4259 self.assertEqual(self.history[0].changes, '2,1 1,1')
4260 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004261
James E. Blairec056492016-07-22 09:45:56 -07004262 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004263 def test_crd_check_git_depends(self):
4264 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004265 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004266 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4267 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4268
4269 # Add two git-dependent changes and make sure they both report
4270 # success.
4271 B.setDependsOn(A, 1)
4272 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4273 self.waitUntilSettled()
4274 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4275 self.waitUntilSettled()
4276
James E. Blairb8c16472015-05-05 14:55:26 -07004277 self.orderedRelease()
4278 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004279 self.waitUntilSettled()
4280
4281 self.assertEqual(A.data['status'], 'NEW')
4282 self.assertEqual(B.data['status'], 'NEW')
4283 self.assertEqual(A.reported, 1)
4284 self.assertEqual(B.reported, 1)
4285
4286 self.assertEqual(self.history[0].changes, '1,1')
4287 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4288 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4289
4290 self.assertIn('Build succeeded', A.messages[0])
4291 self.assertIn('Build succeeded', B.messages[0])
4292
James E. Blairec056492016-07-22 09:45:56 -07004293 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004294 def test_crd_check_duplicate(self):
4295 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004296 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004297 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4298 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4299 check_pipeline = self.sched.layout.pipelines['check']
4300
4301 # Add two git-dependent changes...
4302 B.setDependsOn(A, 1)
4303 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4304 self.waitUntilSettled()
4305 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4306
4307 # ...make sure the live one is not duplicated...
4308 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4309 self.waitUntilSettled()
4310 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4311
4312 # ...but the non-live one is able to be.
4313 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4314 self.waitUntilSettled()
4315 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4316
Clark Boylandd849822015-03-02 12:38:14 -08004317 # Release jobs in order to avoid races with change A jobs
4318 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004319 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004320 self.launch_server.hold_jobs_in_build = False
4321 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004322 self.waitUntilSettled()
4323
4324 self.assertEqual(A.data['status'], 'NEW')
4325 self.assertEqual(B.data['status'], 'NEW')
4326 self.assertEqual(A.reported, 1)
4327 self.assertEqual(B.reported, 1)
4328
4329 self.assertEqual(self.history[0].changes, '1,1 2,1')
4330 self.assertEqual(self.history[1].changes, '1,1')
4331 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4332
4333 self.assertIn('Build succeeded', A.messages[0])
4334 self.assertIn('Build succeeded', B.messages[0])
4335
James E. Blairec056492016-07-22 09:45:56 -07004336 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004337 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004338 "Test cross-repo dependencies re-enqueued in independent pipelines"
4339
4340 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004341 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4342 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004343
4344 # A Depends-On: B
4345 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4346 A.subject, B.data['id'])
4347
4348 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4349 self.waitUntilSettled()
4350
4351 self.sched.reconfigure(self.config)
4352
4353 # Make sure the items still share a change queue, and the
4354 # first one is not live.
4355 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4356 queue = self.sched.layout.pipelines['check'].queues[0]
4357 first_item = queue.queue[0]
4358 for item in queue.queue:
4359 self.assertEqual(item.queue, first_item.queue)
4360 self.assertFalse(first_item.live)
4361 self.assertTrue(queue.queue[1].live)
4362
4363 self.gearman_server.hold_jobs_in_queue = False
4364 self.gearman_server.release()
4365 self.waitUntilSettled()
4366
4367 self.assertEqual(A.data['status'], 'NEW')
4368 self.assertEqual(B.data['status'], 'NEW')
4369 self.assertEqual(A.reported, 1)
4370 self.assertEqual(B.reported, 0)
4371
4372 self.assertEqual(self.history[0].changes, '2,1 1,1')
4373 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004374
James E. Blairec056492016-07-22 09:45:56 -07004375 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004376 def test_crd_check_reconfiguration(self):
4377 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4378
James E. Blairec056492016-07-22 09:45:56 -07004379 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004380 def test_crd_undefined_project(self):
4381 """Test that undefined projects in dependencies are handled for
4382 independent pipelines"""
4383 # It's a hack for fake gerrit,
4384 # as it implies repo creation upon the creation of any change
4385 self.init_repo("org/unknown")
4386 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4387
James E. Blairec056492016-07-22 09:45:56 -07004388 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004389 def test_crd_check_ignore_dependencies(self):
4390 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004391 self.updateConfigLayout(
4392 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004393 self.sched.reconfigure(self.config)
4394 self.registerJobs()
4395
4396 self.gearman_server.hold_jobs_in_queue = True
4397 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4398 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4399 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4400
4401 # A Depends-On: B
4402 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4403 A.subject, B.data['id'])
4404 # C git-depends on B
4405 C.setDependsOn(B, 1)
4406 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4407 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4408 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4409 self.waitUntilSettled()
4410
4411 # Make sure none of the items share a change queue, and all
4412 # are live.
4413 check_pipeline = self.sched.layout.pipelines['check']
4414 self.assertEqual(len(check_pipeline.queues), 3)
4415 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4416 for item in check_pipeline.getAllItems():
4417 self.assertTrue(item.live)
4418
4419 self.gearman_server.hold_jobs_in_queue = False
4420 self.gearman_server.release()
4421 self.waitUntilSettled()
4422
4423 self.assertEqual(A.data['status'], 'NEW')
4424 self.assertEqual(B.data['status'], 'NEW')
4425 self.assertEqual(C.data['status'], 'NEW')
4426 self.assertEqual(A.reported, 1)
4427 self.assertEqual(B.reported, 1)
4428 self.assertEqual(C.reported, 1)
4429
4430 # Each job should have tested exactly one change
4431 for job in self.history:
4432 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004433
James E. Blairec056492016-07-22 09:45:56 -07004434 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004435 def test_crd_check_transitive(self):
4436 "Test transitive cross-repo dependencies"
4437 # Specifically, if A -> B -> C, and C gets a new patchset and
4438 # A gets a new patchset, ensure the test of A,2 includes B,1
4439 # and C,2 (not C,1 which would indicate stale data in the
4440 # cache for B).
4441 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4442 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4443 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4444
4445 # A Depends-On: B
4446 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4447 A.subject, B.data['id'])
4448
4449 # B Depends-On: C
4450 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4451 B.subject, C.data['id'])
4452
4453 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4454 self.waitUntilSettled()
4455 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4456
4457 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4458 self.waitUntilSettled()
4459 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4460
4461 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4462 self.waitUntilSettled()
4463 self.assertEqual(self.history[-1].changes, '3,1')
4464
4465 C.addPatchset()
4466 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4467 self.waitUntilSettled()
4468 self.assertEqual(self.history[-1].changes, '3,2')
4469
4470 A.addPatchset()
4471 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4472 self.waitUntilSettled()
4473 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004474
James E. Blairec056492016-07-22 09:45:56 -07004475 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004476 def test_crd_cycle_join(self):
4477 "Test an updated change creates a cycle"
4478 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4479
4480 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4481 self.waitUntilSettled()
4482
4483 # Create B->A
4484 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4485 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4486 B.subject, A.data['id'])
4487 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4488 self.waitUntilSettled()
4489
4490 # Update A to add A->B (a cycle).
4491 A.addPatchset()
4492 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4493 A.subject, B.data['id'])
4494 # Normally we would submit the patchset-created event for
4495 # processing here, however, we have no way of noting whether
4496 # the dependency cycle detection correctly raised an
4497 # exception, so instead, we reach into the source driver and
4498 # call the method that would ultimately be called by the event
4499 # processing.
4500
4501 source = self.sched.layout.pipelines['gate'].source
4502 with testtools.ExpectedException(
4503 Exception, "Dependency cycle detected"):
4504 source._getChange(u'1', u'2', True)
4505 self.log.debug("Got expected dependency cycle exception")
4506
4507 # Now if we update B to remove the depends-on, everything
4508 # should be okay. B; A->B
4509
4510 B.addPatchset()
4511 B.data['commitMessage'] = '%s\n' % (B.subject,)
4512 source._getChange(u'1', u'2', True)
4513 source._getChange(u'2', u'2', True)
4514
James E. Blairec056492016-07-22 09:45:56 -07004515 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004516 def test_disable_at(self):
4517 "Test a pipeline will only report to the disabled trigger when failing"
4518
James E. Blairf84026c2015-12-08 16:11:46 -08004519 self.updateConfigLayout(
4520 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004521 self.sched.reconfigure(self.config)
4522
4523 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4524 self.assertEqual(
4525 0, self.sched.layout.pipelines['check']._consecutive_failures)
4526 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4527
4528 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4529 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4530 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4531 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4532 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4533 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4534 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4535 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4536 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4537 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4538 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4539
James E. Blair08d19992016-08-10 15:25:31 -07004540 self.launch_server.failJob('project-test1', A)
4541 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004542 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004543 self.launch_server.failJob('project-test1', D)
4544 self.launch_server.failJob('project-test1', E)
4545 self.launch_server.failJob('project-test1', F)
4546 self.launch_server.failJob('project-test1', G)
4547 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004548 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004549 self.launch_server.failJob('project-test1', J)
4550 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004551
4552 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4553 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4554 self.waitUntilSettled()
4555
4556 self.assertEqual(
4557 2, self.sched.layout.pipelines['check']._consecutive_failures)
4558 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4559
4560 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4561 self.waitUntilSettled()
4562
4563 self.assertEqual(
4564 0, self.sched.layout.pipelines['check']._consecutive_failures)
4565 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4566
4567 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4568 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4569 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4570 self.waitUntilSettled()
4571
4572 # We should be disabled now
4573 self.assertEqual(
4574 3, self.sched.layout.pipelines['check']._consecutive_failures)
4575 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4576
4577 # We need to wait between each of these patches to make sure the
4578 # smtp messages come back in an expected order
4579 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4580 self.waitUntilSettled()
4581 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4582 self.waitUntilSettled()
4583 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4584 self.waitUntilSettled()
4585
4586 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4587 # leaving a message on each change
4588 self.assertEqual(1, len(A.messages))
4589 self.assertIn('Build failed.', A.messages[0])
4590 self.assertEqual(1, len(B.messages))
4591 self.assertIn('Build failed.', B.messages[0])
4592 self.assertEqual(1, len(C.messages))
4593 self.assertIn('Build succeeded.', C.messages[0])
4594 self.assertEqual(1, len(D.messages))
4595 self.assertIn('Build failed.', D.messages[0])
4596 self.assertEqual(1, len(E.messages))
4597 self.assertIn('Build failed.', E.messages[0])
4598 self.assertEqual(1, len(F.messages))
4599 self.assertIn('Build failed.', F.messages[0])
4600
4601 # The last 3 (GHI) would have only reported via smtp.
4602 self.assertEqual(3, len(self.smtp_messages))
4603 self.assertEqual(0, len(G.messages))
4604 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4605 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4606 self.assertEqual(0, len(H.messages))
4607 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4608 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4609 self.assertEqual(0, len(I.messages))
4610 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4611 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4612
4613 # Now reload the configuration (simulate a HUP) to check the pipeline
4614 # comes out of disabled
4615 self.sched.reconfigure(self.config)
4616
4617 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4618 self.assertEqual(
4619 0, self.sched.layout.pipelines['check']._consecutive_failures)
4620 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4621
4622 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4623 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4624 self.waitUntilSettled()
4625
4626 self.assertEqual(
4627 2, self.sched.layout.pipelines['check']._consecutive_failures)
4628 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4629
4630 # J and K went back to gerrit
4631 self.assertEqual(1, len(J.messages))
4632 self.assertIn('Build failed.', J.messages[0])
4633 self.assertEqual(1, len(K.messages))
4634 self.assertIn('Build failed.', K.messages[0])
4635 # No more messages reported via smtp
4636 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004637
James E. Blairec056492016-07-22 09:45:56 -07004638 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004639 def test_success_pattern(self):
4640 "Ensure bad build params are ignored"
4641
4642 # Use SMTP reporter to grab the result message easier
4643 self.init_repo("org/docs")
4644 self.config.set('zuul', 'layout_config',
4645 'tests/fixtures/layout-success-pattern.yaml')
4646 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004647 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004648 self.registerJobs()
4649
4650 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4651 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4652 self.waitUntilSettled()
4653
4654 # Grab build id
4655 self.assertEqual(len(self.builds), 1)
4656 uuid = self.builds[0].unique[:7]
4657
James E. Blair08d19992016-08-10 15:25:31 -07004658 self.launch_server.hold_jobs_in_build = False
4659 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004660 self.waitUntilSettled()
4661
4662 self.assertEqual(len(self.smtp_messages), 1)
4663 body = self.smtp_messages[0]['body'].splitlines()
4664 self.assertEqual('Build succeeded.', body[0])
4665
4666 self.assertIn(
4667 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4668 'docs-draft-test/%s/publish-docs/' % uuid,
4669 body[2])
4670 self.assertIn(
4671 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4672 body[3])