blob: abb05487a2331f6c9bee37a821dbd662166efc71 [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
James E. Blairec056492016-07-22 09:45:56 -07001881 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001882 def test_abandoned_gate(self):
1883 "Test that an abandoned change is dequeued from gate"
1884
James E. Blair08d19992016-08-10 15:25:31 -07001885 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001886
1887 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001888 A.addApproval('code-review', 2)
1889 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001890 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001891 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1892 self.assertEqual(self.builds[0].name, 'project-merge')
1893
1894 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1895 self.waitUntilSettled()
1896
James E. Blair08d19992016-08-10 15:25:31 -07001897 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001898 self.waitUntilSettled()
1899
1900 self.assertEqual(len(self.builds), 0, "No job running")
Antoine Mussobd86a312014-01-08 14:51:33 +01001901 self.assertEqual(len(self.history), 1, "Only one build in history")
1902 self.assertEqual(self.history[0].result, 'ABORTED',
James E. Blairba437362015-02-07 11:41:52 -08001903 "Build should have been aborted")
1904 self.assertEqual(A.reported, 1,
1905 "Abandoned gate change should report only start")
1906
James E. Blairec056492016-07-22 09:45:56 -07001907 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001908 def test_abandoned_check(self):
1909 "Test that an abandoned change is dequeued from check"
1910
James E. Blair08d19992016-08-10 15:25:31 -07001911 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001912
1913 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1914 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1915 check_pipeline = self.sched.layout.pipelines['check']
1916
1917 # Add two git-dependent changes
1918 B.setDependsOn(A, 1)
1919 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1920 self.waitUntilSettled()
1921 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1922 self.waitUntilSettled()
1923 # A live item, and a non-live/live pair
1924 items = check_pipeline.getAllItems()
1925 self.assertEqual(len(items), 3)
1926
1927 self.assertEqual(items[0].change.number, '1')
1928 self.assertFalse(items[0].live)
1929
1930 self.assertEqual(items[1].change.number, '2')
1931 self.assertTrue(items[1].live)
1932
1933 self.assertEqual(items[2].change.number, '1')
1934 self.assertTrue(items[2].live)
1935
1936 # Abandon A
1937 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1938 self.waitUntilSettled()
1939
1940 # The live copy of A should be gone, but the non-live and B
1941 # should continue
1942 items = check_pipeline.getAllItems()
1943 self.assertEqual(len(items), 2)
1944
1945 self.assertEqual(items[0].change.number, '1')
1946 self.assertFalse(items[0].live)
1947
1948 self.assertEqual(items[1].change.number, '2')
1949 self.assertTrue(items[1].live)
1950
James E. Blair08d19992016-08-10 15:25:31 -07001951 self.launch_server.hold_jobs_in_build = False
1952 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001953 self.waitUntilSettled()
1954
1955 self.assertEqual(len(self.history), 4)
1956 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001957 'Build should have been aborted')
1958 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001959 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001960
James E. Blairec056492016-07-22 09:45:56 -07001961 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001962 def test_abandoned_not_timer(self):
1963 "Test that an abandoned change does not cancel timer jobs"
1964
James E. Blair08d19992016-08-10 15:25:31 -07001965 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001966
1967 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001968 self.updateConfigLayout(
1969 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001970 self.sched.reconfigure(self.config)
1971 self.registerJobs()
1972 # The pipeline triggers every second, so we should have seen
1973 # several by now.
1974 time.sleep(5)
1975 self.waitUntilSettled()
1976 # Stop queuing timer triggered jobs so that the assertions
1977 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001978 self.updateConfigLayout(
1979 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001980 self.sched.reconfigure(self.config)
1981 self.registerJobs()
1982 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1983
1984 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1985 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1986 self.waitUntilSettled()
1987 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1988
1989 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1990 self.waitUntilSettled()
1991
1992 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1993
James E. Blair08d19992016-08-10 15:25:31 -07001994 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001995 self.waitUntilSettled()
1996
James E. Blairec056492016-07-22 09:45:56 -07001997 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001998 def test_zuul_url_return(self):
1999 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08002000 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07002001 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02002002
2003 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002004 A.addApproval('code-review', 2)
2005 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02002006 self.waitUntilSettled()
2007
2008 self.assertEqual(len(self.builds), 1)
2009 for build in self.builds:
2010 self.assertTrue('ZUUL_URL' in build.parameters)
2011
James E. Blair08d19992016-08-10 15:25:31 -07002012 self.launch_server.hold_jobs_in_build = False
2013 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02002014 self.waitUntilSettled()
2015
James E. Blairec056492016-07-22 09:45:56 -07002016 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002017 def test_new_patchset_dequeues_old_on_head(self):
2018 "Test that a new patchset causes the old to be dequeued (at head)"
2019 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07002020 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002021 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
2022 M.setMerged()
2023 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2024 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2025 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2026 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002027 A.addApproval('code-review', 2)
2028 B.addApproval('code-review', 2)
2029 C.addApproval('code-review', 2)
2030 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002031
2032 C.setDependsOn(B, 1)
2033 B.setDependsOn(A, 1)
2034 A.setDependsOn(M, 1)
2035
James E. Blair8b5408c2016-08-08 15:37:46 -07002036 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2037 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2038 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2039 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002040 self.waitUntilSettled()
2041
2042 A.addPatchset()
2043 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2044 self.waitUntilSettled()
2045
James E. Blair08d19992016-08-10 15:25:31 -07002046 self.launch_server.hold_jobs_in_build = False
2047 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002048 self.waitUntilSettled()
2049
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002050 self.assertEqual(A.data['status'], 'NEW')
2051 self.assertEqual(A.reported, 2)
2052 self.assertEqual(B.data['status'], 'NEW')
2053 self.assertEqual(B.reported, 2)
2054 self.assertEqual(C.data['status'], 'NEW')
2055 self.assertEqual(C.reported, 2)
2056 self.assertEqual(D.data['status'], 'MERGED')
2057 self.assertEqual(D.reported, 2)
2058 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08002059
James E. Blairec056492016-07-22 09:45:56 -07002060 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002061 def test_new_patchset_dequeues_old_without_dependents(self):
2062 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07002063 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002064 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2065 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2066 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07002067 A.addApproval('code-review', 2)
2068 B.addApproval('code-review', 2)
2069 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08002070
James E. Blair8b5408c2016-08-08 15:37:46 -07002071 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2072 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2073 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08002074 self.waitUntilSettled()
2075
2076 B.addPatchset()
2077 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2078 self.waitUntilSettled()
2079
James E. Blair08d19992016-08-10 15:25:31 -07002080 self.launch_server.hold_jobs_in_build = False
2081 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002082 self.waitUntilSettled()
2083
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002084 self.assertEqual(A.data['status'], 'MERGED')
2085 self.assertEqual(A.reported, 2)
2086 self.assertEqual(B.data['status'], 'NEW')
2087 self.assertEqual(B.reported, 2)
2088 self.assertEqual(C.data['status'], 'MERGED')
2089 self.assertEqual(C.reported, 2)
2090 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002091
James E. Blairec056492016-07-22 09:45:56 -07002092 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002093 def test_new_patchset_dequeues_old_independent_queue(self):
2094 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002095 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002096 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2097 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2098 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2099 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2100 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2101 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2102 self.waitUntilSettled()
2103
2104 B.addPatchset()
2105 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2106 self.waitUntilSettled()
2107
James E. Blair08d19992016-08-10 15:25:31 -07002108 self.launch_server.hold_jobs_in_build = False
2109 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002110 self.waitUntilSettled()
2111
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002112 self.assertEqual(A.data['status'], 'NEW')
2113 self.assertEqual(A.reported, 1)
2114 self.assertEqual(B.data['status'], 'NEW')
2115 self.assertEqual(B.reported, 1)
2116 self.assertEqual(C.data['status'], 'NEW')
2117 self.assertEqual(C.reported, 1)
2118 self.assertEqual(len(self.history), 10)
2119 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002120
James E. Blairec056492016-07-22 09:45:56 -07002121 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002122 def test_noop_job(self):
2123 "Test that the internal noop job works"
2124 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002125 A.addApproval('code-review', 2)
2126 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002127 self.waitUntilSettled()
2128
2129 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2130 self.assertTrue(self.sched._areAllBuildsComplete())
2131 self.assertEqual(len(self.history), 0)
2132 self.assertEqual(A.data['status'], 'MERGED')
2133 self.assertEqual(A.reported, 2)
2134
James E. Blairec056492016-07-22 09:45:56 -07002135 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002136 def test_no_job_project(self):
2137 "Test that reports with no jobs don't get sent"
2138 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2139 'master', 'A')
2140 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2141 self.waitUntilSettled()
2142
2143 # Change wasn't reported to
2144 self.assertEqual(A.reported, False)
2145
2146 # Check queue is empty afterwards
2147 check_pipeline = self.sched.layout.pipelines['check']
2148 items = check_pipeline.getAllItems()
2149 self.assertEqual(len(items), 0)
2150
2151 self.assertEqual(len(self.history), 0)
2152
James E. Blairec056492016-07-22 09:45:56 -07002153 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002154 def test_zuul_refs(self):
2155 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002156 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002157 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2158 M1.setMerged()
2159 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2160 M2.setMerged()
2161
2162 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2163 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2164 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2165 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002166 A.addApproval('code-review', 2)
2167 B.addApproval('code-review', 2)
2168 C.addApproval('code-review', 2)
2169 D.addApproval('code-review', 2)
2170 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2171 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2172 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2173 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002174
2175 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002176 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002177 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002178 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002179 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002180 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002181 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002182 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002183 self.waitUntilSettled()
2184
James E. Blair7d0dedc2013-02-21 17:26:09 -08002185 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002186 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002187 if x.parameters['ZUUL_CHANGE'] == '3':
2188 a_zref = x.parameters['ZUUL_REF']
2189 if x.parameters['ZUUL_CHANGE'] == '4':
2190 b_zref = x.parameters['ZUUL_REF']
2191 if x.parameters['ZUUL_CHANGE'] == '5':
2192 c_zref = x.parameters['ZUUL_REF']
2193 if x.parameters['ZUUL_CHANGE'] == '6':
2194 d_zref = x.parameters['ZUUL_REF']
2195
2196 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002197 self.assertIsNotNone(a_zref)
2198 self.assertIsNotNone(b_zref)
2199 self.assertIsNotNone(c_zref)
2200 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002201
2202 # And they should all be different
2203 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002204 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002205
2206 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002207 self.assertTrue(self.ref_has_change(a_zref, A))
2208 self.assertFalse(self.ref_has_change(a_zref, B))
2209 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002210
2211 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002212 self.assertTrue(self.ref_has_change(b_zref, A))
2213 self.assertTrue(self.ref_has_change(b_zref, B))
2214 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002215
2216 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002217 self.assertTrue(self.ref_has_change(c_zref, A))
2218 self.assertTrue(self.ref_has_change(c_zref, B))
2219 self.assertTrue(self.ref_has_change(c_zref, C))
2220 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002221
2222 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002223 self.assertTrue(self.ref_has_change(d_zref, A))
2224 self.assertTrue(self.ref_has_change(d_zref, B))
2225 self.assertTrue(self.ref_has_change(d_zref, C))
2226 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002227
James E. Blair08d19992016-08-10 15:25:31 -07002228 self.launch_server.hold_jobs_in_build = False
2229 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002230 self.waitUntilSettled()
2231
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002232 self.assertEqual(A.data['status'], 'MERGED')
2233 self.assertEqual(A.reported, 2)
2234 self.assertEqual(B.data['status'], 'MERGED')
2235 self.assertEqual(B.reported, 2)
2236 self.assertEqual(C.data['status'], 'MERGED')
2237 self.assertEqual(C.reported, 2)
2238 self.assertEqual(D.data['status'], 'MERGED')
2239 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002240
James E. Blairec056492016-07-22 09:45:56 -07002241 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002242 def test_rerun_on_error(self):
2243 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002244 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002245 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002246 A.addApproval('code-review', 2)
2247 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002248 self.waitUntilSettled()
2249
2250 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002251 self.launch_server.hold_jobs_in_build = False
2252 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002253 self.waitUntilSettled()
2254 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2255 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2256
James E. Blairec056492016-07-22 09:45:56 -07002257 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002258 def test_statsd(self):
2259 "Test each of the statsd methods used in the scheduler"
2260 import extras
2261 statsd = extras.try_import('statsd.statsd')
2262 statsd.incr('test-incr')
2263 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002264 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002265 self.assertReportedStat('test-incr', '1|c')
2266 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002267 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002268
James E. Blairec056492016-07-22 09:45:56 -07002269 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002270 def test_stuck_job_cleanup(self):
2271 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002272 # This job won't be registered at startup because it is not in
2273 # the standard layout, but we need it to already be registerd
2274 # for when we reconfigure, as that is when Zuul will attempt
2275 # to run the new job.
2276 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002277 self.gearman_server.hold_jobs_in_queue = True
2278 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002279 A.addApproval('code-review', 2)
2280 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002281 self.waitUntilSettled()
2282 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2283
James E. Blairf84026c2015-12-08 16:11:46 -08002284 self.updateConfigLayout(
2285 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002286 self.sched.reconfigure(self.config)
2287 self.waitUntilSettled()
2288
James E. Blair18c64442014-03-18 10:14:45 -07002289 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002290 self.waitUntilSettled()
2291 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2292 self.assertTrue(self.sched._areAllBuildsComplete())
2293
2294 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002295 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002296 self.assertEqual(self.history[0].result, 'SUCCESS')
2297
James E. Blairec056492016-07-22 09:45:56 -07002298 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002299 def test_file_head(self):
2300 # This is a regression test for an observed bug. A change
2301 # with a file named "HEAD" in the root directory of the repo
2302 # was processed by a merger. It then was unable to reset the
2303 # repo because of:
2304 # GitCommandError: 'git reset --hard HEAD' returned
2305 # with exit code 128
2306 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2307 # and filename
2308 # Use '--' to separate filenames from revisions'
2309
2310 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2311 A.addPatchset(['HEAD'])
2312 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2313
2314 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2315 self.waitUntilSettled()
2316
2317 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2318 self.waitUntilSettled()
2319
2320 self.assertIn('Build succeeded', A.messages[0])
2321 self.assertIn('Build succeeded', B.messages[0])
2322
James E. Blairec056492016-07-22 09:45:56 -07002323 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002324 def test_file_jobs(self):
2325 "Test that file jobs run only when appropriate"
2326 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2327 A.addPatchset(['pip-requires'])
2328 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002329 A.addApproval('code-review', 2)
2330 B.addApproval('code-review', 2)
2331 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2332 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002333 self.waitUntilSettled()
2334
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002335 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002336 if x.name == 'project-testfile']
2337
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002338 self.assertEqual(len(testfile_jobs), 1)
2339 self.assertEqual(testfile_jobs[0].changes, '1,2')
2340 self.assertEqual(A.data['status'], 'MERGED')
2341 self.assertEqual(A.reported, 2)
2342 self.assertEqual(B.data['status'], 'MERGED')
2343 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002344
James E. Blairec056492016-07-22 09:45:56 -07002345 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002346 def _test_skip_if_jobs(self, branch, should_skip):
2347 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002348 self.updateConfigLayout(
2349 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002350 self.sched.reconfigure(self.config)
2351 self.registerJobs()
2352
2353 change = self.fake_gerrit.addFakeChange('org/project',
2354 branch,
2355 'test skip-if')
2356 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2357 self.waitUntilSettled()
2358
2359 tested_change_ids = [x.changes[0] for x in self.history
2360 if x.name == 'project-test-skip-if']
2361
2362 if should_skip:
2363 self.assertEqual([], tested_change_ids)
2364 else:
2365 self.assertIn(change.data['number'], tested_change_ids)
2366
James E. Blairec056492016-07-22 09:45:56 -07002367 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002368 def test_skip_if_match_skips_job(self):
2369 self._test_skip_if_jobs(branch='master', should_skip=True)
2370
James E. Blairec056492016-07-22 09:45:56 -07002371 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002372 def test_skip_if_no_match_runs_job(self):
2373 self._test_skip_if_jobs(branch='mp', should_skip=False)
2374
James E. Blairec056492016-07-22 09:45:56 -07002375 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002376 def test_test_config(self):
2377 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002378 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002379 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002380
James E. Blairec056492016-07-22 09:45:56 -07002381 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002382 def test_queue_names(self):
2383 "Test shared change queue names"
2384 project1 = self.sched.layout.projects['org/project1']
2385 project2 = self.sched.layout.projects['org/project2']
2386 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2387 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2388 self.assertEqual(q1.name, 'integration')
2389 self.assertEqual(q2.name, 'integration')
2390
James E. Blairf84026c2015-12-08 16:11:46 -08002391 self.updateConfigLayout(
2392 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002393 with testtools.ExpectedException(
2394 Exception, "More than one name assigned to change queue"):
2395 self.sched.reconfigure(self.config)
2396
James E. Blairec056492016-07-22 09:45:56 -07002397 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002398 def test_queue_precedence(self):
2399 "Test that queue precedence works"
2400
2401 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002402 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002403 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2404 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002405 A.addApproval('code-review', 2)
2406 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002407
2408 self.waitUntilSettled()
2409 self.gearman_server.hold_jobs_in_queue = False
2410 self.gearman_server.release()
2411 self.waitUntilSettled()
2412
James E. Blair8de58bd2013-07-18 16:23:33 -07002413 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002414 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002415 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002416 self.waitUntilSettled()
2417
James E. Blair64ed6f22013-07-10 14:07:23 -07002418 self.log.debug(self.history)
2419 self.assertEqual(self.history[0].pipeline, 'gate')
2420 self.assertEqual(self.history[1].pipeline, 'check')
2421 self.assertEqual(self.history[2].pipeline, 'gate')
2422 self.assertEqual(self.history[3].pipeline, 'gate')
2423 self.assertEqual(self.history[4].pipeline, 'check')
2424 self.assertEqual(self.history[5].pipeline, 'check')
2425
James E. Blairec056492016-07-22 09:45:56 -07002426 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002427 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002428 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002429 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002430 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002431 A.addApproval('code-review', 2)
2432 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002433 self.waitUntilSettled()
2434
James E. Blair08d19992016-08-10 15:25:31 -07002435 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002436 self.waitUntilSettled()
2437
James E. Blair1843a552013-07-03 14:19:52 -07002438 port = self.webapp.server.socket.getsockname()[1]
2439
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002440 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2441 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002442 headers = f.info()
2443 self.assertIn('Content-Length', headers)
2444 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002445 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2446 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002447 self.assertIn('Access-Control-Allow-Origin', headers)
2448 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002449 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002450 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002451 data = f.read()
2452
James E. Blair08d19992016-08-10 15:25:31 -07002453 self.launch_server.hold_jobs_in_build = False
2454 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002455 self.waitUntilSettled()
2456
2457 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002458 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002459 for p in data['pipelines']:
2460 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002461 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002462 self.assertEqual(q['window'], 20)
2463 else:
2464 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002465 for head in q['heads']:
2466 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002467 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002468 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002469 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002470 status_jobs.append(job)
2471 self.assertEqual('project-merge', status_jobs[0]['name'])
2472 self.assertEqual('https://server/job/project-merge/0/',
2473 status_jobs[0]['url'])
2474 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2475 status_jobs[0]['report_url'])
2476
2477 self.assertEqual('project-test1', status_jobs[1]['name'])
2478 self.assertEqual('https://server/job/project-test1/1/',
2479 status_jobs[1]['url'])
2480 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2481 status_jobs[1]['report_url'])
2482
2483 self.assertEqual('project-test2', status_jobs[2]['name'])
2484 self.assertEqual('https://server/job/project-test2/2/',
2485 status_jobs[2]['url'])
2486 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2487 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002488
James E. Blairec056492016-07-22 09:45:56 -07002489 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002490 def test_merging_queues(self):
2491 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002492 self.updateConfigLayout(
2493 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002494 self.sched.reconfigure(self.config)
2495 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2496
James E. Blairec056492016-07-22 09:45:56 -07002497 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002498 def test_mutex(self):
2499 "Test job mutexes"
2500 self.config.set('zuul', 'layout_config',
2501 'tests/fixtures/layout-mutex.yaml')
2502 self.sched.reconfigure(self.config)
2503
James E. Blair08d19992016-08-10 15:25:31 -07002504 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002505 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2506 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2507 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2508
2509 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2510 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2511 self.waitUntilSettled()
2512 self.assertEqual(len(self.builds), 3)
2513 self.assertEqual(self.builds[0].name, 'project-test1')
2514 self.assertEqual(self.builds[1].name, 'mutex-one')
2515 self.assertEqual(self.builds[2].name, 'project-test1')
2516
James E. Blair08d19992016-08-10 15:25:31 -07002517 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002518 self.waitUntilSettled()
2519
2520 self.assertEqual(len(self.builds), 3)
2521 self.assertEqual(self.builds[0].name, 'project-test1')
2522 self.assertEqual(self.builds[1].name, 'project-test1')
2523 self.assertEqual(self.builds[2].name, 'mutex-two')
2524 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2525
James E. Blair08d19992016-08-10 15:25:31 -07002526 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002527 self.waitUntilSettled()
2528
2529 self.assertEqual(len(self.builds), 3)
2530 self.assertEqual(self.builds[0].name, 'project-test1')
2531 self.assertEqual(self.builds[1].name, 'project-test1')
2532 self.assertEqual(self.builds[2].name, 'mutex-one')
2533 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2534
James E. Blair08d19992016-08-10 15:25:31 -07002535 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002536 self.waitUntilSettled()
2537
2538 self.assertEqual(len(self.builds), 3)
2539 self.assertEqual(self.builds[0].name, 'project-test1')
2540 self.assertEqual(self.builds[1].name, 'project-test1')
2541 self.assertEqual(self.builds[2].name, 'mutex-two')
2542 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2543
James E. Blair08d19992016-08-10 15:25:31 -07002544 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002545 self.waitUntilSettled()
2546
2547 self.assertEqual(len(self.builds), 2)
2548 self.assertEqual(self.builds[0].name, 'project-test1')
2549 self.assertEqual(self.builds[1].name, 'project-test1')
2550 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2551
James E. Blair08d19992016-08-10 15:25:31 -07002552 self.launch_server.hold_jobs_in_build = False
2553 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002554
2555 self.waitUntilSettled()
2556 self.assertEqual(len(self.builds), 0)
2557
2558 self.assertEqual(A.reported, 1)
2559 self.assertEqual(B.reported, 1)
2560 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2561
James E. Blairec056492016-07-22 09:45:56 -07002562 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002563 def test_node_label(self):
2564 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002565 self.worker.registerFunction('build:node-project-test1:debian')
2566
2567 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002568 A.addApproval('code-review', 2)
2569 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002570 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002571
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002572 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2573 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2574 'debian')
2575 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002576
James E. Blairec056492016-07-22 09:45:56 -07002577 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002578 def test_live_reconfiguration(self):
2579 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002580 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002581 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002582 A.addApproval('code-review', 2)
2583 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002584 self.waitUntilSettled()
2585
2586 self.sched.reconfigure(self.config)
2587
James E. Blair08d19992016-08-10 15:25:31 -07002588 self.launch_server.hold_jobs_in_build = False
2589 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002590 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002591 self.assertEqual(self.getJobFromHistory('project-merge').result,
2592 'SUCCESS')
2593 self.assertEqual(self.getJobFromHistory('project-test1').result,
2594 'SUCCESS')
2595 self.assertEqual(self.getJobFromHistory('project-test2').result,
2596 'SUCCESS')
2597 self.assertEqual(A.data['status'], 'MERGED')
2598 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002599
James E. Blairec056492016-07-22 09:45:56 -07002600 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002601 def test_live_reconfiguration_merge_conflict(self):
2602 # A real-world bug: a change in a gate queue has a merge
2603 # conflict and a job is added to its project while it's
2604 # sitting in the queue. The job gets added to the change and
2605 # enqueued and the change gets stuck.
2606 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002607 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002608
2609 # This change is fine. It's here to stop the queue long
2610 # enough for the next change to be subject to the
2611 # reconfiguration, as well as to provide a conflict for the
2612 # next change. This change will succeed and merge.
2613 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2614 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002615 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002616
2617 # This change will be in merge conflict. During the
2618 # reconfiguration, we will add a job. We want to make sure
2619 # that doesn't cause it to get stuck.
2620 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2621 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002622 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002623
James E. Blair8b5408c2016-08-08 15:37:46 -07002624 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2625 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002626
2627 self.waitUntilSettled()
2628
2629 # No jobs have run yet
2630 self.assertEqual(A.data['status'], 'NEW')
2631 self.assertEqual(A.reported, 1)
2632 self.assertEqual(B.data['status'], 'NEW')
2633 self.assertEqual(B.reported, 1)
2634 self.assertEqual(len(self.history), 0)
2635
2636 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002637 self.updateConfigLayout(
2638 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002639 self.sched.reconfigure(self.config)
2640 self.waitUntilSettled()
2641
James E. Blair08d19992016-08-10 15:25:31 -07002642 self.launch_server.hold_jobs_in_build = False
2643 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002644 self.waitUntilSettled()
2645
2646 self.assertEqual(A.data['status'], 'MERGED')
2647 self.assertEqual(A.reported, 2)
2648 self.assertEqual(B.data['status'], 'NEW')
2649 self.assertEqual(B.reported, 2)
2650 self.assertEqual(self.getJobFromHistory('project-merge').result,
2651 'SUCCESS')
2652 self.assertEqual(self.getJobFromHistory('project-test1').result,
2653 'SUCCESS')
2654 self.assertEqual(self.getJobFromHistory('project-test2').result,
2655 'SUCCESS')
2656 self.assertEqual(self.getJobFromHistory('project-test3').result,
2657 'SUCCESS')
2658 self.assertEqual(len(self.history), 4)
2659
James E. Blairec056492016-07-22 09:45:56 -07002660 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002661 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002662 # An extrapolation of test_live_reconfiguration_merge_conflict
2663 # that tests a job added to a job tree with a failed root does
2664 # not run.
2665 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002666 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002667
2668 # This change is fine. It's here to stop the queue long
2669 # enough for the next change to be subject to the
2670 # reconfiguration. This change will succeed and merge.
2671 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2672 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002673 A.addApproval('code-review', 2)
2674 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002675 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002676 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002677 self.waitUntilSettled()
2678
2679 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002680 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002681 B.addApproval('code-review', 2)
2682 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002683 self.waitUntilSettled()
2684
James E. Blair08d19992016-08-10 15:25:31 -07002685 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002686 self.waitUntilSettled()
2687
2688 # Both -merge jobs have run, but no others.
2689 self.assertEqual(A.data['status'], 'NEW')
2690 self.assertEqual(A.reported, 1)
2691 self.assertEqual(B.data['status'], 'NEW')
2692 self.assertEqual(B.reported, 1)
2693 self.assertEqual(self.history[0].result, 'SUCCESS')
2694 self.assertEqual(self.history[0].name, 'project-merge')
2695 self.assertEqual(self.history[1].result, 'FAILURE')
2696 self.assertEqual(self.history[1].name, 'project-merge')
2697 self.assertEqual(len(self.history), 2)
2698
2699 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002700 self.updateConfigLayout(
2701 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002702 self.sched.reconfigure(self.config)
2703 self.waitUntilSettled()
2704
James E. Blair08d19992016-08-10 15:25:31 -07002705 self.launch_server.hold_jobs_in_build = False
2706 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002707 self.waitUntilSettled()
2708
2709 self.assertEqual(A.data['status'], 'MERGED')
2710 self.assertEqual(A.reported, 2)
2711 self.assertEqual(B.data['status'], 'NEW')
2712 self.assertEqual(B.reported, 2)
2713 self.assertEqual(self.history[0].result, 'SUCCESS')
2714 self.assertEqual(self.history[0].name, 'project-merge')
2715 self.assertEqual(self.history[1].result, 'FAILURE')
2716 self.assertEqual(self.history[1].name, 'project-merge')
2717 self.assertEqual(self.history[2].result, 'SUCCESS')
2718 self.assertEqual(self.history[3].result, 'SUCCESS')
2719 self.assertEqual(self.history[4].result, 'SUCCESS')
2720 self.assertEqual(len(self.history), 5)
2721
James E. Blairec056492016-07-22 09:45:56 -07002722 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002723 def test_live_reconfiguration_failed_job(self):
2724 # Test that a change with a removed failing job does not
2725 # disrupt reconfiguration. If a change has a failed job and
2726 # that job is removed during a reconfiguration, we observed a
2727 # bug where the code to re-set build statuses would run on
2728 # that build and raise an exception because the job no longer
2729 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002730 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002731
2732 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2733
2734 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002735 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002736
2737 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2738 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002739 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002740 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002741 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002742 self.waitUntilSettled()
2743
2744 self.assertEqual(A.data['status'], 'NEW')
2745 self.assertEqual(A.reported, 0)
2746
2747 self.assertEqual(self.getJobFromHistory('project-merge').result,
2748 'SUCCESS')
2749 self.assertEqual(self.getJobFromHistory('project-test1').result,
2750 'FAILURE')
2751 self.assertEqual(len(self.history), 2)
2752
2753 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002754 self.updateConfigLayout(
2755 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002756 self.sched.reconfigure(self.config)
2757 self.waitUntilSettled()
2758
James E. Blair08d19992016-08-10 15:25:31 -07002759 self.launch_server.hold_jobs_in_build = False
2760 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002761 self.waitUntilSettled()
2762
2763 self.assertEqual(self.getJobFromHistory('project-test2').result,
2764 'SUCCESS')
2765 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2766 'SUCCESS')
2767 self.assertEqual(len(self.history), 4)
2768
2769 self.assertEqual(A.data['status'], 'NEW')
2770 self.assertEqual(A.reported, 1)
2771 self.assertIn('Build succeeded', A.messages[0])
2772 # Ensure the removed job was not included in the report.
2773 self.assertNotIn('project-test1', A.messages[0])
2774
James E. Blairec056492016-07-22 09:45:56 -07002775 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002776 def test_live_reconfiguration_shared_queue(self):
2777 # Test that a change with a failing job which was removed from
2778 # this project but otherwise still exists in the system does
2779 # not disrupt reconfiguration.
2780
James E. Blair08d19992016-08-10 15:25:31 -07002781 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002782
2783 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2784
James E. Blair08d19992016-08-10 15:25:31 -07002785 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002786
2787 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2788 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002789 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002790 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002791 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002792 self.waitUntilSettled()
2793
2794 self.assertEqual(A.data['status'], 'NEW')
2795 self.assertEqual(A.reported, 0)
2796
2797 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2798 'SUCCESS')
2799 self.assertEqual(self.getJobFromHistory(
2800 'project1-project2-integration').result, 'FAILURE')
2801 self.assertEqual(len(self.history), 2)
2802
2803 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002804 self.updateConfigLayout(
2805 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002806 self.sched.reconfigure(self.config)
2807 self.waitUntilSettled()
2808
James E. Blair08d19992016-08-10 15:25:31 -07002809 self.launch_server.hold_jobs_in_build = False
2810 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002811 self.waitUntilSettled()
2812
2813 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2814 'SUCCESS')
2815 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2816 'SUCCESS')
2817 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2818 'SUCCESS')
2819 self.assertEqual(self.getJobFromHistory(
2820 'project1-project2-integration').result, 'FAILURE')
2821 self.assertEqual(len(self.history), 4)
2822
2823 self.assertEqual(A.data['status'], 'NEW')
2824 self.assertEqual(A.reported, 1)
2825 self.assertIn('Build succeeded', A.messages[0])
2826 # Ensure the removed job was not included in the report.
2827 self.assertNotIn('project1-project2-integration', A.messages[0])
2828
James E. Blairec056492016-07-22 09:45:56 -07002829 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002830 def test_double_live_reconfiguration_shared_queue(self):
2831 # This was a real-world regression. A change is added to
2832 # gate; a reconfigure happens, a second change which depends
2833 # on the first is added, and a second reconfiguration happens.
2834 # Ensure that both changes merge.
2835
2836 # A failure may indicate incorrect caching or cleaning up of
2837 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002838 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002839
2840 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2841 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2842 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002843 A.addApproval('code-review', 2)
2844 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002845
2846 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002847 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002848 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002849 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002850 self.waitUntilSettled()
2851
2852 # Reconfigure (with only one change in the pipeline).
2853 self.sched.reconfigure(self.config)
2854 self.waitUntilSettled()
2855
2856 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002857 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002858 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002859 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002860 self.waitUntilSettled()
2861
2862 # Reconfigure (with both in the pipeline).
2863 self.sched.reconfigure(self.config)
2864 self.waitUntilSettled()
2865
James E. Blair08d19992016-08-10 15:25:31 -07002866 self.launch_server.hold_jobs_in_build = False
2867 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002868 self.waitUntilSettled()
2869
2870 self.assertEqual(len(self.history), 8)
2871
2872 self.assertEqual(A.data['status'], 'MERGED')
2873 self.assertEqual(A.reported, 2)
2874 self.assertEqual(B.data['status'], 'MERGED')
2875 self.assertEqual(B.reported, 2)
2876
James E. Blairec056492016-07-22 09:45:56 -07002877 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002878 def test_live_reconfiguration_del_project(self):
2879 # Test project deletion from layout
2880 # while changes are enqueued
2881
James E. Blair08d19992016-08-10 15:25:31 -07002882 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002883 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2884 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2885 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2886
2887 # A Depends-On: B
2888 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2889 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002890 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002891
2892 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2893 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2894 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002895 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002896 self.waitUntilSettled()
2897 self.assertEqual(len(self.builds), 5)
2898
2899 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002900 self.updateConfigLayout(
2901 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002902 self.sched.reconfigure(self.config)
2903 self.waitUntilSettled()
2904
2905 # Builds for C aborted, builds for A succeed,
2906 # and have change B applied ahead
2907 job_c = self.getJobFromHistory('project1-test1')
2908 self.assertEqual(job_c.changes, '3,1')
2909 self.assertEqual(job_c.result, 'ABORTED')
2910
James E. Blair08d19992016-08-10 15:25:31 -07002911 self.launch_server.hold_jobs_in_build = False
2912 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002913 self.waitUntilSettled()
2914
2915 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2916 '2,1 1,1')
2917
2918 self.assertEqual(A.data['status'], 'NEW')
2919 self.assertEqual(B.data['status'], 'NEW')
2920 self.assertEqual(C.data['status'], 'NEW')
2921 self.assertEqual(A.reported, 1)
2922 self.assertEqual(B.reported, 0)
2923 self.assertEqual(C.reported, 0)
2924
2925 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2926 self.assertIn('Build succeeded', A.messages[0])
2927
James E. Blairec056492016-07-22 09:45:56 -07002928 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002929 def test_live_reconfiguration_functions(self):
2930 "Test live reconfiguration with a custom function"
2931 self.worker.registerFunction('build:node-project-test1:debian')
2932 self.worker.registerFunction('build:node-project-test1:wheezy')
2933 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002934 A.addApproval('code-review', 2)
2935 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002936 self.waitUntilSettled()
2937
2938 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2939 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2940 'debian')
2941 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2942
James E. Blairf84026c2015-12-08 16:11:46 -08002943 self.updateConfigLayout(
2944 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002945 self.sched.reconfigure(self.config)
2946 self.worker.build_history = []
2947
2948 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002949 B.addApproval('code-review', 2)
2950 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002951 self.waitUntilSettled()
2952
2953 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2954 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2955 'wheezy')
2956 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2957
James E. Blairec056492016-07-22 09:45:56 -07002958 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002959 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002960 self.updateConfigLayout(
2961 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002962 self.sched.reconfigure(self.config)
2963
2964 self.init_repo("org/new-project")
2965 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2966
James E. Blair8b5408c2016-08-08 15:37:46 -07002967 A.addApproval('code-review', 2)
2968 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002969 self.waitUntilSettled()
2970 self.assertEqual(self.getJobFromHistory('project-merge').result,
2971 'SUCCESS')
2972 self.assertEqual(self.getJobFromHistory('project-test1').result,
2973 'SUCCESS')
2974 self.assertEqual(self.getJobFromHistory('project-test2').result,
2975 'SUCCESS')
2976 self.assertEqual(A.data['status'], 'MERGED')
2977 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002978
James E. Blairec056492016-07-22 09:45:56 -07002979 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002980 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002981 self.updateConfigLayout(
2982 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002983 self.sched.reconfigure(self.config)
2984
2985 self.init_repo("org/delete-project")
2986 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2987
James E. Blair8b5408c2016-08-08 15:37:46 -07002988 A.addApproval('code-review', 2)
2989 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002990 self.waitUntilSettled()
2991 self.assertEqual(self.getJobFromHistory('project-merge').result,
2992 'SUCCESS')
2993 self.assertEqual(self.getJobFromHistory('project-test1').result,
2994 'SUCCESS')
2995 self.assertEqual(self.getJobFromHistory('project-test2').result,
2996 'SUCCESS')
2997 self.assertEqual(A.data['status'], 'MERGED')
2998 self.assertEqual(A.reported, 2)
2999
3000 # Delete org/new-project zuul repo. Should be recloned.
3001 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
3002
3003 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
3004
James E. Blair8b5408c2016-08-08 15:37:46 -07003005 B.addApproval('code-review', 2)
3006 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07003007 self.waitUntilSettled()
3008 self.assertEqual(self.getJobFromHistory('project-merge').result,
3009 'SUCCESS')
3010 self.assertEqual(self.getJobFromHistory('project-test1').result,
3011 'SUCCESS')
3012 self.assertEqual(self.getJobFromHistory('project-test2').result,
3013 'SUCCESS')
3014 self.assertEqual(B.data['status'], 'MERGED')
3015 self.assertEqual(B.reported, 2)
3016
James E. Blairec056492016-07-22 09:45:56 -07003017 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08003018 def test_tags(self):
3019 "Test job tags"
3020 self.config.set('zuul', 'layout_config',
3021 'tests/fixtures/layout-tags.yaml')
3022 self.sched.reconfigure(self.config)
3023
3024 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3025 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3026 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3027 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
3028 self.waitUntilSettled()
3029
3030 results = {'project1-merge': 'extratag merge project1',
3031 'project2-merge': 'merge'}
3032
3033 for build in self.history:
3034 self.assertEqual(results.get(build.name, ''),
3035 build.parameters.get('BUILD_TAGS'))
3036
James E. Blairec056492016-07-22 09:45:56 -07003037 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07003038 def test_timer(self):
3039 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003040 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003041 self.updateConfigLayout(
3042 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07003043 self.sched.reconfigure(self.config)
3044 self.registerJobs()
3045
Clark Boylan3ee090a2014-04-03 20:55:09 -07003046 # The pipeline triggers every second, so we should have seen
3047 # several by now.
3048 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003049 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003050
3051 self.assertEqual(len(self.builds), 2)
3052
James E. Blair63bb0ef2013-07-29 17:14:51 -07003053 port = self.webapp.server.socket.getsockname()[1]
3054
Morgan Fainberg293f7f82016-05-30 14:01:22 -07003055 req = urllib.request.Request("http://localhost:%s/status.json" % port)
3056 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003057 data = f.read()
3058
James E. Blair08d19992016-08-10 15:25:31 -07003059 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07003060 # Stop queuing timer triggered jobs so that the assertions
3061 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003062 self.updateConfigLayout(
3063 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003064 self.sched.reconfigure(self.config)
3065 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07003066 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07003067 self.waitUntilSettled()
3068
3069 self.assertEqual(self.getJobFromHistory(
3070 'project-bitrot-stable-old').result, 'SUCCESS')
3071 self.assertEqual(self.getJobFromHistory(
3072 'project-bitrot-stable-older').result, 'SUCCESS')
3073
3074 data = json.loads(data)
3075 status_jobs = set()
3076 for p in data['pipelines']:
3077 for q in p['change_queues']:
3078 for head in q['heads']:
3079 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07003080 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07003081 for job in change['jobs']:
3082 status_jobs.add(job['name'])
3083 self.assertIn('project-bitrot-stable-old', status_jobs)
3084 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003085
James E. Blairec056492016-07-22 09:45:56 -07003086 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07003087 def test_idle(self):
3088 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07003089 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07003090
Clark Boylan3ee090a2014-04-03 20:55:09 -07003091 for x in range(1, 3):
3092 # Test that timer triggers periodic jobs even across
3093 # layout config reloads.
3094 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003095 self.updateConfigLayout(
3096 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003097 self.sched.reconfigure(self.config)
3098 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003099 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003100
Clark Boylan3ee090a2014-04-03 20:55:09 -07003101 # The pipeline triggers every second, so we should have seen
3102 # several by now.
3103 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003104
3105 # Stop queuing timer triggered jobs so that the assertions
3106 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003107 self.updateConfigLayout(
3108 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003109 self.sched.reconfigure(self.config)
3110 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003111 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003112
3113 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003114 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003115 self.waitUntilSettled()
3116 self.assertEqual(len(self.builds), 0)
3117 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003118
James E. Blairec056492016-07-22 09:45:56 -07003119 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003120 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003121 self.updateConfigLayout(
3122 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003123 self.sched.reconfigure(self.config)
3124
3125 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3126 self.waitUntilSettled()
3127
3128 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3129 self.waitUntilSettled()
3130
James E. Blairff80a2f2013-12-27 13:24:06 -08003131 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003132
3133 # A.messages only holds what FakeGerrit places in it. Thus we
3134 # work on the knowledge of what the first message should be as
3135 # it is only configured to go to SMTP.
3136
3137 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003138 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003139 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003140 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003141 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003142 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003143
3144 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003145 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003146 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003147 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003148 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003149 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003150
James E. Blairec056492016-07-22 09:45:56 -07003151 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003152 def test_timer_smtp(self):
3153 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003154 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003155 self.updateConfigLayout(
3156 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003157 self.sched.reconfigure(self.config)
3158 self.registerJobs()
3159
Clark Boylan3ee090a2014-04-03 20:55:09 -07003160 # The pipeline triggers every second, so we should have seen
3161 # several by now.
3162 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003163 self.waitUntilSettled()
3164
Clark Boylan3ee090a2014-04-03 20:55:09 -07003165 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003166 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003167 self.waitUntilSettled()
3168 self.assertEqual(len(self.history), 2)
3169
James E. Blaire5910202013-12-27 09:50:31 -08003170 self.assertEqual(self.getJobFromHistory(
3171 'project-bitrot-stable-old').result, 'SUCCESS')
3172 self.assertEqual(self.getJobFromHistory(
3173 'project-bitrot-stable-older').result, 'SUCCESS')
3174
James E. Blairff80a2f2013-12-27 13:24:06 -08003175 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003176
3177 # A.messages only holds what FakeGerrit places in it. Thus we
3178 # work on the knowledge of what the first message should be as
3179 # it is only configured to go to SMTP.
3180
3181 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003182 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003183 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003184 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003185 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003186 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003187
Clark Boylan3ee090a2014-04-03 20:55:09 -07003188 # Stop queuing timer triggered jobs and let any that may have
3189 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003190 self.updateConfigLayout(
3191 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003192 self.sched.reconfigure(self.config)
3193 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003194 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003195 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003196 self.waitUntilSettled()
3197
James E. Blairec056492016-07-22 09:45:56 -07003198 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003199 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003200 "Test that the RPC client can enqueue a change"
3201 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003202 A.addApproval('code-review', 2)
3203 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003204
3205 client = zuul.rpcclient.RPCClient('127.0.0.1',
3206 self.gearman_server.port)
3207 r = client.enqueue(pipeline='gate',
3208 project='org/project',
3209 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003210 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003211 self.waitUntilSettled()
3212 self.assertEqual(self.getJobFromHistory('project-merge').result,
3213 'SUCCESS')
3214 self.assertEqual(self.getJobFromHistory('project-test1').result,
3215 'SUCCESS')
3216 self.assertEqual(self.getJobFromHistory('project-test2').result,
3217 'SUCCESS')
3218 self.assertEqual(A.data['status'], 'MERGED')
3219 self.assertEqual(A.reported, 2)
3220 self.assertEqual(r, True)
3221
James E. Blairec056492016-07-22 09:45:56 -07003222 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003223 def test_client_enqueue_ref(self):
3224 "Test that the RPC client can enqueue a ref"
3225
3226 client = zuul.rpcclient.RPCClient('127.0.0.1',
3227 self.gearman_server.port)
3228 r = client.enqueue_ref(
3229 pipeline='post',
3230 project='org/project',
3231 trigger='gerrit',
3232 ref='master',
3233 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3234 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3235 self.waitUntilSettled()
3236 job_names = [x.name for x in self.history]
3237 self.assertEqual(len(self.history), 1)
3238 self.assertIn('project-post', job_names)
3239 self.assertEqual(r, True)
3240
James E. Blairec056492016-07-22 09:45:56 -07003241 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003242 def test_client_enqueue_negative(self):
3243 "Test that the RPC client returns errors"
3244 client = zuul.rpcclient.RPCClient('127.0.0.1',
3245 self.gearman_server.port)
3246 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3247 "Invalid project"):
3248 r = client.enqueue(pipeline='gate',
3249 project='project-does-not-exist',
3250 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003251 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003252 client.shutdown()
3253 self.assertEqual(r, False)
3254
3255 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3256 "Invalid pipeline"):
3257 r = client.enqueue(pipeline='pipeline-does-not-exist',
3258 project='org/project',
3259 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003260 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003261 client.shutdown()
3262 self.assertEqual(r, False)
3263
3264 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3265 "Invalid trigger"):
3266 r = client.enqueue(pipeline='gate',
3267 project='org/project',
3268 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003269 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003270 client.shutdown()
3271 self.assertEqual(r, False)
3272
3273 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3274 "Invalid change"):
3275 r = client.enqueue(pipeline='gate',
3276 project='org/project',
3277 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003278 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003279 client.shutdown()
3280 self.assertEqual(r, False)
3281
3282 self.waitUntilSettled()
3283 self.assertEqual(len(self.history), 0)
3284 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003285
James E. Blairec056492016-07-22 09:45:56 -07003286 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003287 def test_client_promote(self):
3288 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003289 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003290 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3291 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3292 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003293 A.addApproval('code-review', 2)
3294 B.addApproval('code-review', 2)
3295 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003296
James E. Blair8b5408c2016-08-08 15:37:46 -07003297 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3298 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3299 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003300
3301 self.waitUntilSettled()
3302
Sean Daguef39b9ca2014-01-10 21:34:35 -05003303 items = self.sched.layout.pipelines['gate'].getAllItems()
3304 enqueue_times = {}
3305 for item in items:
3306 enqueue_times[str(item.change)] = item.enqueue_time
3307
James E. Blair36658cf2013-12-06 17:53:48 -08003308 client = zuul.rpcclient.RPCClient('127.0.0.1',
3309 self.gearman_server.port)
3310 r = client.promote(pipeline='gate',
3311 change_ids=['2,1', '3,1'])
3312
Sean Daguef39b9ca2014-01-10 21:34:35 -05003313 # ensure that enqueue times are durable
3314 items = self.sched.layout.pipelines['gate'].getAllItems()
3315 for item in items:
3316 self.assertEqual(
3317 enqueue_times[str(item.change)], item.enqueue_time)
3318
James E. Blair78acec92014-02-06 07:11:32 -08003319 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003320 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003321 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003322 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003323 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003324 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003325 self.waitUntilSettled()
3326
3327 self.assertEqual(len(self.builds), 6)
3328 self.assertEqual(self.builds[0].name, 'project-test1')
3329 self.assertEqual(self.builds[1].name, 'project-test2')
3330 self.assertEqual(self.builds[2].name, 'project-test1')
3331 self.assertEqual(self.builds[3].name, 'project-test2')
3332 self.assertEqual(self.builds[4].name, 'project-test1')
3333 self.assertEqual(self.builds[5].name, 'project-test2')
3334
3335 self.assertTrue(self.job_has_changes(self.builds[0], B))
3336 self.assertFalse(self.job_has_changes(self.builds[0], A))
3337 self.assertFalse(self.job_has_changes(self.builds[0], C))
3338
3339 self.assertTrue(self.job_has_changes(self.builds[2], B))
3340 self.assertTrue(self.job_has_changes(self.builds[2], C))
3341 self.assertFalse(self.job_has_changes(self.builds[2], A))
3342
3343 self.assertTrue(self.job_has_changes(self.builds[4], B))
3344 self.assertTrue(self.job_has_changes(self.builds[4], C))
3345 self.assertTrue(self.job_has_changes(self.builds[4], A))
3346
James E. Blair08d19992016-08-10 15:25:31 -07003347 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003348 self.waitUntilSettled()
3349
3350 self.assertEqual(A.data['status'], 'MERGED')
3351 self.assertEqual(A.reported, 2)
3352 self.assertEqual(B.data['status'], 'MERGED')
3353 self.assertEqual(B.reported, 2)
3354 self.assertEqual(C.data['status'], 'MERGED')
3355 self.assertEqual(C.reported, 2)
3356
3357 client.shutdown()
3358 self.assertEqual(r, True)
3359
James E. Blairec056492016-07-22 09:45:56 -07003360 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003361 def test_client_promote_dependent(self):
3362 "Test that the RPC client can promote a dependent change"
3363 # C (depends on B) -> B -> A ; then promote C to get:
3364 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003365 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003366 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3367 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3368 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3369
3370 C.setDependsOn(B, 1)
3371
James E. Blair8b5408c2016-08-08 15:37:46 -07003372 A.addApproval('code-review', 2)
3373 B.addApproval('code-review', 2)
3374 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003375
James E. Blair8b5408c2016-08-08 15:37:46 -07003376 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3377 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3378 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003379
3380 self.waitUntilSettled()
3381
3382 client = zuul.rpcclient.RPCClient('127.0.0.1',
3383 self.gearman_server.port)
3384 r = client.promote(pipeline='gate',
3385 change_ids=['3,1'])
3386
James E. Blair78acec92014-02-06 07:11:32 -08003387 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003388 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003389 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003390 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003391 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003392 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003393 self.waitUntilSettled()
3394
3395 self.assertEqual(len(self.builds), 6)
3396 self.assertEqual(self.builds[0].name, 'project-test1')
3397 self.assertEqual(self.builds[1].name, 'project-test2')
3398 self.assertEqual(self.builds[2].name, 'project-test1')
3399 self.assertEqual(self.builds[3].name, 'project-test2')
3400 self.assertEqual(self.builds[4].name, 'project-test1')
3401 self.assertEqual(self.builds[5].name, 'project-test2')
3402
3403 self.assertTrue(self.job_has_changes(self.builds[0], B))
3404 self.assertFalse(self.job_has_changes(self.builds[0], A))
3405 self.assertFalse(self.job_has_changes(self.builds[0], C))
3406
3407 self.assertTrue(self.job_has_changes(self.builds[2], B))
3408 self.assertTrue(self.job_has_changes(self.builds[2], C))
3409 self.assertFalse(self.job_has_changes(self.builds[2], A))
3410
3411 self.assertTrue(self.job_has_changes(self.builds[4], B))
3412 self.assertTrue(self.job_has_changes(self.builds[4], C))
3413 self.assertTrue(self.job_has_changes(self.builds[4], A))
3414
James E. Blair08d19992016-08-10 15:25:31 -07003415 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003416 self.waitUntilSettled()
3417
3418 self.assertEqual(A.data['status'], 'MERGED')
3419 self.assertEqual(A.reported, 2)
3420 self.assertEqual(B.data['status'], 'MERGED')
3421 self.assertEqual(B.reported, 2)
3422 self.assertEqual(C.data['status'], 'MERGED')
3423 self.assertEqual(C.reported, 2)
3424
3425 client.shutdown()
3426 self.assertEqual(r, True)
3427
James E. Blairec056492016-07-22 09:45:56 -07003428 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003429 def test_client_promote_negative(self):
3430 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003431 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003432 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003433 A.addApproval('code-review', 2)
3434 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003435 self.waitUntilSettled()
3436
3437 client = zuul.rpcclient.RPCClient('127.0.0.1',
3438 self.gearman_server.port)
3439
3440 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3441 r = client.promote(pipeline='nonexistent',
3442 change_ids=['2,1', '3,1'])
3443 client.shutdown()
3444 self.assertEqual(r, False)
3445
3446 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3447 r = client.promote(pipeline='gate',
3448 change_ids=['4,1'])
3449 client.shutdown()
3450 self.assertEqual(r, False)
3451
James E. Blair08d19992016-08-10 15:25:31 -07003452 self.launch_server.hold_jobs_in_build = False
3453 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003454 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003455
James E. Blairec056492016-07-22 09:45:56 -07003456 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003457 def test_queue_rate_limiting(self):
3458 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003459 self.updateConfigLayout(
3460 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003461 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003462 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003463 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3464 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3465 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3466
3467 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003468 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003469
James E. Blair8b5408c2016-08-08 15:37:46 -07003470 A.addApproval('code-review', 2)
3471 B.addApproval('code-review', 2)
3472 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003473
James E. Blair8b5408c2016-08-08 15:37:46 -07003474 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3475 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3476 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003477 self.waitUntilSettled()
3478
3479 # Only A and B will have their merge jobs queued because
3480 # window is 2.
3481 self.assertEqual(len(self.builds), 2)
3482 self.assertEqual(self.builds[0].name, 'project-merge')
3483 self.assertEqual(self.builds[1].name, 'project-merge')
3484
James E. Blair08d19992016-08-10 15:25:31 -07003485 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003486 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003487 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003488 self.waitUntilSettled()
3489
3490 # Only A and B will have their test jobs queued because
3491 # window is 2.
3492 self.assertEqual(len(self.builds), 4)
3493 self.assertEqual(self.builds[0].name, 'project-test1')
3494 self.assertEqual(self.builds[1].name, 'project-test2')
3495 self.assertEqual(self.builds[2].name, 'project-test1')
3496 self.assertEqual(self.builds[3].name, 'project-test2')
3497
James E. Blair08d19992016-08-10 15:25:31 -07003498 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003499 self.waitUntilSettled()
3500
3501 queue = self.sched.layout.pipelines['gate'].queues[0]
3502 # A failed so window is reduced by 1 to 1.
3503 self.assertEqual(queue.window, 1)
3504 self.assertEqual(queue.window_floor, 1)
3505 self.assertEqual(A.data['status'], 'NEW')
3506
3507 # Gate is reset and only B's merge job is queued because
3508 # window shrunk to 1.
3509 self.assertEqual(len(self.builds), 1)
3510 self.assertEqual(self.builds[0].name, 'project-merge')
3511
James E. Blair08d19992016-08-10 15:25:31 -07003512 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003513 self.waitUntilSettled()
3514
3515 # Only B's test jobs are queued because window is still 1.
3516 self.assertEqual(len(self.builds), 2)
3517 self.assertEqual(self.builds[0].name, 'project-test1')
3518 self.assertEqual(self.builds[1].name, 'project-test2')
3519
James E. Blair08d19992016-08-10 15:25:31 -07003520 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003521 self.waitUntilSettled()
3522
3523 # B was successfully merged so window is increased to 2.
3524 self.assertEqual(queue.window, 2)
3525 self.assertEqual(queue.window_floor, 1)
3526 self.assertEqual(B.data['status'], 'MERGED')
3527
3528 # Only C is left and its merge job is queued.
3529 self.assertEqual(len(self.builds), 1)
3530 self.assertEqual(self.builds[0].name, 'project-merge')
3531
James E. Blair08d19992016-08-10 15:25:31 -07003532 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003533 self.waitUntilSettled()
3534
3535 # After successful merge job the test jobs for C are queued.
3536 self.assertEqual(len(self.builds), 2)
3537 self.assertEqual(self.builds[0].name, 'project-test1')
3538 self.assertEqual(self.builds[1].name, 'project-test2')
3539
James E. Blair08d19992016-08-10 15:25:31 -07003540 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003541 self.waitUntilSettled()
3542
3543 # C successfully merged so window is bumped to 3.
3544 self.assertEqual(queue.window, 3)
3545 self.assertEqual(queue.window_floor, 1)
3546 self.assertEqual(C.data['status'], 'MERGED')
3547
James E. Blairec056492016-07-22 09:45:56 -07003548 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003549 def test_queue_rate_limiting_dependent(self):
3550 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003551 self.updateConfigLayout(
3552 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003553 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003554 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003555 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3556 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3557 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3558
3559 B.setDependsOn(A, 1)
3560
James E. Blair08d19992016-08-10 15:25:31 -07003561 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003562
James E. Blair8b5408c2016-08-08 15:37:46 -07003563 A.addApproval('code-review', 2)
3564 B.addApproval('code-review', 2)
3565 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003566
James E. Blair8b5408c2016-08-08 15:37:46 -07003567 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3568 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3569 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003570 self.waitUntilSettled()
3571
3572 # Only A and B will have their merge jobs queued because
3573 # window is 2.
3574 self.assertEqual(len(self.builds), 2)
3575 self.assertEqual(self.builds[0].name, 'project-merge')
3576 self.assertEqual(self.builds[1].name, 'project-merge')
3577
James E. Blair08d19992016-08-10 15:25:31 -07003578 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003579 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003580 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003581 self.waitUntilSettled()
3582
3583 # Only A and B will have their test jobs queued because
3584 # window is 2.
3585 self.assertEqual(len(self.builds), 4)
3586 self.assertEqual(self.builds[0].name, 'project-test1')
3587 self.assertEqual(self.builds[1].name, 'project-test2')
3588 self.assertEqual(self.builds[2].name, 'project-test1')
3589 self.assertEqual(self.builds[3].name, 'project-test2')
3590
James E. Blair08d19992016-08-10 15:25:31 -07003591 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003592 self.waitUntilSettled()
3593
3594 queue = self.sched.layout.pipelines['gate'].queues[0]
3595 # A failed so window is reduced by 1 to 1.
3596 self.assertEqual(queue.window, 1)
3597 self.assertEqual(queue.window_floor, 1)
3598 self.assertEqual(A.data['status'], 'NEW')
3599 self.assertEqual(B.data['status'], 'NEW')
3600
3601 # Gate is reset and only C's merge job is queued because
3602 # window shrunk to 1 and A and B were dequeued.
3603 self.assertEqual(len(self.builds), 1)
3604 self.assertEqual(self.builds[0].name, 'project-merge')
3605
James E. Blair08d19992016-08-10 15:25:31 -07003606 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003607 self.waitUntilSettled()
3608
3609 # Only C's test jobs are queued because window is still 1.
3610 self.assertEqual(len(self.builds), 2)
3611 self.assertEqual(self.builds[0].name, 'project-test1')
3612 self.assertEqual(self.builds[1].name, 'project-test2')
3613
James E. Blair08d19992016-08-10 15:25:31 -07003614 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003615 self.waitUntilSettled()
3616
3617 # C was successfully merged so window is increased to 2.
3618 self.assertEqual(queue.window, 2)
3619 self.assertEqual(queue.window_floor, 1)
3620 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003621
James E. Blairec056492016-07-22 09:45:56 -07003622 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003623 def test_worker_update_metadata(self):
3624 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003625 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003626
3627 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003628 A.addApproval('code-review', 2)
3629 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003630 self.waitUntilSettled()
3631
3632 self.assertEqual(len(self.launcher.builds), 1)
3633
3634 self.log.debug('Current builds:')
3635 self.log.debug(self.launcher.builds)
3636
3637 start = time.time()
3638 while True:
3639 if time.time() - start > 10:
3640 raise Exception("Timeout waiting for gearman server to report "
3641 + "back to the client")
3642 build = self.launcher.builds.values()[0]
3643 if build.worker.name == "My Worker":
3644 break
3645 else:
3646 time.sleep(0)
3647
3648 self.log.debug(build)
3649 self.assertEqual("My Worker", build.worker.name)
3650 self.assertEqual("localhost", build.worker.hostname)
3651 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3652 self.assertEqual("zuul.example.org", build.worker.fqdn)
3653 self.assertEqual("FakeBuilder", build.worker.program)
3654 self.assertEqual("v1.1", build.worker.version)
3655 self.assertEqual({'something': 'else'}, build.worker.extra)
3656
James E. Blair08d19992016-08-10 15:25:31 -07003657 self.launch_server.hold_jobs_in_build = False
3658 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003659 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003660
James E. Blairec056492016-07-22 09:45:56 -07003661 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003662 def test_footer_message(self):
3663 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003664 self.updateConfigLayout(
3665 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003666 self.sched.reconfigure(self.config)
3667 self.registerJobs()
3668
3669 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003670 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003671 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003672 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003673 self.waitUntilSettled()
3674
3675 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003676 B.addApproval('code-review', 2)
3677 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003678 self.waitUntilSettled()
3679
3680 self.assertEqual(2, len(self.smtp_messages))
3681
3682 failure_body = """\
3683Build failed. For information on how to proceed, see \
3684http://wiki.example.org/Test_Failures
3685
3686- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3687- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3688
3689For CI problems and help debugging, contact ci@example.org"""
3690
3691 success_body = """\
3692Build succeeded.
3693
3694- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3695- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3696
3697For CI problems and help debugging, contact ci@example.org"""
3698
3699 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3700 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003701
James E. Blairec056492016-07-22 09:45:56 -07003702 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003703 def test_merge_failure_reporters(self):
3704 """Check that the config is set up correctly"""
3705
James E. Blairf84026c2015-12-08 16:11:46 -08003706 self.updateConfigLayout(
3707 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003708 self.sched.reconfigure(self.config)
3709 self.registerJobs()
3710
3711 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003712 "Merge Failed.\n\nThis change or one of its cross-repo "
3713 "dependencies was unable to be automatically merged with the "
3714 "current state of its repository. Please rebase the change and "
3715 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003716 self.sched.layout.pipelines['check'].merge_failure_message)
3717 self.assertEqual(
3718 "The merge failed! For more information...",
3719 self.sched.layout.pipelines['gate'].merge_failure_message)
3720
3721 self.assertEqual(
3722 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3723 self.assertEqual(
3724 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3725
3726 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003727 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3728 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003729
3730 self.assertTrue(
3731 (
3732 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003733 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003734 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003735 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003736 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003737 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003738 ) or (
3739 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003740 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003741 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003742 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003743 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003744 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003745 )
3746 )
3747
James E. Blairec056492016-07-22 09:45:56 -07003748 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003749 def test_merge_failure_reports(self):
3750 """Check that when a change fails to merge the correct message is sent
3751 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003752 self.updateConfigLayout(
3753 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003754 self.sched.reconfigure(self.config)
3755 self.registerJobs()
3756
3757 # Check a test failure isn't reported to SMTP
3758 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003759 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003760 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003761 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003762 self.waitUntilSettled()
3763
3764 self.assertEqual(3, len(self.history)) # 3 jobs
3765 self.assertEqual(0, len(self.smtp_messages))
3766
3767 # Check a merge failure is reported to SMTP
3768 # B should be merged, but C will conflict with B
3769 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3770 B.addPatchset(['conflict'])
3771 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3772 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003773 B.addApproval('code-review', 2)
3774 C.addApproval('code-review', 2)
3775 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3776 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003777 self.waitUntilSettled()
3778
3779 self.assertEqual(6, len(self.history)) # A and B jobs
3780 self.assertEqual(1, len(self.smtp_messages))
3781 self.assertEqual('The merge failed! For more information...',
3782 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003783
James E. Blairec056492016-07-22 09:45:56 -07003784 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003785 def test_default_merge_failure_reports(self):
3786 """Check that the default merge failure reports are correct."""
3787
3788 # A should report success, B should report merge failure.
3789 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3790 A.addPatchset(['conflict'])
3791 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3792 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003793 A.addApproval('code-review', 2)
3794 B.addApproval('code-review', 2)
3795 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3796 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003797 self.waitUntilSettled()
3798
3799 self.assertEqual(3, len(self.history)) # A jobs
3800 self.assertEqual(A.reported, 2)
3801 self.assertEqual(B.reported, 2)
3802 self.assertEqual(A.data['status'], 'MERGED')
3803 self.assertEqual(B.data['status'], 'NEW')
3804 self.assertIn('Build succeeded', A.messages[1])
3805 self.assertIn('Merge Failed', B.messages[1])
3806 self.assertIn('automatically merged', B.messages[1])
3807 self.assertNotIn('logs.example.com', B.messages[1])
3808 self.assertNotIn('SKIPPED', B.messages[1])
3809
James E. Blairec056492016-07-22 09:45:56 -07003810 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003811 def test_swift_instructions(self):
3812 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003813 self.updateConfigLayout(
3814 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003815 self.sched.reconfigure(self.config)
3816 self.registerJobs()
3817
James E. Blair08d19992016-08-10 15:25:31 -07003818 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003819 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3820
James E. Blair8b5408c2016-08-08 15:37:46 -07003821 A.addApproval('code-review', 2)
3822 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003823 self.waitUntilSettled()
3824
3825 self.assertEqual(
3826 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3827 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003828 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003829 self.assertEqual(5,
3830 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3831 split('\n')))
3832 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3833
3834 self.assertEqual(
3835 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3836 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003837 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003838 self.assertEqual(5,
3839 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3840 split('\n')))
3841 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3842
3843 self.assertEqual(
3844 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3845 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003846 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003847 self.assertEqual(5,
3848 len(self.builds[1].
3849 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3850 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3851
James E. Blair08d19992016-08-10 15:25:31 -07003852 self.launch_server.hold_jobs_in_build = False
3853 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003854 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003855
James E. Blairec056492016-07-22 09:45:56 -07003856 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003857 def test_client_get_running_jobs(self):
3858 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003859 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003860 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003861 A.addApproval('code-review', 2)
3862 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003863 self.waitUntilSettled()
3864
3865 client = zuul.rpcclient.RPCClient('127.0.0.1',
3866 self.gearman_server.port)
3867
3868 # Wait for gearman server to send the initial workData back to zuul
3869 start = time.time()
3870 while True:
3871 if time.time() - start > 10:
3872 raise Exception("Timeout waiting for gearman server to report "
3873 + "back to the client")
3874 build = self.launcher.builds.values()[0]
3875 if build.worker.name == "My Worker":
3876 break
3877 else:
3878 time.sleep(0)
3879
3880 running_items = client.get_running_jobs()
3881
3882 self.assertEqual(1, len(running_items))
3883 running_item = running_items[0]
3884 self.assertEqual([], running_item['failing_reasons'])
3885 self.assertEqual([], running_item['items_behind'])
3886 self.assertEqual('https://hostname/1', running_item['url'])
3887 self.assertEqual(None, running_item['item_ahead'])
3888 self.assertEqual('org/project', running_item['project'])
3889 self.assertEqual(None, running_item['remaining_time'])
3890 self.assertEqual(True, running_item['active'])
3891 self.assertEqual('1,1', running_item['id'])
3892
3893 self.assertEqual(3, len(running_item['jobs']))
3894 for job in running_item['jobs']:
3895 if job['name'] == 'project-merge':
3896 self.assertEqual('project-merge', job['name'])
3897 self.assertEqual('gate', job['pipeline'])
3898 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003899 self.assertEqual('https://server/job/project-merge/0/',
3900 job['url'])
3901 self.assertEqual(7, len(job['worker']))
3902 self.assertEqual(False, job['canceled'])
3903 self.assertEqual(True, job['voting'])
3904 self.assertEqual(None, job['result'])
3905 self.assertEqual('gate', job['pipeline'])
3906 break
3907
James E. Blair08d19992016-08-10 15:25:31 -07003908 self.launch_server.hold_jobs_in_build = False
3909 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003910 self.waitUntilSettled()
3911
3912 running_items = client.get_running_jobs()
3913 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003914
James E. Blairec056492016-07-22 09:45:56 -07003915 @skip("Disabled for early v3 development")
James E. Blairbadc1ad2014-04-28 13:55:14 -07003916 def test_nonvoting_pipeline(self):
3917 "Test that a nonvoting pipeline (experimental) can still report"
3918
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003919 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3920 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003921 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3922 self.waitUntilSettled()
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003923 self.assertEqual(
3924 self.getJobFromHistory('experimental-project-test').result,
3925 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003926 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003927
James E. Blairec056492016-07-22 09:45:56 -07003928 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003929 def test_crd_gate(self):
3930 "Test cross-repo dependencies"
3931 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3932 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003933 A.addApproval('code-review', 2)
3934 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003935
3936 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3937 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3938 AM2.setMerged()
3939 AM1.setMerged()
3940
3941 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3942 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3943 BM2.setMerged()
3944 BM1.setMerged()
3945
3946 # A -> AM1 -> AM2
3947 # B -> BM1 -> BM2
3948 # A Depends-On: B
3949 # M2 is here to make sure it is never queried. If it is, it
3950 # means zuul is walking down the entire history of merged
3951 # changes.
3952
3953 B.setDependsOn(BM1, 1)
3954 BM1.setDependsOn(BM2, 1)
3955
3956 A.setDependsOn(AM1, 1)
3957 AM1.setDependsOn(AM2, 1)
3958
3959 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3960 A.subject, B.data['id'])
3961
James E. Blair8b5408c2016-08-08 15:37:46 -07003962 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003963 self.waitUntilSettled()
3964
3965 self.assertEqual(A.data['status'], 'NEW')
3966 self.assertEqual(B.data['status'], 'NEW')
3967
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003968 for connection in self.connections.values():
3969 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003970
James E. Blair08d19992016-08-10 15:25:31 -07003971 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003972 B.addApproval('approved', 1)
3973 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003974 self.waitUntilSettled()
3975
James E. Blair08d19992016-08-10 15:25:31 -07003976 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003977 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003978 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003979 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003980 self.launch_server.hold_jobs_in_build = False
3981 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003982 self.waitUntilSettled()
3983
3984 self.assertEqual(AM2.queried, 0)
3985 self.assertEqual(BM2.queried, 0)
3986 self.assertEqual(A.data['status'], 'MERGED')
3987 self.assertEqual(B.data['status'], 'MERGED')
3988 self.assertEqual(A.reported, 2)
3989 self.assertEqual(B.reported, 2)
3990
James E. Blair8f78d882015-02-05 08:51:37 -08003991 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3992 '2,1 1,1')
3993
James E. Blairec056492016-07-22 09:45:56 -07003994 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003995 def test_crd_branch(self):
3996 "Test cross-repo dependencies in multiple branches"
3997 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3998 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3999 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
4000 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07004001 A.addApproval('code-review', 2)
4002 B.addApproval('code-review', 2)
4003 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004004
4005 # A Depends-On: B+C
4006 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4007 A.subject, B.data['id'])
4008
James E. Blair08d19992016-08-10 15:25:31 -07004009 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004010 B.addApproval('approved', 1)
4011 C.addApproval('approved', 1)
4012 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004013 self.waitUntilSettled()
4014
James E. Blair08d19992016-08-10 15:25:31 -07004015 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004016 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004017 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004018 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004019 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004020 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004021 self.launch_server.hold_jobs_in_build = False
4022 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004023 self.waitUntilSettled()
4024
4025 self.assertEqual(A.data['status'], 'MERGED')
4026 self.assertEqual(B.data['status'], 'MERGED')
4027 self.assertEqual(C.data['status'], 'MERGED')
4028 self.assertEqual(A.reported, 2)
4029 self.assertEqual(B.reported, 2)
4030 self.assertEqual(C.reported, 2)
4031
4032 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4033 '2,1 3,1 1,1')
4034
James E. Blairec056492016-07-22 09:45:56 -07004035 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08004036 def test_crd_multiline(self):
4037 "Test multiple depends-on lines in commit"
4038 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4039 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4040 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07004041 A.addApproval('code-review', 2)
4042 B.addApproval('code-review', 2)
4043 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08004044
4045 # A Depends-On: B+C
4046 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
4047 A.subject, B.data['id'], C.data['id'])
4048
James E. Blair08d19992016-08-10 15:25:31 -07004049 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004050 B.addApproval('approved', 1)
4051 C.addApproval('approved', 1)
4052 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08004053 self.waitUntilSettled()
4054
James E. Blair08d19992016-08-10 15:25:31 -07004055 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004056 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004057 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004058 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004059 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08004060 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004061 self.launch_server.hold_jobs_in_build = False
4062 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08004063 self.waitUntilSettled()
4064
4065 self.assertEqual(A.data['status'], 'MERGED')
4066 self.assertEqual(B.data['status'], 'MERGED')
4067 self.assertEqual(C.data['status'], 'MERGED')
4068 self.assertEqual(A.reported, 2)
4069 self.assertEqual(B.reported, 2)
4070 self.assertEqual(C.reported, 2)
4071
4072 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4073 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08004074
James E. Blairec056492016-07-22 09:45:56 -07004075 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004076 def test_crd_unshared_gate(self):
4077 "Test cross-repo dependencies in unshared gate queues"
4078 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4079 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004080 A.addApproval('code-review', 2)
4081 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004082
4083 # A Depends-On: B
4084 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4085 A.subject, B.data['id'])
4086
4087 # A and B do not share a queue, make sure that A is unable to
4088 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07004089 B.addApproval('approved', 1)
4090 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004091 self.waitUntilSettled()
4092
4093 self.assertEqual(A.data['status'], 'NEW')
4094 self.assertEqual(B.data['status'], 'NEW')
4095 self.assertEqual(A.reported, 0)
4096 self.assertEqual(B.reported, 0)
4097 self.assertEqual(len(self.history), 0)
4098
4099 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004100 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004101 self.waitUntilSettled()
4102
4103 self.assertEqual(B.data['status'], 'MERGED')
4104 self.assertEqual(B.reported, 2)
4105
4106 # Now that B is merged, A should be able to be enqueued and
4107 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004108 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004109 self.waitUntilSettled()
4110
4111 self.assertEqual(A.data['status'], 'MERGED')
4112 self.assertEqual(A.reported, 2)
4113
James E. Blairec056492016-07-22 09:45:56 -07004114 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004115 def test_crd_gate_reverse(self):
4116 "Test reverse cross-repo dependencies"
4117 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4118 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004119 A.addApproval('code-review', 2)
4120 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004121
4122 # A Depends-On: B
4123
4124 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4125 A.subject, B.data['id'])
4126
James E. Blair8b5408c2016-08-08 15:37:46 -07004127 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004128 self.waitUntilSettled()
4129
4130 self.assertEqual(A.data['status'], 'NEW')
4131 self.assertEqual(B.data['status'], 'NEW')
4132
James E. Blair08d19992016-08-10 15:25:31 -07004133 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004134 A.addApproval('approved', 1)
4135 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004136 self.waitUntilSettled()
4137
James E. Blair08d19992016-08-10 15:25:31 -07004138 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004139 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004140 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004141 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004142 self.launch_server.hold_jobs_in_build = False
4143 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004144 self.waitUntilSettled()
4145
4146 self.assertEqual(A.data['status'], 'MERGED')
4147 self.assertEqual(B.data['status'], 'MERGED')
4148 self.assertEqual(A.reported, 2)
4149 self.assertEqual(B.reported, 2)
4150
4151 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4152 '2,1 1,1')
4153
James E. Blairec056492016-07-22 09:45:56 -07004154 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004155 def test_crd_cycle(self):
4156 "Test cross-repo dependency cycles"
4157 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4158 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004159 A.addApproval('code-review', 2)
4160 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004161
4162 # A -> B -> A (via commit-depends)
4163
4164 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4165 A.subject, B.data['id'])
4166 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4167 B.subject, A.data['id'])
4168
James E. Blair8b5408c2016-08-08 15:37:46 -07004169 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004170 self.waitUntilSettled()
4171
4172 self.assertEqual(A.reported, 0)
4173 self.assertEqual(B.reported, 0)
4174 self.assertEqual(A.data['status'], 'NEW')
4175 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004176
James E. Blairec056492016-07-22 09:45:56 -07004177 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004178 def test_crd_gate_unknown(self):
4179 "Test unknown projects in dependent pipeline"
4180 self.init_repo("org/unknown")
4181 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4182 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004183 A.addApproval('code-review', 2)
4184 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004185
4186 # A Depends-On: B
4187 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4188 A.subject, B.data['id'])
4189
James E. Blair8b5408c2016-08-08 15:37:46 -07004190 B.addApproval('approved', 1)
4191 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004192 self.waitUntilSettled()
4193
4194 # Unknown projects cannot share a queue with any other
4195 # since they don't have common jobs with any other (they have no jobs).
4196 # Changes which depend on unknown project changes
4197 # should not be processed in dependent pipeline
4198 self.assertEqual(A.data['status'], 'NEW')
4199 self.assertEqual(B.data['status'], 'NEW')
4200 self.assertEqual(A.reported, 0)
4201 self.assertEqual(B.reported, 0)
4202 self.assertEqual(len(self.history), 0)
4203
4204 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004205 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004206 B.setMerged()
4207 self.waitUntilSettled()
4208 self.assertEqual(len(self.history), 0)
4209
4210 # Now that B is merged, A should be able to be enqueued and
4211 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004212 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004213 self.waitUntilSettled()
4214
4215 self.assertEqual(A.data['status'], 'MERGED')
4216 self.assertEqual(A.reported, 2)
4217 self.assertEqual(B.data['status'], 'MERGED')
4218 self.assertEqual(B.reported, 0)
4219
James E. Blairec056492016-07-22 09:45:56 -07004220 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004221 def test_crd_check(self):
4222 "Test cross-repo dependencies in independent pipelines"
4223
4224 self.gearman_server.hold_jobs_in_queue = True
4225 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4226 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4227
4228 # A Depends-On: B
4229 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4230 A.subject, B.data['id'])
4231
4232 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4233 self.waitUntilSettled()
4234
4235 queue = self.gearman_server.getQueue()
4236 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4237 self.gearman_server.hold_jobs_in_queue = False
4238 self.gearman_server.release()
4239 self.waitUntilSettled()
4240
4241 path = os.path.join(self.git_root, "org/project1")
4242 repo = git.Repo(path)
4243 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4244 repo_messages.reverse()
4245 correct_messages = ['initial commit', 'A-1']
4246 self.assertEqual(repo_messages, correct_messages)
4247
4248 path = os.path.join(self.git_root, "org/project2")
4249 repo = git.Repo(path)
4250 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4251 repo_messages.reverse()
4252 correct_messages = ['initial commit', 'B-1']
4253 self.assertEqual(repo_messages, correct_messages)
4254
4255 self.assertEqual(A.data['status'], 'NEW')
4256 self.assertEqual(B.data['status'], 'NEW')
4257 self.assertEqual(A.reported, 1)
4258 self.assertEqual(B.reported, 0)
4259
4260 self.assertEqual(self.history[0].changes, '2,1 1,1')
4261 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004262
James E. Blairec056492016-07-22 09:45:56 -07004263 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004264 def test_crd_check_git_depends(self):
4265 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004266 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004267 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4268 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4269
4270 # Add two git-dependent changes and make sure they both report
4271 # success.
4272 B.setDependsOn(A, 1)
4273 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4274 self.waitUntilSettled()
4275 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4276 self.waitUntilSettled()
4277
James E. Blairb8c16472015-05-05 14:55:26 -07004278 self.orderedRelease()
4279 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004280 self.waitUntilSettled()
4281
4282 self.assertEqual(A.data['status'], 'NEW')
4283 self.assertEqual(B.data['status'], 'NEW')
4284 self.assertEqual(A.reported, 1)
4285 self.assertEqual(B.reported, 1)
4286
4287 self.assertEqual(self.history[0].changes, '1,1')
4288 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4289 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4290
4291 self.assertIn('Build succeeded', A.messages[0])
4292 self.assertIn('Build succeeded', B.messages[0])
4293
James E. Blairec056492016-07-22 09:45:56 -07004294 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004295 def test_crd_check_duplicate(self):
4296 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004297 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004298 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4299 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4300 check_pipeline = self.sched.layout.pipelines['check']
4301
4302 # Add two git-dependent changes...
4303 B.setDependsOn(A, 1)
4304 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4305 self.waitUntilSettled()
4306 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4307
4308 # ...make sure the live one is not duplicated...
4309 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4310 self.waitUntilSettled()
4311 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4312
4313 # ...but the non-live one is able to be.
4314 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4315 self.waitUntilSettled()
4316 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4317
Clark Boylandd849822015-03-02 12:38:14 -08004318 # Release jobs in order to avoid races with change A jobs
4319 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004320 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004321 self.launch_server.hold_jobs_in_build = False
4322 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004323 self.waitUntilSettled()
4324
4325 self.assertEqual(A.data['status'], 'NEW')
4326 self.assertEqual(B.data['status'], 'NEW')
4327 self.assertEqual(A.reported, 1)
4328 self.assertEqual(B.reported, 1)
4329
4330 self.assertEqual(self.history[0].changes, '1,1 2,1')
4331 self.assertEqual(self.history[1].changes, '1,1')
4332 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4333
4334 self.assertIn('Build succeeded', A.messages[0])
4335 self.assertIn('Build succeeded', B.messages[0])
4336
James E. Blairec056492016-07-22 09:45:56 -07004337 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004338 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004339 "Test cross-repo dependencies re-enqueued in independent pipelines"
4340
4341 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004342 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4343 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004344
4345 # A Depends-On: B
4346 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4347 A.subject, B.data['id'])
4348
4349 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4350 self.waitUntilSettled()
4351
4352 self.sched.reconfigure(self.config)
4353
4354 # Make sure the items still share a change queue, and the
4355 # first one is not live.
4356 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4357 queue = self.sched.layout.pipelines['check'].queues[0]
4358 first_item = queue.queue[0]
4359 for item in queue.queue:
4360 self.assertEqual(item.queue, first_item.queue)
4361 self.assertFalse(first_item.live)
4362 self.assertTrue(queue.queue[1].live)
4363
4364 self.gearman_server.hold_jobs_in_queue = False
4365 self.gearman_server.release()
4366 self.waitUntilSettled()
4367
4368 self.assertEqual(A.data['status'], 'NEW')
4369 self.assertEqual(B.data['status'], 'NEW')
4370 self.assertEqual(A.reported, 1)
4371 self.assertEqual(B.reported, 0)
4372
4373 self.assertEqual(self.history[0].changes, '2,1 1,1')
4374 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004375
James E. Blairec056492016-07-22 09:45:56 -07004376 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004377 def test_crd_check_reconfiguration(self):
4378 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4379
James E. Blairec056492016-07-22 09:45:56 -07004380 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004381 def test_crd_undefined_project(self):
4382 """Test that undefined projects in dependencies are handled for
4383 independent pipelines"""
4384 # It's a hack for fake gerrit,
4385 # as it implies repo creation upon the creation of any change
4386 self.init_repo("org/unknown")
4387 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4388
James E. Blairec056492016-07-22 09:45:56 -07004389 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004390 def test_crd_check_ignore_dependencies(self):
4391 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004392 self.updateConfigLayout(
4393 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004394 self.sched.reconfigure(self.config)
4395 self.registerJobs()
4396
4397 self.gearman_server.hold_jobs_in_queue = True
4398 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4399 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4400 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4401
4402 # A Depends-On: B
4403 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4404 A.subject, B.data['id'])
4405 # C git-depends on B
4406 C.setDependsOn(B, 1)
4407 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4408 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4409 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4410 self.waitUntilSettled()
4411
4412 # Make sure none of the items share a change queue, and all
4413 # are live.
4414 check_pipeline = self.sched.layout.pipelines['check']
4415 self.assertEqual(len(check_pipeline.queues), 3)
4416 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4417 for item in check_pipeline.getAllItems():
4418 self.assertTrue(item.live)
4419
4420 self.gearman_server.hold_jobs_in_queue = False
4421 self.gearman_server.release()
4422 self.waitUntilSettled()
4423
4424 self.assertEqual(A.data['status'], 'NEW')
4425 self.assertEqual(B.data['status'], 'NEW')
4426 self.assertEqual(C.data['status'], 'NEW')
4427 self.assertEqual(A.reported, 1)
4428 self.assertEqual(B.reported, 1)
4429 self.assertEqual(C.reported, 1)
4430
4431 # Each job should have tested exactly one change
4432 for job in self.history:
4433 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004434
James E. Blairec056492016-07-22 09:45:56 -07004435 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004436 def test_crd_check_transitive(self):
4437 "Test transitive cross-repo dependencies"
4438 # Specifically, if A -> B -> C, and C gets a new patchset and
4439 # A gets a new patchset, ensure the test of A,2 includes B,1
4440 # and C,2 (not C,1 which would indicate stale data in the
4441 # cache for B).
4442 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4443 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4444 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4445
4446 # A Depends-On: B
4447 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4448 A.subject, B.data['id'])
4449
4450 # B Depends-On: C
4451 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4452 B.subject, C.data['id'])
4453
4454 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4455 self.waitUntilSettled()
4456 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4457
4458 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4459 self.waitUntilSettled()
4460 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4461
4462 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4463 self.waitUntilSettled()
4464 self.assertEqual(self.history[-1].changes, '3,1')
4465
4466 C.addPatchset()
4467 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4468 self.waitUntilSettled()
4469 self.assertEqual(self.history[-1].changes, '3,2')
4470
4471 A.addPatchset()
4472 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4473 self.waitUntilSettled()
4474 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004475
James E. Blairec056492016-07-22 09:45:56 -07004476 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004477 def test_crd_cycle_join(self):
4478 "Test an updated change creates a cycle"
4479 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4480
4481 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4482 self.waitUntilSettled()
4483
4484 # Create B->A
4485 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4486 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4487 B.subject, A.data['id'])
4488 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4489 self.waitUntilSettled()
4490
4491 # Update A to add A->B (a cycle).
4492 A.addPatchset()
4493 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4494 A.subject, B.data['id'])
4495 # Normally we would submit the patchset-created event for
4496 # processing here, however, we have no way of noting whether
4497 # the dependency cycle detection correctly raised an
4498 # exception, so instead, we reach into the source driver and
4499 # call the method that would ultimately be called by the event
4500 # processing.
4501
4502 source = self.sched.layout.pipelines['gate'].source
4503 with testtools.ExpectedException(
4504 Exception, "Dependency cycle detected"):
4505 source._getChange(u'1', u'2', True)
4506 self.log.debug("Got expected dependency cycle exception")
4507
4508 # Now if we update B to remove the depends-on, everything
4509 # should be okay. B; A->B
4510
4511 B.addPatchset()
4512 B.data['commitMessage'] = '%s\n' % (B.subject,)
4513 source._getChange(u'1', u'2', True)
4514 source._getChange(u'2', u'2', True)
4515
James E. Blairec056492016-07-22 09:45:56 -07004516 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004517 def test_disable_at(self):
4518 "Test a pipeline will only report to the disabled trigger when failing"
4519
James E. Blairf84026c2015-12-08 16:11:46 -08004520 self.updateConfigLayout(
4521 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004522 self.sched.reconfigure(self.config)
4523
4524 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4525 self.assertEqual(
4526 0, self.sched.layout.pipelines['check']._consecutive_failures)
4527 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4528
4529 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4530 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4531 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4532 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4533 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4534 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4535 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4536 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4537 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4538 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4539 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4540
James E. Blair08d19992016-08-10 15:25:31 -07004541 self.launch_server.failJob('project-test1', A)
4542 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004543 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004544 self.launch_server.failJob('project-test1', D)
4545 self.launch_server.failJob('project-test1', E)
4546 self.launch_server.failJob('project-test1', F)
4547 self.launch_server.failJob('project-test1', G)
4548 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004549 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004550 self.launch_server.failJob('project-test1', J)
4551 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004552
4553 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4554 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4555 self.waitUntilSettled()
4556
4557 self.assertEqual(
4558 2, self.sched.layout.pipelines['check']._consecutive_failures)
4559 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4560
4561 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4562 self.waitUntilSettled()
4563
4564 self.assertEqual(
4565 0, self.sched.layout.pipelines['check']._consecutive_failures)
4566 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4567
4568 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4569 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4570 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4571 self.waitUntilSettled()
4572
4573 # We should be disabled now
4574 self.assertEqual(
4575 3, self.sched.layout.pipelines['check']._consecutive_failures)
4576 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4577
4578 # We need to wait between each of these patches to make sure the
4579 # smtp messages come back in an expected order
4580 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4581 self.waitUntilSettled()
4582 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4583 self.waitUntilSettled()
4584 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4585 self.waitUntilSettled()
4586
4587 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4588 # leaving a message on each change
4589 self.assertEqual(1, len(A.messages))
4590 self.assertIn('Build failed.', A.messages[0])
4591 self.assertEqual(1, len(B.messages))
4592 self.assertIn('Build failed.', B.messages[0])
4593 self.assertEqual(1, len(C.messages))
4594 self.assertIn('Build succeeded.', C.messages[0])
4595 self.assertEqual(1, len(D.messages))
4596 self.assertIn('Build failed.', D.messages[0])
4597 self.assertEqual(1, len(E.messages))
4598 self.assertIn('Build failed.', E.messages[0])
4599 self.assertEqual(1, len(F.messages))
4600 self.assertIn('Build failed.', F.messages[0])
4601
4602 # The last 3 (GHI) would have only reported via smtp.
4603 self.assertEqual(3, len(self.smtp_messages))
4604 self.assertEqual(0, len(G.messages))
4605 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4606 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4607 self.assertEqual(0, len(H.messages))
4608 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4609 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4610 self.assertEqual(0, len(I.messages))
4611 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4612 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4613
4614 # Now reload the configuration (simulate a HUP) to check the pipeline
4615 # comes out of disabled
4616 self.sched.reconfigure(self.config)
4617
4618 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4619 self.assertEqual(
4620 0, self.sched.layout.pipelines['check']._consecutive_failures)
4621 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4622
4623 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4624 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4625 self.waitUntilSettled()
4626
4627 self.assertEqual(
4628 2, self.sched.layout.pipelines['check']._consecutive_failures)
4629 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4630
4631 # J and K went back to gerrit
4632 self.assertEqual(1, len(J.messages))
4633 self.assertIn('Build failed.', J.messages[0])
4634 self.assertEqual(1, len(K.messages))
4635 self.assertIn('Build failed.', K.messages[0])
4636 # No more messages reported via smtp
4637 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004638
James E. Blairec056492016-07-22 09:45:56 -07004639 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004640 def test_success_pattern(self):
4641 "Ensure bad build params are ignored"
4642
4643 # Use SMTP reporter to grab the result message easier
4644 self.init_repo("org/docs")
4645 self.config.set('zuul', 'layout_config',
4646 'tests/fixtures/layout-success-pattern.yaml')
4647 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004648 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004649 self.registerJobs()
4650
4651 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4652 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4653 self.waitUntilSettled()
4654
4655 # Grab build id
4656 self.assertEqual(len(self.builds), 1)
4657 uuid = self.builds[0].unique[:7]
4658
James E. Blair08d19992016-08-10 15:25:31 -07004659 self.launch_server.hold_jobs_in_build = False
4660 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004661 self.waitUntilSettled()
4662
4663 self.assertEqual(len(self.smtp_messages), 1)
4664 body = self.smtp_messages[0]['body'].splitlines()
4665 self.assertEqual('Build succeeded.', body[0])
4666
4667 self.assertIn(
4668 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4669 'docs-draft-test/%s/publish-docs/' % uuid,
4670 body[2])
4671 self.assertIn(
4672 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4673 body[3])