blob: fe814e850a0b5544c254d228901622b6bb8d3c9a [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. Blairb0fcae42012-07-17 11:12:10 -070064
James E. Blair552b54f2016-07-22 13:55:32 -070065 # TODOv3(jeblair): we may want to report stats by tenant (also?).
James E. Blair66eeebf2013-07-27 17:44:32 -070066 self.assertReportedStat('gerrit.event.comment-added', value='1|c')
67 self.assertReportedStat('zuul.pipeline.gate.current_changes',
68 value='1|g')
69 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
70 kind='ms')
71 self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',
72 value='1|c')
73 self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms')
74 self.assertReportedStat('zuul.pipeline.gate.total_changes',
75 value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070076 self.assertReportedStat(
James E. Blair66eeebf2013-07-27 17:44:32 -070077 'zuul.pipeline.gate.org.project.resident_time', kind='ms')
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.total_changes', value='1|c')
James E. Blair412e5582013-04-22 15:50:12 -070080
James E. Blair5821bd92015-09-16 08:48:15 -070081 for build in self.builds:
82 self.assertEqual(build.parameters['ZUUL_VOTING'], '1')
83
James E. Blair3cb10702013-08-24 08:56:03 -070084 def test_initial_pipeline_gauges(self):
85 "Test that each pipeline reported its length on start"
James E. Blair7da51b72016-07-25 15:29:43 -070086 self.assertReportedStat('zuul.pipeline.gate.current_changes',
87 value='0|g')
88 self.assertReportedStat('zuul.pipeline.check.current_changes',
89 value='0|g')
James E. Blair3cb10702013-08-24 08:56:03 -070090
James E. Blairec056492016-07-22 09:45:56 -070091 @skip("Disabled for early v3 development")
James E. Blair42f74822013-05-14 15:18:03 -070092 def test_duplicate_pipelines(self):
93 "Test that a change matching multiple pipelines works"
James E. Blair1b4d9722013-05-21 10:32:04 -070094
James E. Blair42f74822013-05-14 15:18:03 -070095 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
96 self.fake_gerrit.addEvent(A.getChangeRestoredEvent())
97 self.waitUntilSettled()
James E. Blair42f74822013-05-14 15:18:03 -070098
Monty Taylor98f0f3e2013-07-06 16:02:31 -040099 self.assertEqual(len(self.history), 2)
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400100 self.history[0].name == 'project-test1'
101 self.history[1].name == 'project-test1'
James E. Blair42f74822013-05-14 15:18:03 -0700102
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400103 self.assertEqual(len(A.messages), 2)
James E. Blair42f74822013-05-14 15:18:03 -0700104 if 'dup1/project-test1' in A.messages[0]:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400105 self.assertIn('dup1/project-test1', A.messages[0])
106 self.assertNotIn('dup2/project-test1', A.messages[0])
107 self.assertNotIn('dup1/project-test1', A.messages[1])
108 self.assertIn('dup2/project-test1', A.messages[1])
James E. Blair42f74822013-05-14 15:18:03 -0700109 else:
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400110 self.assertIn('dup1/project-test1', A.messages[1])
111 self.assertNotIn('dup2/project-test1', A.messages[1])
112 self.assertNotIn('dup1/project-test1', A.messages[0])
113 self.assertIn('dup2/project-test1', A.messages[0])
James E. Blair42f74822013-05-14 15:18:03 -0700114
James E. Blairb0fcae42012-07-17 11:12:10 -0700115 def test_parallel_changes(self):
116 "Test that changes are tested in parallel and merged in series"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700117
James E. Blair791b5392016-08-03 11:25:56 -0700118 self.launch_server.hold_jobs_in_build = True
James E. Blairb0fcae42012-07-17 11:12:10 -0700119 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
120 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
121 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700122 A.addApproval('code-review', 2)
123 B.addApproval('code-review', 2)
124 C.addApproval('code-review', 2)
James E. Blairb0fcae42012-07-17 11:12:10 -0700125
James E. Blair8b5408c2016-08-08 15:37:46 -0700126 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
127 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
128 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb0fcae42012-07-17 11:12:10 -0700129
130 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400131 self.assertEqual(len(self.builds), 1)
132 self.assertEqual(self.builds[0].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700133 self.assertTrue(self.builds[0].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700134
James E. Blair791b5392016-08-03 11:25:56 -0700135 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700136 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400137 self.assertEqual(len(self.builds), 3)
138 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700139 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400140 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700141 self.assertTrue(self.builds[1].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400142 self.assertEqual(self.builds[2].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700143 self.assertTrue(self.builds[2].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700144
James E. Blair791b5392016-08-03 11:25:56 -0700145 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700146 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400147 self.assertEqual(len(self.builds), 5)
148 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700149 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400150 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700151 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700152
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400153 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700154 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400155 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700156 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700157
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400158 self.assertEqual(self.builds[4].name, 'project-merge')
James E. Blair791b5392016-08-03 11:25:56 -0700159 self.assertTrue(self.builds[4].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700160
James E. Blair791b5392016-08-03 11:25:56 -0700161 self.launch_server.release('.*-merge')
James E. Blairb0fcae42012-07-17 11:12:10 -0700162 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400163 self.assertEqual(len(self.builds), 6)
164 self.assertEqual(self.builds[0].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700165 self.assertTrue(self.builds[0].hasChanges(A))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400166 self.assertEqual(self.builds[1].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700167 self.assertTrue(self.builds[1].hasChanges(A))
James E. Blairb0fcae42012-07-17 11:12:10 -0700168
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400169 self.assertEqual(self.builds[2].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700170 self.assertTrue(self.builds[2].hasChanges(A, B))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400171 self.assertEqual(self.builds[3].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700172 self.assertTrue(self.builds[3].hasChanges(A, B))
James E. Blairb0fcae42012-07-17 11:12:10 -0700173
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400174 self.assertEqual(self.builds[4].name, 'project-test1')
James E. Blair791b5392016-08-03 11:25:56 -0700175 self.assertTrue(self.builds[4].hasChanges(A, B, C))
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400176 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blair791b5392016-08-03 11:25:56 -0700177 self.assertTrue(self.builds[5].hasChanges(A, B, C))
James E. Blairb0fcae42012-07-17 11:12:10 -0700178
James E. Blair791b5392016-08-03 11:25:56 -0700179 self.launch_server.hold_jobs_in_build = False
180 self.launch_server.release()
James E. Blairb0fcae42012-07-17 11:12:10 -0700181 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400182 self.assertEqual(len(self.builds), 0)
James E. Blairb0fcae42012-07-17 11:12:10 -0700183
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400184 self.assertEqual(len(self.history), 9)
185 self.assertEqual(A.data['status'], 'MERGED')
186 self.assertEqual(B.data['status'], 'MERGED')
187 self.assertEqual(C.data['status'], 'MERGED')
188 self.assertEqual(A.reported, 2)
189 self.assertEqual(B.reported, 2)
190 self.assertEqual(C.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700191
192 def test_failed_changes(self):
193 "Test that a change behind a failed change is retested"
James E. Blair08d19992016-08-10 15:25:31 -0700194 self.launch_server.hold_jobs_in_build = True
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700195
James E. Blairb02a3bb2012-07-30 17:49:55 -0700196 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
197 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -0700198 A.addApproval('code-review', 2)
199 B.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700200
James E. Blair08d19992016-08-10 15:25:31 -0700201 self.launch_server.failJob('project-test1', A)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700202
James E. Blair8b5408c2016-08-08 15:37:46 -0700203 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
204 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700205 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700206 self.assertBuilds([dict(name='project-merge', changes='1,1')])
James E. Blaire2819012013-06-28 17:17:26 -0400207
James E. Blair08d19992016-08-10 15:25:31 -0700208 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400209 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700210 # A/project-merge is complete
211 self.assertBuilds([
212 dict(name='project-test1', changes='1,1'),
213 dict(name='project-test2', changes='1,1'),
214 dict(name='project-merge', changes='1,1 2,1'),
215 ])
James E. Blaire2819012013-06-28 17:17:26 -0400216
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700217 self.launch_server.release('.*-merge')
James E. Blaire2819012013-06-28 17:17:26 -0400218 self.waitUntilSettled()
James E. Blair2b2a8ab2016-08-11 14:39:11 -0700219 # A/project-merge is complete
220 # B/project-merge is complete
221 self.assertBuilds([
222 dict(name='project-test1', changes='1,1'),
223 dict(name='project-test2', changes='1,1'),
224 dict(name='project-test1', changes='1,1 2,1'),
225 dict(name='project-test2', changes='1,1 2,1'),
226 ])
227
228 # Release project-test1 for A which will fail. This will
229 # abort both running B jobs and relaunch project-merge for B.
230 self.builds[0].release()
231 self.waitUntilSettled()
232
233 self.orderedRelease()
234 self.assertHistory([
235 dict(name='project-merge', result='SUCCESS', changes='1,1'),
236 dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'),
237 dict(name='project-test1', result='FAILURE', changes='1,1'),
238 dict(name='project-test1', result='ABORTED', changes='1,1 2,1'),
239 dict(name='project-test2', result='ABORTED', changes='1,1 2,1'),
240 dict(name='project-test2', result='SUCCESS', changes='1,1'),
241 dict(name='project-merge', result='SUCCESS', changes='2,1'),
242 dict(name='project-test1', result='SUCCESS', changes='2,1'),
243 dict(name='project-test2', result='SUCCESS', changes='2,1'),
244 ])
245
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400246 self.assertEqual(A.data['status'], 'NEW')
247 self.assertEqual(B.data['status'], 'MERGED')
248 self.assertEqual(A.reported, 2)
249 self.assertEqual(B.reported, 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700250
James E. Blairec056492016-07-22 09:45:56 -0700251 @skip("Disabled for early v3 development")
James E. Blairb02a3bb2012-07-30 17:49:55 -0700252 def test_independent_queues(self):
253 "Test that changes end up in the right queues"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700254
James E. Blair08d19992016-08-10 15:25:31 -0700255 self.launch_server.hold_jobs_in_build = True
Zhongyue Luo5d556072012-09-21 02:00:47 +0900256 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700257 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
258 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700259 A.addApproval('code-review', 2)
260 B.addApproval('code-review', 2)
261 C.addApproval('code-review', 2)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700262
James E. Blair8b5408c2016-08-08 15:37:46 -0700263 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
264 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
265 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700266
James E. Blairb02a3bb2012-07-30 17:49:55 -0700267 self.waitUntilSettled()
268
269 # There should be one merge job at the head of each queue running
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400270 self.assertEqual(len(self.builds), 2)
271 self.assertEqual(self.builds[0].name, 'project-merge')
272 self.assertTrue(self.job_has_changes(self.builds[0], A))
273 self.assertEqual(self.builds[1].name, 'project1-merge')
274 self.assertTrue(self.job_has_changes(self.builds[1], B))
James E. Blairb02a3bb2012-07-30 17:49:55 -0700275
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700276 # Release the current merge builds
James E. Blair08d19992016-08-10 15:25:31 -0700277 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700278 self.waitUntilSettled()
279 # Release the merge job for project2 which is behind project1
James E. Blair08d19992016-08-10 15:25:31 -0700280 self.launch_server.release('.*-merge')
James E. Blairb02a3bb2012-07-30 17:49:55 -0700281 self.waitUntilSettled()
282
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700283 # All the test builds should be running:
James E. Blairb02a3bb2012-07-30 17:49:55 -0700284 # project1 (3) + project2 (3) + project (2) = 8
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400285 self.assertEqual(len(self.builds), 8)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700286
James E. Blair08d19992016-08-10 15:25:31 -0700287 self.launch_server.release()
James E. Blairb02a3bb2012-07-30 17:49:55 -0700288 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400289 self.assertEqual(len(self.builds), 0)
James E. Blairb02a3bb2012-07-30 17:49:55 -0700290
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400291 self.assertEqual(len(self.history), 11)
292 self.assertEqual(A.data['status'], 'MERGED')
293 self.assertEqual(B.data['status'], 'MERGED')
294 self.assertEqual(C.data['status'], 'MERGED')
295 self.assertEqual(A.reported, 2)
296 self.assertEqual(B.reported, 2)
297 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700298
James E. Blairec056492016-07-22 09:45:56 -0700299 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700300 def test_failed_change_at_head(self):
301 "Test that if a change at the head fails, jobs behind it are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700302
James E. Blair08d19992016-08-10 15:25:31 -0700303 self.launch_server.hold_jobs_in_build = True
James E. Blaird466dc42012-07-31 10:42:56 -0700304 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
305 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
306 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700307 A.addApproval('code-review', 2)
308 B.addApproval('code-review', 2)
309 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700310
James E. Blair08d19992016-08-10 15:25:31 -0700311 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700312
James E. Blair8b5408c2016-08-08 15:37:46 -0700313 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
314 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
315 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700316
317 self.waitUntilSettled()
James E. Blaird466dc42012-07-31 10:42:56 -0700318
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400319 self.assertEqual(len(self.builds), 1)
320 self.assertEqual(self.builds[0].name, 'project-merge')
321 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700322
James E. Blair08d19992016-08-10 15:25:31 -0700323 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700324 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700325 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700326 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700327 self.launch_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700328 self.waitUntilSettled()
329
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400330 self.assertEqual(len(self.builds), 6)
331 self.assertEqual(self.builds[0].name, 'project-test1')
332 self.assertEqual(self.builds[1].name, 'project-test2')
333 self.assertEqual(self.builds[2].name, 'project-test1')
334 self.assertEqual(self.builds[3].name, 'project-test2')
335 self.assertEqual(self.builds[4].name, 'project-test1')
336 self.assertEqual(self.builds[5].name, 'project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700337
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400338 self.release(self.builds[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700339 self.waitUntilSettled()
340
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400341 # project-test2, project-merge for B
342 self.assertEqual(len(self.builds), 2)
343 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4)
James E. Blaird466dc42012-07-31 10:42:56 -0700344
James E. Blair08d19992016-08-10 15:25:31 -0700345 self.launch_server.hold_jobs_in_build = False
346 self.launch_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700347 self.waitUntilSettled()
348
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400349 self.assertEqual(len(self.builds), 0)
350 self.assertEqual(len(self.history), 15)
351 self.assertEqual(A.data['status'], 'NEW')
352 self.assertEqual(B.data['status'], 'MERGED')
353 self.assertEqual(C.data['status'], 'MERGED')
354 self.assertEqual(A.reported, 2)
355 self.assertEqual(B.reported, 2)
356 self.assertEqual(C.reported, 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700357
James E. Blairec056492016-07-22 09:45:56 -0700358 @skip("Disabled for early v3 development")
James E. Blair0aac4872013-08-23 14:02:38 -0700359 def test_failed_change_in_middle(self):
360 "Test a failed change in the middle of the queue"
361
James E. Blair08d19992016-08-10 15:25:31 -0700362 self.launch_server.hold_jobs_in_build = True
James E. Blair0aac4872013-08-23 14:02:38 -0700363 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
364 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
365 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700366 A.addApproval('code-review', 2)
367 B.addApproval('code-review', 2)
368 C.addApproval('code-review', 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700369
James E. Blair08d19992016-08-10 15:25:31 -0700370 self.launch_server.failJob('project-test1', B)
James E. Blair0aac4872013-08-23 14:02:38 -0700371
James E. Blair8b5408c2016-08-08 15:37:46 -0700372 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
373 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
374 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair0aac4872013-08-23 14:02:38 -0700375
376 self.waitUntilSettled()
377
James E. Blair08d19992016-08-10 15:25:31 -0700378 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700379 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700380 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700381 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700382 self.launch_server.release('.*-merge')
James E. Blair0aac4872013-08-23 14:02:38 -0700383 self.waitUntilSettled()
384
385 self.assertEqual(len(self.builds), 6)
386 self.assertEqual(self.builds[0].name, 'project-test1')
387 self.assertEqual(self.builds[1].name, 'project-test2')
388 self.assertEqual(self.builds[2].name, 'project-test1')
389 self.assertEqual(self.builds[3].name, 'project-test2')
390 self.assertEqual(self.builds[4].name, 'project-test1')
391 self.assertEqual(self.builds[5].name, 'project-test2')
392
393 self.release(self.builds[2])
394 self.waitUntilSettled()
395
James E. Blair972e3c72013-08-29 12:04:55 -0700396 # project-test1 and project-test2 for A
397 # project-test2 for B
398 # project-merge for C (without B)
399 self.assertEqual(len(self.builds), 4)
James E. Blair0aac4872013-08-23 14:02:38 -0700400 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2)
401
James E. Blair08d19992016-08-10 15:25:31 -0700402 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -0700403 self.waitUntilSettled()
404
405 # project-test1 and project-test2 for A
406 # project-test2 for B
407 # project-test1 and project-test2 for C
408 self.assertEqual(len(self.builds), 5)
409
James E. Blair0aac4872013-08-23 14:02:38 -0700410 items = self.sched.layout.pipelines['gate'].getAllItems()
411 builds = items[0].current_build_set.getBuilds()
412 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
413 self.assertEqual(self.countJobResults(builds, None), 2)
414 builds = items[1].current_build_set.getBuilds()
415 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
416 self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1)
417 self.assertEqual(self.countJobResults(builds, None), 1)
418 builds = items[2].current_build_set.getBuilds()
419 self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1)
James E. Blair972e3c72013-08-29 12:04:55 -0700420 self.assertEqual(self.countJobResults(builds, None), 2)
James E. Blair0aac4872013-08-23 14:02:38 -0700421
James E. Blair08d19992016-08-10 15:25:31 -0700422 self.launch_server.hold_jobs_in_build = False
423 self.launch_server.release()
James E. Blair0aac4872013-08-23 14:02:38 -0700424 self.waitUntilSettled()
425
426 self.assertEqual(len(self.builds), 0)
427 self.assertEqual(len(self.history), 12)
428 self.assertEqual(A.data['status'], 'MERGED')
429 self.assertEqual(B.data['status'], 'NEW')
430 self.assertEqual(C.data['status'], 'MERGED')
431 self.assertEqual(A.reported, 2)
432 self.assertEqual(B.reported, 2)
433 self.assertEqual(C.reported, 2)
434
James E. Blairec056492016-07-22 09:45:56 -0700435 @skip("Disabled for early v3 development")
James E. Blaird466dc42012-07-31 10:42:56 -0700436 def test_failed_change_at_head_with_queue(self):
437 "Test that if a change at the head fails, queued jobs are canceled"
James E. Blaird466dc42012-07-31 10:42:56 -0700438
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700439 self.gearman_server.hold_jobs_in_queue = True
James E. Blaird466dc42012-07-31 10:42:56 -0700440 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
441 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
442 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700443 A.addApproval('code-review', 2)
444 B.addApproval('code-review', 2)
445 C.addApproval('code-review', 2)
James E. Blaird466dc42012-07-31 10:42:56 -0700446
James E. Blair08d19992016-08-10 15:25:31 -0700447 self.launch_server.failJob('project-test1', A)
James E. Blaird466dc42012-07-31 10:42:56 -0700448
James E. Blair8b5408c2016-08-08 15:37:46 -0700449 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
450 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
451 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blaird466dc42012-07-31 10:42:56 -0700452
453 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700454 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400455 self.assertEqual(len(self.builds), 0)
456 self.assertEqual(len(queue), 1)
457 self.assertEqual(queue[0].name, 'build:project-merge')
458 self.assertTrue(self.job_has_changes(queue[0], A))
James E. Blaird466dc42012-07-31 10:42:56 -0700459
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700460 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700461 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700462 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700463 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700464 self.gearman_server.release('.*-merge')
James E. Blaird466dc42012-07-31 10:42:56 -0700465 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700466 queue = self.gearman_server.getQueue()
James E. Blaird466dc42012-07-31 10:42:56 -0700467
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400468 self.assertEqual(len(self.builds), 0)
469 self.assertEqual(len(queue), 6)
470 self.assertEqual(queue[0].name, 'build:project-test1')
471 self.assertEqual(queue[1].name, 'build:project-test2')
472 self.assertEqual(queue[2].name, 'build:project-test1')
473 self.assertEqual(queue[3].name, 'build:project-test2')
474 self.assertEqual(queue[4].name, 'build:project-test1')
475 self.assertEqual(queue[5].name, 'build:project-test2')
James E. Blaird466dc42012-07-31 10:42:56 -0700476
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700477 self.release(queue[0])
James E. Blaird466dc42012-07-31 10:42:56 -0700478 self.waitUntilSettled()
479
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400480 self.assertEqual(len(self.builds), 0)
James E. Blair701c5b42013-06-06 09:34:59 -0700481 queue = self.gearman_server.getQueue()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400482 self.assertEqual(len(queue), 2) # project-test2, project-merge for B
483 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0)
James E. Blaird466dc42012-07-31 10:42:56 -0700484
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700485 self.gearman_server.hold_jobs_in_queue = False
486 self.gearman_server.release()
James E. Blaird466dc42012-07-31 10:42:56 -0700487 self.waitUntilSettled()
488
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400489 self.assertEqual(len(self.builds), 0)
490 self.assertEqual(len(self.history), 11)
491 self.assertEqual(A.data['status'], 'NEW')
492 self.assertEqual(B.data['status'], 'MERGED')
493 self.assertEqual(C.data['status'], 'MERGED')
494 self.assertEqual(A.reported, 2)
495 self.assertEqual(B.reported, 2)
496 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700497
James E. Blairec056492016-07-22 09:45:56 -0700498 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700499 def _test_time_database(self, iteration):
James E. Blair08d19992016-08-10 15:25:31 -0700500 self.launch_server.hold_jobs_in_build = True
James E. Blairce8a2132016-05-19 15:21:52 -0700501 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -0700502 A.addApproval('code-review', 2)
503 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairce8a2132016-05-19 15:21:52 -0700504 self.waitUntilSettled()
505 time.sleep(2)
506
507 data = json.loads(self.sched.formatStatusJSON())
508 found_job = None
509 for pipeline in data['pipelines']:
510 if pipeline['name'] != 'gate':
511 continue
512 for queue in pipeline['change_queues']:
513 for head in queue['heads']:
514 for item in head:
515 for job in item['jobs']:
516 if job['name'] == 'project-merge':
517 found_job = job
518 break
519
520 self.assertIsNotNone(found_job)
521 if iteration == 1:
522 self.assertIsNotNone(found_job['estimated_time'])
523 self.assertIsNone(found_job['remaining_time'])
524 else:
525 self.assertIsNotNone(found_job['estimated_time'])
526 self.assertTrue(found_job['estimated_time'] >= 2)
527 self.assertIsNotNone(found_job['remaining_time'])
528
James E. Blair08d19992016-08-10 15:25:31 -0700529 self.launch_server.hold_jobs_in_build = False
530 self.launch_server.release()
James E. Blairce8a2132016-05-19 15:21:52 -0700531 self.waitUntilSettled()
532
James E. Blairec056492016-07-22 09:45:56 -0700533 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700534 def test_time_database(self):
535 "Test the time database"
536
537 self._test_time_database(1)
538 self._test_time_database(2)
539
James E. Blairec056492016-07-22 09:45:56 -0700540 @skip("Disabled for early v3 development")
James E. Blairfef71632013-09-23 11:15:47 -0700541 def test_two_failed_changes_at_head(self):
542 "Test that changes are reparented correctly if 2 fail at head"
543
James E. Blair08d19992016-08-10 15:25:31 -0700544 self.launch_server.hold_jobs_in_build = True
James E. Blairfef71632013-09-23 11:15:47 -0700545 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
546 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
547 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700548 A.addApproval('code-review', 2)
549 B.addApproval('code-review', 2)
550 C.addApproval('code-review', 2)
James E. Blairfef71632013-09-23 11:15:47 -0700551
James E. Blair08d19992016-08-10 15:25:31 -0700552 self.launch_server.failJob('project-test1', A)
553 self.launch_server.failJob('project-test1', B)
James E. Blairfef71632013-09-23 11:15:47 -0700554
James E. Blair8b5408c2016-08-08 15:37:46 -0700555 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
556 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
557 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairfef71632013-09-23 11:15:47 -0700558 self.waitUntilSettled()
559
James E. Blair08d19992016-08-10 15:25:31 -0700560 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700561 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700562 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700563 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700564 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700565 self.waitUntilSettled()
566
567 self.assertEqual(len(self.builds), 6)
568 self.assertEqual(self.builds[0].name, 'project-test1')
569 self.assertEqual(self.builds[1].name, 'project-test2')
570 self.assertEqual(self.builds[2].name, 'project-test1')
571 self.assertEqual(self.builds[3].name, 'project-test2')
572 self.assertEqual(self.builds[4].name, 'project-test1')
573 self.assertEqual(self.builds[5].name, 'project-test2')
574
575 self.assertTrue(self.job_has_changes(self.builds[0], A))
576 self.assertTrue(self.job_has_changes(self.builds[2], A))
577 self.assertTrue(self.job_has_changes(self.builds[2], B))
578 self.assertTrue(self.job_has_changes(self.builds[4], A))
579 self.assertTrue(self.job_has_changes(self.builds[4], B))
580 self.assertTrue(self.job_has_changes(self.builds[4], C))
581
582 # Fail change B first
583 self.release(self.builds[2])
584 self.waitUntilSettled()
585
586 # restart of C after B failure
James E. Blair08d19992016-08-10 15:25:31 -0700587 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700588 self.waitUntilSettled()
589
590 self.assertEqual(len(self.builds), 5)
591 self.assertEqual(self.builds[0].name, 'project-test1')
592 self.assertEqual(self.builds[1].name, 'project-test2')
593 self.assertEqual(self.builds[2].name, 'project-test2')
594 self.assertEqual(self.builds[3].name, 'project-test1')
595 self.assertEqual(self.builds[4].name, 'project-test2')
596
597 self.assertTrue(self.job_has_changes(self.builds[1], A))
598 self.assertTrue(self.job_has_changes(self.builds[2], A))
599 self.assertTrue(self.job_has_changes(self.builds[2], B))
600 self.assertTrue(self.job_has_changes(self.builds[4], A))
601 self.assertFalse(self.job_has_changes(self.builds[4], B))
602 self.assertTrue(self.job_has_changes(self.builds[4], C))
603
604 # Finish running all passing jobs for change A
605 self.release(self.builds[1])
606 self.waitUntilSettled()
607 # Fail and report change A
608 self.release(self.builds[0])
609 self.waitUntilSettled()
610
611 # restart of B,C after A failure
James E. Blair08d19992016-08-10 15:25:31 -0700612 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700613 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700614 self.launch_server.release('.*-merge')
James E. Blairfef71632013-09-23 11:15:47 -0700615 self.waitUntilSettled()
616
617 self.assertEqual(len(self.builds), 4)
618 self.assertEqual(self.builds[0].name, 'project-test1') # B
619 self.assertEqual(self.builds[1].name, 'project-test2') # B
620 self.assertEqual(self.builds[2].name, 'project-test1') # C
621 self.assertEqual(self.builds[3].name, 'project-test2') # C
622
623 self.assertFalse(self.job_has_changes(self.builds[1], A))
624 self.assertTrue(self.job_has_changes(self.builds[1], B))
625 self.assertFalse(self.job_has_changes(self.builds[1], C))
626
627 self.assertFalse(self.job_has_changes(self.builds[2], A))
628 # After A failed and B and C restarted, B should be back in
629 # C's tests because it has not failed yet.
630 self.assertTrue(self.job_has_changes(self.builds[2], B))
631 self.assertTrue(self.job_has_changes(self.builds[2], C))
632
James E. Blair08d19992016-08-10 15:25:31 -0700633 self.launch_server.hold_jobs_in_build = False
634 self.launch_server.release()
James E. Blairfef71632013-09-23 11:15:47 -0700635 self.waitUntilSettled()
636
637 self.assertEqual(len(self.builds), 0)
638 self.assertEqual(len(self.history), 21)
639 self.assertEqual(A.data['status'], 'NEW')
640 self.assertEqual(B.data['status'], 'NEW')
641 self.assertEqual(C.data['status'], 'MERGED')
642 self.assertEqual(A.reported, 2)
643 self.assertEqual(B.reported, 2)
644 self.assertEqual(C.reported, 2)
645
James E. Blairec056492016-07-22 09:45:56 -0700646 @skip("Disabled for early v3 development")
James E. Blairce8a2132016-05-19 15:21:52 -0700647 def test_parse_skip_if(self):
648 job_yaml = """
649jobs:
650 - name: job_name
651 skip-if:
652 - project: ^project_name$
653 branch: ^stable/icehouse$
654 all-files-match-any:
655 - ^filename$
656 - project: ^project2_name$
657 all-files-match-any:
658 - ^filename2$
659 """.strip()
660 data = yaml.load(job_yaml)
661 config_job = data.get('jobs')[0]
662 cm = zuul.change_matcher
663 expected = cm.MatchAny([
664 cm.MatchAll([
665 cm.ProjectMatcher('^project_name$'),
666 cm.BranchMatcher('^stable/icehouse$'),
667 cm.MatchAllFiles([cm.FileMatcher('^filename$')]),
668 ]),
669 cm.MatchAll([
670 cm.ProjectMatcher('^project2_name$'),
671 cm.MatchAllFiles([cm.FileMatcher('^filename2$')]),
672 ]),
673 ])
674 matcher = self.sched._parseSkipIf(config_job)
675 self.assertEqual(expected, matcher)
676
James E. Blairec056492016-07-22 09:45:56 -0700677 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700678 def test_patch_order(self):
679 "Test that dependent patches are tested in the right order"
680 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
681 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
682 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700683 A.addApproval('code-review', 2)
684 B.addApproval('code-review', 2)
685 C.addApproval('code-review', 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700686
687 M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2')
688 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
689 M2.setMerged()
690 M1.setMerged()
691
692 # C -> B -> A -> M1 -> M2
693 # M2 is here to make sure it is never queried. If it is, it
694 # means zuul is walking down the entire history of merged
695 # changes.
696
697 C.setDependsOn(B, 1)
698 B.setDependsOn(A, 1)
699 A.setDependsOn(M1, 1)
700 M1.setDependsOn(M2, 1)
701
James E. Blair8b5408c2016-08-08 15:37:46 -0700702 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700703
704 self.waitUntilSettled()
705
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400706 self.assertEqual(A.data['status'], 'NEW')
707 self.assertEqual(B.data['status'], 'NEW')
708 self.assertEqual(C.data['status'], 'NEW')
James E. Blair8c803f82012-07-31 16:25:42 -0700709
James E. Blair8b5408c2016-08-08 15:37:46 -0700710 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
711 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8c803f82012-07-31 16:25:42 -0700712
713 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400714 self.assertEqual(M2.queried, 0)
715 self.assertEqual(A.data['status'], 'MERGED')
716 self.assertEqual(B.data['status'], 'MERGED')
717 self.assertEqual(C.data['status'], 'MERGED')
718 self.assertEqual(A.reported, 2)
719 self.assertEqual(B.reported, 2)
720 self.assertEqual(C.reported, 2)
James E. Blair8c803f82012-07-31 16:25:42 -0700721
James E. Blairec056492016-07-22 09:45:56 -0700722 @skip("Disabled for early v3 development")
James E. Blair063672f2015-01-29 13:09:12 -0800723 def test_needed_changes_enqueue(self):
724 "Test that a needed change is enqueued ahead"
725 # A Given a git tree like this, if we enqueue
726 # / \ change C, we should walk up and down the tree
727 # B G and enqueue changes in the order ABCDEFG.
728 # /|\ This is also the order that you would get if
729 # *C E F you enqueued changes in the order ABCDEFG, so
730 # / the ordering is stable across re-enqueue events.
731 # D
732
733 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
734 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
735 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
736 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
737 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
738 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
739 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
740 B.setDependsOn(A, 1)
741 C.setDependsOn(B, 1)
742 D.setDependsOn(C, 1)
743 E.setDependsOn(B, 1)
744 F.setDependsOn(B, 1)
745 G.setDependsOn(A, 1)
746
James E. Blair8b5408c2016-08-08 15:37:46 -0700747 A.addApproval('code-review', 2)
748 B.addApproval('code-review', 2)
749 C.addApproval('code-review', 2)
750 D.addApproval('code-review', 2)
751 E.addApproval('code-review', 2)
752 F.addApproval('code-review', 2)
753 G.addApproval('code-review', 2)
754 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800755
756 self.waitUntilSettled()
757
758 self.assertEqual(A.data['status'], 'NEW')
759 self.assertEqual(B.data['status'], 'NEW')
760 self.assertEqual(C.data['status'], 'NEW')
761 self.assertEqual(D.data['status'], 'NEW')
762 self.assertEqual(E.data['status'], 'NEW')
763 self.assertEqual(F.data['status'], 'NEW')
764 self.assertEqual(G.data['status'], 'NEW')
765
766 # We're about to add approvals to changes without adding the
767 # triggering events to Zuul, so that we can be sure that it is
768 # enqueing the changes based on dependencies, not because of
769 # triggering events. Since it will have the changes cached
770 # already (without approvals), we need to clear the cache
771 # first.
Joshua Hesketh4bd7da32016-02-17 20:58:47 +1100772 for connection in self.connections.values():
773 connection.maintainCache([])
James E. Blair063672f2015-01-29 13:09:12 -0800774
James E. Blair08d19992016-08-10 15:25:31 -0700775 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -0700776 A.addApproval('approved', 1)
777 B.addApproval('approved', 1)
778 D.addApproval('approved', 1)
779 E.addApproval('approved', 1)
780 F.addApproval('approved', 1)
781 G.addApproval('approved', 1)
782 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair063672f2015-01-29 13:09:12 -0800783
784 for x in range(8):
James E. Blair08d19992016-08-10 15:25:31 -0700785 self.launch_server.release('.*-merge')
James E. Blair063672f2015-01-29 13:09:12 -0800786 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -0700787 self.launch_server.hold_jobs_in_build = False
788 self.launch_server.release()
James E. Blair063672f2015-01-29 13:09:12 -0800789 self.waitUntilSettled()
790
791 self.assertEqual(A.data['status'], 'MERGED')
792 self.assertEqual(B.data['status'], 'MERGED')
793 self.assertEqual(C.data['status'], 'MERGED')
794 self.assertEqual(D.data['status'], 'MERGED')
795 self.assertEqual(E.data['status'], 'MERGED')
796 self.assertEqual(F.data['status'], 'MERGED')
797 self.assertEqual(G.data['status'], 'MERGED')
798 self.assertEqual(A.reported, 2)
799 self.assertEqual(B.reported, 2)
800 self.assertEqual(C.reported, 2)
801 self.assertEqual(D.reported, 2)
802 self.assertEqual(E.reported, 2)
803 self.assertEqual(F.reported, 2)
804 self.assertEqual(G.reported, 2)
805 self.assertEqual(self.history[6].changes,
806 '1,1 2,1 3,1 4,1 5,1 6,1 7,1')
807
James E. Blairec056492016-07-22 09:45:56 -0700808 @skip("Disabled for early v3 development")
Joshua Hesketh850ccb62014-11-27 11:31:02 +1100809 def test_source_cache(self):
810 "Test that the source cache operates correctly"
James E. Blair08d19992016-08-10 15:25:31 -0700811 self.launch_server.hold_jobs_in_build = True
James E. Blair0e933c52013-07-11 10:18:52 -0700812
813 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
814 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
815 X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X')
James E. Blair8b5408c2016-08-08 15:37:46 -0700816 A.addApproval('code-review', 2)
817 B.addApproval('code-review', 2)
James E. Blair0e933c52013-07-11 10:18:52 -0700818
819 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
820 M1.setMerged()
821
822 B.setDependsOn(A, 1)
823 A.setDependsOn(M1, 1)
824
James E. Blair8b5408c2016-08-08 15:37:46 -0700825 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700826 self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1))
827
828 self.waitUntilSettled()
829
830 for build in self.builds:
831 if build.parameters['ZUUL_PIPELINE'] == 'check':
832 build.release()
833 self.waitUntilSettled()
834 for build in self.builds:
835 if build.parameters['ZUUL_PIPELINE'] == 'check':
836 build.release()
837 self.waitUntilSettled()
838
James E. Blair8b5408c2016-08-08 15:37:46 -0700839 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair0e933c52013-07-11 10:18:52 -0700840 self.waitUntilSettled()
841
Joshua Hesketh352264b2015-08-11 23:42:08 +1000842 self.log.debug("len %s" % self.fake_gerrit._change_cache.keys())
James E. Blair0e933c52013-07-11 10:18:52 -0700843 # there should still be changes in the cache
Joshua Hesketh352264b2015-08-11 23:42:08 +1000844 self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0)
James E. Blair0e933c52013-07-11 10:18:52 -0700845
James E. Blair08d19992016-08-10 15:25:31 -0700846 self.launch_server.hold_jobs_in_build = False
847 self.launch_server.release()
James E. Blair0e933c52013-07-11 10:18:52 -0700848 self.waitUntilSettled()
849
850 self.assertEqual(A.data['status'], 'MERGED')
851 self.assertEqual(B.data['status'], 'MERGED')
852 self.assertEqual(A.queried, 2) # Initial and isMerged
853 self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged
854
James E. Blairec056492016-07-22 09:45:56 -0700855 @skip("Disabled for early v3 development")
James E. Blair8c803f82012-07-31 16:25:42 -0700856 def test_can_merge(self):
James E. Blair4886cc12012-07-18 15:39:41 -0700857 "Test whether a change is ready to merge"
James E. Blair8c803f82012-07-31 16:25:42 -0700858 # TODO: move to test_gerrit (this is a unit test!)
859 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairc0dedf82014-08-06 09:37:52 -0700860 source = self.sched.layout.pipelines['gate'].source
861 a = source._getChange(1, 2)
James E. Blaireff88162013-07-01 12:44:14 -0400862 mgr = self.sched.layout.pipelines['gate'].manager
James E. Blairc0dedf82014-08-06 09:37:52 -0700863 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700864
James E. Blair8b5408c2016-08-08 15:37:46 -0700865 A.addApproval('code-review', 2)
James E. Blairc0dedf82014-08-06 09:37:52 -0700866 a = source._getChange(1, 2, refresh=True)
867 self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair8c803f82012-07-31 16:25:42 -0700868
James E. Blair8b5408c2016-08-08 15:37:46 -0700869 A.addApproval('approved', 1)
James E. Blairc0dedf82014-08-06 09:37:52 -0700870 a = source._getChange(1, 2, refresh=True)
871 self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
James E. Blair4886cc12012-07-18 15:39:41 -0700872
James E. Blairec056492016-07-22 09:45:56 -0700873 @skip("Disabled for early v3 development")
James E. Blair4886cc12012-07-18 15:39:41 -0700874 def test_build_configuration(self):
875 "Test that zuul merges the right commits for testing"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700876
877 self.gearman_server.hold_jobs_in_queue = True
James E. Blair4886cc12012-07-18 15:39:41 -0700878 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
879 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
880 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700881 A.addApproval('code-review', 2)
882 B.addApproval('code-review', 2)
883 C.addApproval('code-review', 2)
884 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
885 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
886 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair4886cc12012-07-18 15:39:41 -0700887 self.waitUntilSettled()
888
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700889 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700890 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700891 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700892 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700893 self.gearman_server.release('.*-merge')
James E. Blair4886cc12012-07-18 15:39:41 -0700894 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -0700895 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700896 ref = self.getParameter(queue[-1], 'ZUUL_REF')
897 self.gearman_server.hold_jobs_in_queue = False
898 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700899 self.waitUntilSettled()
James E. Blair4886cc12012-07-18 15:39:41 -0700900
Monty Taylorbc758832013-06-17 17:22:42 -0400901 path = os.path.join(self.git_root, "org/project")
James E. Blair4886cc12012-07-18 15:39:41 -0700902 repo = git.Repo(path)
903 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
904 repo_messages.reverse()
James E. Blair4886cc12012-07-18 15:39:41 -0700905 correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400906 self.assertEqual(repo_messages, correct_messages)
James E. Blair973721f2012-08-15 10:19:43 -0700907
James E. Blairec056492016-07-22 09:45:56 -0700908 @skip("Disabled for early v3 development")
James E. Blair973721f2012-08-15 10:19:43 -0700909 def test_build_configuration_conflict(self):
910 "Test that merge conflicts are handled"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700911
912 self.gearman_server.hold_jobs_in_queue = True
James E. Blair6736beb2013-07-11 15:18:15 -0700913 A = self.fake_gerrit.addFakeChange('org/conflict-project',
914 'master', 'A')
James E. Blair973721f2012-08-15 10:19:43 -0700915 A.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700916 B = self.fake_gerrit.addFakeChange('org/conflict-project',
917 'master', 'B')
James E. Blair973721f2012-08-15 10:19:43 -0700918 B.addPatchset(['conflict'])
James E. Blair6736beb2013-07-11 15:18:15 -0700919 C = self.fake_gerrit.addFakeChange('org/conflict-project',
920 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -0700921 A.addApproval('code-review', 2)
922 B.addApproval('code-review', 2)
923 C.addApproval('code-review', 2)
924 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
925 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
926 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair973721f2012-08-15 10:19:43 -0700927 self.waitUntilSettled()
928
James E. Blair6736beb2013-07-11 15:18:15 -0700929 self.assertEqual(A.reported, 1)
930 self.assertEqual(B.reported, 1)
931 self.assertEqual(C.reported, 1)
932
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700933 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700934 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700935 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700936 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700937 self.gearman_server.release('.*-merge')
James E. Blair973721f2012-08-15 10:19:43 -0700938 self.waitUntilSettled()
James E. Blair972e3c72013-08-29 12:04:55 -0700939
940 self.assertEqual(len(self.history), 2) # A and C merge jobs
941
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700942 self.gearman_server.hold_jobs_in_queue = False
943 self.gearman_server.release()
James E. Blair973721f2012-08-15 10:19:43 -0700944 self.waitUntilSettled()
945
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400946 self.assertEqual(A.data['status'], 'MERGED')
947 self.assertEqual(B.data['status'], 'NEW')
948 self.assertEqual(C.data['status'], 'MERGED')
949 self.assertEqual(A.reported, 2)
950 self.assertEqual(B.reported, 2)
951 self.assertEqual(C.reported, 2)
James E. Blair972e3c72013-08-29 12:04:55 -0700952 self.assertEqual(len(self.history), 6)
James E. Blair6736beb2013-07-11 15:18:15 -0700953
James E. Blairec056492016-07-22 09:45:56 -0700954 @skip("Disabled for early v3 development")
James E. Blairdaabed22012-08-15 15:38:57 -0700955 def test_post(self):
956 "Test that post jobs run"
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700957
Zhongyue Luo5d556072012-09-21 02:00:47 +0900958 e = {
959 "type": "ref-updated",
960 "submitter": {
961 "name": "User Name",
962 },
963 "refUpdate": {
964 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
965 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
966 "refName": "master",
967 "project": "org/project",
968 }
969 }
James E. Blairdaabed22012-08-15 15:38:57 -0700970 self.fake_gerrit.addEvent(e)
971 self.waitUntilSettled()
972
Monty Taylor6bef8ef2013-06-02 08:17:12 -0400973 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -0400974 self.assertEqual(len(self.history), 1)
975 self.assertIn('project-post', job_names)
James E. Blairc6294a52012-08-17 10:19:48 -0700976
James E. Blairec056492016-07-22 09:45:56 -0700977 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -0700978 def test_post_ignore_deletes(self):
979 "Test that deleting refs does not trigger post jobs"
980
981 e = {
982 "type": "ref-updated",
983 "submitter": {
984 "name": "User Name",
985 },
986 "refUpdate": {
987 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
988 "newRev": "0000000000000000000000000000000000000000",
989 "refName": "master",
990 "project": "org/project",
991 }
992 }
993 self.fake_gerrit.addEvent(e)
994 self.waitUntilSettled()
995
996 job_names = [x.name for x in self.history]
997 self.assertEqual(len(self.history), 0)
998 self.assertNotIn('project-post', job_names)
999
James E. Blairec056492016-07-22 09:45:56 -07001000 @skip("Disabled for early v3 development")
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001001 def test_post_ignore_deletes_negative(self):
1002 "Test that deleting refs does trigger post jobs"
1003
James E. Blairf84026c2015-12-08 16:11:46 -08001004 self.updateConfigLayout(
1005 'tests/fixtures/layout-dont-ignore-deletes.yaml')
K Jonathan Harkerf95e7232015-04-29 13:33:16 -07001006 self.sched.reconfigure(self.config)
1007
1008 e = {
1009 "type": "ref-updated",
1010 "submitter": {
1011 "name": "User Name",
1012 },
1013 "refUpdate": {
1014 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1015 "newRev": "0000000000000000000000000000000000000000",
1016 "refName": "master",
1017 "project": "org/project",
1018 }
1019 }
1020 self.fake_gerrit.addEvent(e)
1021 self.waitUntilSettled()
1022
1023 job_names = [x.name for x in self.history]
1024 self.assertEqual(len(self.history), 1)
1025 self.assertIn('project-post', job_names)
1026
James E. Blairec056492016-07-22 09:45:56 -07001027 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001028 def test_build_configuration_branch(self):
1029 "Test that the right commits are on alternate branches"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001030
1031 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001032 A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A')
1033 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1034 C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001035 A.addApproval('code-review', 2)
1036 B.addApproval('code-review', 2)
1037 C.addApproval('code-review', 2)
1038 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1039 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1040 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001041 self.waitUntilSettled()
1042
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001043 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001044 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001045 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001046 self.waitUntilSettled()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001047 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001048 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001049 queue = self.gearman_server.getQueue()
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001050 ref = self.getParameter(queue[-1], 'ZUUL_REF')
1051 self.gearman_server.hold_jobs_in_queue = False
1052 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001053 self.waitUntilSettled()
1054
Monty Taylorbc758832013-06-17 17:22:42 -04001055 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001056 repo = git.Repo(path)
1057 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
1058 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001059 correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001060 self.assertEqual(repo_messages, correct_messages)
James E. Blairc6294a52012-08-17 10:19:48 -07001061
James E. Blairec056492016-07-22 09:45:56 -07001062 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001063 def test_build_configuration_branch_interaction(self):
1064 "Test that switching between branches works"
1065 self.test_build_configuration()
1066 self.test_build_configuration_branch()
1067 # C has been merged, undo that
Monty Taylorbc758832013-06-17 17:22:42 -04001068 path = os.path.join(self.upstream_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001069 repo = git.Repo(path)
1070 repo.heads.master.commit = repo.commit('init')
1071 self.test_build_configuration()
1072
James E. Blairec056492016-07-22 09:45:56 -07001073 @skip("Disabled for early v3 development")
James E. Blairc6294a52012-08-17 10:19:48 -07001074 def test_build_configuration_multi_branch(self):
1075 "Test that dependent changes on multiple branches are merged"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001076
1077 self.gearman_server.hold_jobs_in_queue = True
James E. Blairc6294a52012-08-17 10:19:48 -07001078 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1079 B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B')
1080 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001081 A.addApproval('code-review', 2)
1082 B.addApproval('code-review', 2)
1083 C.addApproval('code-review', 2)
1084 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1085 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1086 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairc6294a52012-08-17 10:19:48 -07001087 self.waitUntilSettled()
James E. Blairbb1fe502014-03-04 10:15:06 -08001088 queue = self.gearman_server.getQueue()
1089 job_A = None
1090 for job in queue:
1091 if 'project-merge' in job.name:
1092 job_A = job
1093 ref_A = self.getParameter(job_A, 'ZUUL_REF')
1094 commit_A = self.getParameter(job_A, 'ZUUL_COMMIT')
1095 self.log.debug("Got Zuul ref for change A: %s" % ref_A)
1096 self.log.debug("Got Zuul commit for change A: %s" % commit_A)
James E. Blairc6294a52012-08-17 10:19:48 -07001097
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001098 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001099 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001100 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001101 job_B = None
1102 for job in queue:
1103 if 'project-merge' in job.name:
1104 job_B = job
1105 ref_B = self.getParameter(job_B, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001106 commit_B = self.getParameter(job_B, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001107 self.log.debug("Got Zuul ref for change B: %s" % ref_B)
James E. Blairbb1fe502014-03-04 10:15:06 -08001108 self.log.debug("Got Zuul commit for change B: %s" % commit_B)
1109
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001110 self.gearman_server.release('.*-merge')
James E. Blairc6294a52012-08-17 10:19:48 -07001111 self.waitUntilSettled()
James E. Blair701c5b42013-06-06 09:34:59 -07001112 queue = self.gearman_server.getQueue()
James E. Blaird320d7e2013-07-30 16:36:20 -07001113 for job in queue:
1114 if 'project-merge' in job.name:
1115 job_C = job
1116 ref_C = self.getParameter(job_C, 'ZUUL_REF')
James E. Blairbb1fe502014-03-04 10:15:06 -08001117 commit_C = self.getParameter(job_C, 'ZUUL_COMMIT')
James E. Blairf750aa02013-07-15 14:11:24 -07001118 self.log.debug("Got Zuul ref for change C: %s" % ref_C)
James E. Blairbb1fe502014-03-04 10:15:06 -08001119 self.log.debug("Got Zuul commit for change C: %s" % commit_C)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001120 self.gearman_server.hold_jobs_in_queue = False
1121 self.gearman_server.release()
James E. Blairc6294a52012-08-17 10:19:48 -07001122 self.waitUntilSettled()
1123
Monty Taylorbc758832013-06-17 17:22:42 -04001124 path = os.path.join(self.git_root, "org/project")
James E. Blairc6294a52012-08-17 10:19:48 -07001125 repo = git.Repo(path)
1126
1127 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001128 for c in repo.iter_commits(ref_C)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001129 repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)]
James E. Blairc6294a52012-08-17 10:19:48 -07001130 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001131 correct_messages = ['initial commit', 'A-1', 'C-1']
James E. Blairbb1fe502014-03-04 10:15:06 -08001132 # Ensure the right commits are in the history for this ref
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001133 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001134 # Ensure ZUUL_REF -> ZUUL_COMMIT
1135 self.assertEqual(repo_shas[0], commit_C)
James E. Blairc6294a52012-08-17 10:19:48 -07001136
1137 repo_messages = [c.message.strip()
James E. Blairf750aa02013-07-15 14:11:24 -07001138 for c in repo.iter_commits(ref_B)]
James E. Blairbb1fe502014-03-04 10:15:06 -08001139 repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)]
James E. Blairc6294a52012-08-17 10:19:48 -07001140 repo_messages.reverse()
James E. Blairc6294a52012-08-17 10:19:48 -07001141 correct_messages = ['initial commit', 'mp commit', 'B-1']
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001142 self.assertEqual(repo_messages, correct_messages)
James E. Blairbb1fe502014-03-04 10:15:06 -08001143 self.assertEqual(repo_shas[0], commit_B)
1144
1145 repo_messages = [c.message.strip()
1146 for c in repo.iter_commits(ref_A)]
1147 repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)]
1148 repo_messages.reverse()
1149 correct_messages = ['initial commit', 'A-1']
1150 self.assertEqual(repo_messages, correct_messages)
1151 self.assertEqual(repo_shas[0], commit_A)
1152
1153 self.assertNotEqual(ref_A, ref_B, ref_C)
1154 self.assertNotEqual(commit_A, commit_B, commit_C)
James E. Blair7f71c802012-08-22 13:04:32 -07001155
James E. Blairec056492016-07-22 09:45:56 -07001156 @skip("Disabled for early v3 development")
James E. Blair7f71c802012-08-22 13:04:32 -07001157 def test_one_job_project(self):
1158 "Test that queueing works with one job"
1159 A = self.fake_gerrit.addFakeChange('org/one-job-project',
1160 'master', 'A')
1161 B = self.fake_gerrit.addFakeChange('org/one-job-project',
1162 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07001163 A.addApproval('code-review', 2)
1164 B.addApproval('code-review', 2)
1165 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1166 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair7f71c802012-08-22 13:04:32 -07001167 self.waitUntilSettled()
1168
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001169 self.assertEqual(A.data['status'], 'MERGED')
1170 self.assertEqual(A.reported, 2)
1171 self.assertEqual(B.data['status'], 'MERGED')
1172 self.assertEqual(B.reported, 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001173
James E. Blairec056492016-07-22 09:45:56 -07001174 @skip("Disabled for early v3 development")
Antoine Musso80edd5a2013-02-13 15:37:53 +01001175 def test_job_from_templates_launched(self):
1176 "Test whether a job generated via a template can be launched"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001177
Antoine Musso80edd5a2013-02-13 15:37:53 +01001178 A = self.fake_gerrit.addFakeChange(
1179 'org/templated-project', 'master', 'A')
1180 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1181 self.waitUntilSettled()
Antoine Musso80edd5a2013-02-13 15:37:53 +01001182
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001183 self.assertEqual(self.getJobFromHistory('project-test1').result,
1184 'SUCCESS')
1185 self.assertEqual(self.getJobFromHistory('project-test2').result,
1186 'SUCCESS')
Antoine Musso80edd5a2013-02-13 15:37:53 +01001187
James E. Blairec056492016-07-22 09:45:56 -07001188 @skip("Disabled for early v3 development")
James E. Blair3e98c022013-12-16 15:25:38 -08001189 def test_layered_templates(self):
1190 "Test whether a job generated via a template can be launched"
1191
1192 A = self.fake_gerrit.addFakeChange(
1193 'org/layered-project', 'master', 'A')
1194 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1195 self.waitUntilSettled()
1196
1197 self.assertEqual(self.getJobFromHistory('project-test1').result,
1198 'SUCCESS')
1199 self.assertEqual(self.getJobFromHistory('project-test2').result,
1200 'SUCCESS')
James E. Blairaea6cf62013-12-16 15:38:12 -08001201 self.assertEqual(self.getJobFromHistory('layered-project-test3'
1202 ).result, 'SUCCESS')
1203 self.assertEqual(self.getJobFromHistory('layered-project-test4'
1204 ).result, 'SUCCESS')
James E. Blair12a92b12014-03-26 11:54:53 -07001205 self.assertEqual(self.getJobFromHistory('layered-project-foo-test5'
1206 ).result, 'SUCCESS')
James E. Blair3e98c022013-12-16 15:25:38 -08001207 self.assertEqual(self.getJobFromHistory('project-test6').result,
1208 'SUCCESS')
1209
James E. Blairec056492016-07-22 09:45:56 -07001210 @skip("Disabled for early v3 development")
James E. Blaircaec0c52012-08-22 14:52:22 -07001211 def test_dependent_changes_dequeue(self):
1212 "Test that dependent patches are not needlessly tested"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001213
James E. Blaircaec0c52012-08-22 14:52:22 -07001214 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1215 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1216 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001217 A.addApproval('code-review', 2)
1218 B.addApproval('code-review', 2)
1219 C.addApproval('code-review', 2)
James E. Blaircaec0c52012-08-22 14:52:22 -07001220
1221 M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1')
1222 M1.setMerged()
1223
1224 # C -> B -> A -> M1
1225
1226 C.setDependsOn(B, 1)
1227 B.setDependsOn(A, 1)
1228 A.setDependsOn(M1, 1)
1229
James E. Blair08d19992016-08-10 15:25:31 -07001230 self.launch_server.failJob('project-merge', A)
James E. Blaircaec0c52012-08-22 14:52:22 -07001231
James E. Blair8b5408c2016-08-08 15:37:46 -07001232 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1233 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1234 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircaec0c52012-08-22 14:52:22 -07001235
1236 self.waitUntilSettled()
1237
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001238 self.assertEqual(A.data['status'], 'NEW')
1239 self.assertEqual(A.reported, 2)
1240 self.assertEqual(B.data['status'], 'NEW')
1241 self.assertEqual(B.reported, 2)
1242 self.assertEqual(C.data['status'], 'NEW')
1243 self.assertEqual(C.reported, 2)
1244 self.assertEqual(len(self.history), 1)
James E. Blairec590122012-08-22 15:19:31 -07001245
James E. Blairec056492016-07-22 09:45:56 -07001246 @skip("Disabled for early v3 development")
James E. Blair972e3c72013-08-29 12:04:55 -07001247 def test_failing_dependent_changes(self):
1248 "Test that failing dependent patches are taken out of stream"
James E. Blair08d19992016-08-10 15:25:31 -07001249 self.launch_server.hold_jobs_in_build = True
James E. Blair972e3c72013-08-29 12:04:55 -07001250 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1251 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1252 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1253 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
1254 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
James E. Blair8b5408c2016-08-08 15:37:46 -07001255 A.addApproval('code-review', 2)
1256 B.addApproval('code-review', 2)
1257 C.addApproval('code-review', 2)
1258 D.addApproval('code-review', 2)
1259 E.addApproval('code-review', 2)
James E. Blair972e3c72013-08-29 12:04:55 -07001260
1261 # E, D -> C -> B, A
1262
1263 D.setDependsOn(C, 1)
1264 C.setDependsOn(B, 1)
1265
James E. Blair08d19992016-08-10 15:25:31 -07001266 self.launch_server.failJob('project-test1', B)
James E. Blair972e3c72013-08-29 12:04:55 -07001267
James E. Blair8b5408c2016-08-08 15:37:46 -07001268 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1269 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
1270 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1271 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1272 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair972e3c72013-08-29 12:04:55 -07001273
1274 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001275 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001276 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001277 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001278 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001279 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001280 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001281 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001282 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001283 self.launch_server.release('.*-merge')
James E. Blair972e3c72013-08-29 12:04:55 -07001284 self.waitUntilSettled()
1285
James E. Blair08d19992016-08-10 15:25:31 -07001286 self.launch_server.hold_jobs_in_build = False
James E. Blair972e3c72013-08-29 12:04:55 -07001287 for build in self.builds:
1288 if build.parameters['ZUUL_CHANGE'] != '1':
1289 build.release()
1290 self.waitUntilSettled()
1291
James E. Blair08d19992016-08-10 15:25:31 -07001292 self.launch_server.release()
James E. Blair972e3c72013-08-29 12:04:55 -07001293 self.waitUntilSettled()
1294
1295 self.assertEqual(A.data['status'], 'MERGED')
1296 self.assertEqual(A.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001297 self.assertIn('Build succeeded', A.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001298 self.assertEqual(B.data['status'], 'NEW')
1299 self.assertEqual(B.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001300 self.assertIn('Build failed', B.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001301 self.assertEqual(C.data['status'], 'NEW')
1302 self.assertEqual(C.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001303 self.assertIn('depends on a change', C.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001304 self.assertEqual(D.data['status'], 'NEW')
1305 self.assertEqual(D.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001306 self.assertIn('depends on a change', D.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001307 self.assertEqual(E.data['status'], 'MERGED')
1308 self.assertEqual(E.reported, 2)
Jeremy Stanley10837132014-08-02 16:10:56 +00001309 self.assertIn('Build succeeded', E.messages[1])
James E. Blair972e3c72013-08-29 12:04:55 -07001310 self.assertEqual(len(self.history), 18)
1311
James E. Blairec056492016-07-22 09:45:56 -07001312 @skip("Disabled for early v3 development")
James E. Blairec590122012-08-22 15:19:31 -07001313 def test_head_is_dequeued_once(self):
James E. Blair2fa50962013-01-30 21:50:41 -08001314 "Test that if a change at the head fails it is dequeued only once"
James E. Blairec590122012-08-22 15:19:31 -07001315 # If it's dequeued more than once, we should see extra
1316 # aborted jobs.
James E. Blairec590122012-08-22 15:19:31 -07001317
James E. Blair08d19992016-08-10 15:25:31 -07001318 self.launch_server.hold_jobs_in_build = True
James E. Blairec590122012-08-22 15:19:31 -07001319 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1320 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1321 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001322 A.addApproval('code-review', 2)
1323 B.addApproval('code-review', 2)
1324 C.addApproval('code-review', 2)
James E. Blairec590122012-08-22 15:19:31 -07001325
James E. Blair08d19992016-08-10 15:25:31 -07001326 self.launch_server.failJob('project1-test1', A)
1327 self.launch_server.failJob('project1-test2', A)
1328 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairec590122012-08-22 15:19:31 -07001329
James E. Blair8b5408c2016-08-08 15:37:46 -07001330 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1331 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1332 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blairec590122012-08-22 15:19:31 -07001333
1334 self.waitUntilSettled()
James E. Blairec590122012-08-22 15:19:31 -07001335
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001336 self.assertEqual(len(self.builds), 1)
1337 self.assertEqual(self.builds[0].name, 'project1-merge')
1338 self.assertTrue(self.job_has_changes(self.builds[0], A))
James E. Blairec590122012-08-22 15:19:31 -07001339
James E. Blair08d19992016-08-10 15:25:31 -07001340 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001341 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001342 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001343 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001344 self.launch_server.release('.*-merge')
James E. Blairec590122012-08-22 15:19:31 -07001345 self.waitUntilSettled()
1346
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001347 self.assertEqual(len(self.builds), 9)
1348 self.assertEqual(self.builds[0].name, 'project1-test1')
1349 self.assertEqual(self.builds[1].name, 'project1-test2')
1350 self.assertEqual(self.builds[2].name, 'project1-project2-integration')
1351 self.assertEqual(self.builds[3].name, 'project1-test1')
1352 self.assertEqual(self.builds[4].name, 'project1-test2')
1353 self.assertEqual(self.builds[5].name, 'project1-project2-integration')
1354 self.assertEqual(self.builds[6].name, 'project1-test1')
1355 self.assertEqual(self.builds[7].name, 'project1-test2')
1356 self.assertEqual(self.builds[8].name, 'project1-project2-integration')
James E. Blairec590122012-08-22 15:19:31 -07001357
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001358 self.release(self.builds[0])
James E. Blairec590122012-08-22 15:19:31 -07001359 self.waitUntilSettled()
1360
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001361 self.assertEqual(len(self.builds), 3) # test2,integration, merge for B
1362 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6)
James E. Blairec590122012-08-22 15:19:31 -07001363
James E. Blair08d19992016-08-10 15:25:31 -07001364 self.launch_server.hold_jobs_in_build = False
1365 self.launch_server.release()
James E. Blairec590122012-08-22 15:19:31 -07001366 self.waitUntilSettled()
1367
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001368 self.assertEqual(len(self.builds), 0)
1369 self.assertEqual(len(self.history), 20)
James E. Blaircaec0c52012-08-22 14:52:22 -07001370
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001371 self.assertEqual(A.data['status'], 'NEW')
1372 self.assertEqual(B.data['status'], 'MERGED')
1373 self.assertEqual(C.data['status'], 'MERGED')
1374 self.assertEqual(A.reported, 2)
1375 self.assertEqual(B.reported, 2)
1376 self.assertEqual(C.reported, 2)
James E. Blair4ec821f2012-08-23 15:28:28 -07001377
James E. Blairec056492016-07-22 09:45:56 -07001378 @skip("Disabled for early v3 development")
James E. Blair4ec821f2012-08-23 15:28:28 -07001379 def test_nonvoting_job(self):
1380 "Test that non-voting jobs don't vote."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001381
James E. Blair4ec821f2012-08-23 15:28:28 -07001382 A = self.fake_gerrit.addFakeChange('org/nonvoting-project',
1383 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001384 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07001385 self.launch_server.failJob('nonvoting-project-test2', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07001386 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4ec821f2012-08-23 15:28:28 -07001387
1388 self.waitUntilSettled()
James E. Blair4ec821f2012-08-23 15:28:28 -07001389
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001390 self.assertEqual(A.data['status'], 'MERGED')
1391 self.assertEqual(A.reported, 2)
1392 self.assertEqual(
1393 self.getJobFromHistory('nonvoting-project-merge').result,
1394 'SUCCESS')
1395 self.assertEqual(
1396 self.getJobFromHistory('nonvoting-project-test1').result,
1397 'SUCCESS')
1398 self.assertEqual(
1399 self.getJobFromHistory('nonvoting-project-test2').result,
1400 'FAILURE')
James E. Blaire0487072012-08-29 17:38:31 -07001401
James E. Blair5821bd92015-09-16 08:48:15 -07001402 for build in self.builds:
1403 self.assertEqual(build.parameters['ZUUL_VOTING'], '0')
1404
James E. Blairec056492016-07-22 09:45:56 -07001405 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001406 def test_check_queue_success(self):
1407 "Test successful check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001408
James E. Blaire0487072012-08-29 17:38:31 -07001409 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1410 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1411
1412 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001413
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001414 self.assertEqual(A.data['status'], 'NEW')
1415 self.assertEqual(A.reported, 1)
1416 self.assertEqual(self.getJobFromHistory('project-merge').result,
1417 'SUCCESS')
1418 self.assertEqual(self.getJobFromHistory('project-test1').result,
1419 'SUCCESS')
1420 self.assertEqual(self.getJobFromHistory('project-test2').result,
1421 'SUCCESS')
James E. Blaire0487072012-08-29 17:38:31 -07001422
James E. Blairec056492016-07-22 09:45:56 -07001423 @skip("Disabled for early v3 development")
James E. Blaire0487072012-08-29 17:38:31 -07001424 def test_check_queue_failure(self):
1425 "Test failed check queue jobs."
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001426
James E. Blaire0487072012-08-29 17:38:31 -07001427 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair08d19992016-08-10 15:25:31 -07001428 self.launch_server.failJob('project-test2', A)
James E. Blaire0487072012-08-29 17:38:31 -07001429 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1430
1431 self.waitUntilSettled()
James E. Blaire0487072012-08-29 17:38:31 -07001432
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001433 self.assertEqual(A.data['status'], 'NEW')
1434 self.assertEqual(A.reported, 1)
1435 self.assertEqual(self.getJobFromHistory('project-merge').result,
James E. Blair78e31b32013-07-09 09:11:34 -07001436 'SUCCESS')
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001437 self.assertEqual(self.getJobFromHistory('project-test1').result,
1438 'SUCCESS')
1439 self.assertEqual(self.getJobFromHistory('project-test2').result,
1440 'FAILURE')
James E. Blair127bc182012-08-28 15:55:15 -07001441
James E. Blairec056492016-07-22 09:45:56 -07001442 @skip("Disabled for early v3 development")
James E. Blair127bc182012-08-28 15:55:15 -07001443 def test_dependent_behind_dequeue(self):
1444 "test that dependent changes behind dequeued changes work"
1445 # This complicated test is a reproduction of a real life bug
1446 self.sched.reconfigure(self.config)
James E. Blair127bc182012-08-28 15:55:15 -07001447
James E. Blair08d19992016-08-10 15:25:31 -07001448 self.launch_server.hold_jobs_in_build = True
James E. Blair127bc182012-08-28 15:55:15 -07001449 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1450 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
1451 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
1452 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
1453 E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E')
1454 F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F')
1455 D.setDependsOn(C, 1)
1456 E.setDependsOn(D, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07001457 A.addApproval('code-review', 2)
1458 B.addApproval('code-review', 2)
1459 C.addApproval('code-review', 2)
1460 D.addApproval('code-review', 2)
1461 E.addApproval('code-review', 2)
1462 F.addApproval('code-review', 2)
James E. Blair127bc182012-08-28 15:55:15 -07001463
1464 A.fail_merge = True
James E. Blair127bc182012-08-28 15:55:15 -07001465
1466 # Change object re-use in the gerrit trigger is hidden if
1467 # changes are added in quick succession; waiting makes it more
1468 # like real life.
James E. Blair8b5408c2016-08-08 15:37:46 -07001469 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001470 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001471 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001472 self.waitUntilSettled()
1473
James E. Blair08d19992016-08-10 15:25:31 -07001474 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001475 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001476 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001477 self.waitUntilSettled()
1478
James E. Blair8b5408c2016-08-08 15:37:46 -07001479 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001480 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001481 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001482 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001483 self.fake_gerrit.addEvent(E.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001484 self.waitUntilSettled()
James E. Blair8b5408c2016-08-08 15:37:46 -07001485 self.fake_gerrit.addEvent(F.addApproval('approved', 1))
James E. Blair127bc182012-08-28 15:55:15 -07001486 self.waitUntilSettled()
1487
James E. Blair08d19992016-08-10 15:25:31 -07001488 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001489 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001490 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001491 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001492 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001493 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001494 self.launch_server.release('.*-merge')
James E. Blair127bc182012-08-28 15:55:15 -07001495 self.waitUntilSettled()
1496
1497 # all jobs running
James E. Blaire955e062012-10-08 09:49:03 -07001498
1499 # Grab pointers to the jobs we want to release before
1500 # releasing any, because list indexes may change as
1501 # the jobs complete.
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001502 a, b, c = self.builds[:3]
James E. Blaire955e062012-10-08 09:49:03 -07001503 a.release()
1504 b.release()
1505 c.release()
James E. Blair127bc182012-08-28 15:55:15 -07001506 self.waitUntilSettled()
1507
James E. Blair08d19992016-08-10 15:25:31 -07001508 self.launch_server.hold_jobs_in_build = False
1509 self.launch_server.release()
James E. Blair127bc182012-08-28 15:55:15 -07001510 self.waitUntilSettled()
1511
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001512 self.assertEqual(A.data['status'], 'NEW')
1513 self.assertEqual(B.data['status'], 'MERGED')
1514 self.assertEqual(C.data['status'], 'MERGED')
1515 self.assertEqual(D.data['status'], 'MERGED')
1516 self.assertEqual(E.data['status'], 'MERGED')
1517 self.assertEqual(F.data['status'], 'MERGED')
James E. Blair127bc182012-08-28 15:55:15 -07001518
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001519 self.assertEqual(A.reported, 2)
1520 self.assertEqual(B.reported, 2)
1521 self.assertEqual(C.reported, 2)
1522 self.assertEqual(D.reported, 2)
1523 self.assertEqual(E.reported, 2)
1524 self.assertEqual(F.reported, 2)
James E. Blair127bc182012-08-28 15:55:15 -07001525
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001526 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15)
1527 self.assertEqual(len(self.history), 44)
James E. Blair05fed602012-09-07 12:45:24 -07001528
James E. Blairec056492016-07-22 09:45:56 -07001529 @skip("Disabled for early v3 development")
James E. Blair05fed602012-09-07 12:45:24 -07001530 def test_merger_repack(self):
1531 "Test that the merger works after a repack"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001532
James E. Blair05fed602012-09-07 12:45:24 -07001533 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001534 A.addApproval('code-review', 2)
1535 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001536 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001537 self.assertEqual(self.getJobFromHistory('project-merge').result,
1538 'SUCCESS')
1539 self.assertEqual(self.getJobFromHistory('project-test1').result,
1540 'SUCCESS')
1541 self.assertEqual(self.getJobFromHistory('project-test2').result,
1542 'SUCCESS')
1543 self.assertEqual(A.data['status'], 'MERGED')
1544 self.assertEqual(A.reported, 2)
James E. Blair05fed602012-09-07 12:45:24 -07001545 self.assertEmptyQueues()
James E. Blair4ca985f2013-05-30 12:27:43 -07001546 self.worker.build_history = []
James E. Blair05fed602012-09-07 12:45:24 -07001547
Monty Taylorbc758832013-06-17 17:22:42 -04001548 path = os.path.join(self.git_root, "org/project")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001549 print(repack_repo(path))
James E. Blair05fed602012-09-07 12:45:24 -07001550
1551 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001552 A.addApproval('code-review', 2)
1553 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair05fed602012-09-07 12:45:24 -07001554 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001555 self.assertEqual(self.getJobFromHistory('project-merge').result,
1556 'SUCCESS')
1557 self.assertEqual(self.getJobFromHistory('project-test1').result,
1558 'SUCCESS')
1559 self.assertEqual(self.getJobFromHistory('project-test2').result,
1560 'SUCCESS')
1561 self.assertEqual(A.data['status'], 'MERGED')
1562 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001563
James E. Blairec056492016-07-22 09:45:56 -07001564 @skip("Disabled for early v3 development")
James E. Blair4886f282012-11-15 09:27:33 -08001565 def test_merger_repack_large_change(self):
1566 "Test that the merger works with large changes after a repack"
1567 # https://bugs.launchpad.net/zuul/+bug/1078946
James E. Blairac2c3242014-01-24 13:38:51 -08001568 # This test assumes the repo is already cloned; make sure it is
Joshua Hesketh352264b2015-08-11 23:42:08 +10001569 url = self.fake_gerrit.getGitUrl(
James E. Blairac2c3242014-01-24 13:38:51 -08001570 self.sched.layout.projects['org/project1'])
James E. Blair4076e2b2014-01-28 12:42:20 -08001571 self.merge_server.merger.addProject('org/project1', url)
James E. Blair4886f282012-11-15 09:27:33 -08001572 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
1573 A.addPatchset(large=True)
Monty Taylorbc758832013-06-17 17:22:42 -04001574 path = os.path.join(self.upstream_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001575 print(repack_repo(path))
Monty Taylorbc758832013-06-17 17:22:42 -04001576 path = os.path.join(self.git_root, "org/project1")
Morgan Fainberg4c6a7742016-05-27 08:42:17 -07001577 print(repack_repo(path))
James E. Blair4886f282012-11-15 09:27:33 -08001578
James E. Blair8b5408c2016-08-08 15:37:46 -07001579 A.addApproval('code-review', 2)
1580 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4886f282012-11-15 09:27:33 -08001581 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001582 self.assertEqual(self.getJobFromHistory('project1-merge').result,
1583 'SUCCESS')
1584 self.assertEqual(self.getJobFromHistory('project1-test1').result,
1585 'SUCCESS')
1586 self.assertEqual(self.getJobFromHistory('project1-test2').result,
1587 'SUCCESS')
1588 self.assertEqual(A.data['status'], 'MERGED')
1589 self.assertEqual(A.reported, 2)
James E. Blair4886f282012-11-15 09:27:33 -08001590
James E. Blairec056492016-07-22 09:45:56 -07001591 @skip("Disabled for early v3 development")
James E. Blair7ee88a22012-09-12 18:59:31 +02001592 def test_nonexistent_job(self):
1593 "Test launching a job that doesn't exist"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001594 # Set to the state immediately after a restart
1595 self.resetGearmanServer()
1596 self.launcher.negative_function_cache_ttl = 0
James E. Blair7ee88a22012-09-12 18:59:31 +02001597
1598 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001599 A.addApproval('code-review', 2)
1600 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001601 # There may be a thread about to report a lost change
1602 while A.reported < 2:
1603 self.waitUntilSettled()
Monty Taylor6bef8ef2013-06-02 08:17:12 -04001604 job_names = [x.name for x in self.history]
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001605 self.assertFalse(job_names)
1606 self.assertEqual(A.data['status'], 'NEW')
1607 self.assertEqual(A.reported, 2)
James E. Blair7ee88a22012-09-12 18:59:31 +02001608 self.assertEmptyQueues()
1609
1610 # Make sure things still work:
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001611 self.registerJobs()
James E. Blair7ee88a22012-09-12 18:59:31 +02001612 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001613 A.addApproval('code-review', 2)
1614 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair7ee88a22012-09-12 18:59:31 +02001615 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001616 self.assertEqual(self.getJobFromHistory('project-merge').result,
1617 'SUCCESS')
1618 self.assertEqual(self.getJobFromHistory('project-test1').result,
1619 'SUCCESS')
1620 self.assertEqual(self.getJobFromHistory('project-test2').result,
1621 'SUCCESS')
1622 self.assertEqual(A.data['status'], 'MERGED')
1623 self.assertEqual(A.reported, 2)
James E. Blairf62d4282012-12-31 17:01:50 -08001624
James E. Blairec056492016-07-22 09:45:56 -07001625 @skip("Disabled for early v3 development")
James E. Blairf62d4282012-12-31 17:01:50 -08001626 def test_single_nonexistent_post_job(self):
1627 "Test launching a single post job that doesn't exist"
James E. Blairf62d4282012-12-31 17:01:50 -08001628 e = {
1629 "type": "ref-updated",
1630 "submitter": {
1631 "name": "User Name",
1632 },
1633 "refUpdate": {
1634 "oldRev": "90f173846e3af9154517b88543ffbd1691f31366",
1635 "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543",
1636 "refName": "master",
1637 "project": "org/project",
1638 }
1639 }
James E. Blair1f4c2bb2013-04-26 08:40:46 -07001640 # Set to the state immediately after a restart
1641 self.resetGearmanServer()
1642 self.launcher.negative_function_cache_ttl = 0
1643
James E. Blairf62d4282012-12-31 17:01:50 -08001644 self.fake_gerrit.addEvent(e)
1645 self.waitUntilSettled()
1646
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001647 self.assertEqual(len(self.history), 0)
James E. Blair2fa50962013-01-30 21:50:41 -08001648
James E. Blairec056492016-07-22 09:45:56 -07001649 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001650 def test_new_patchset_dequeues_old(self):
1651 "Test that a new patchset causes the old to be dequeued"
1652 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001653 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001654 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1655 M.setMerged()
1656
1657 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1658 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1659 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1660 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001661 A.addApproval('code-review', 2)
1662 B.addApproval('code-review', 2)
1663 C.addApproval('code-review', 2)
1664 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001665
1666 C.setDependsOn(B, 1)
1667 B.setDependsOn(A, 1)
1668 A.setDependsOn(M, 1)
1669
James E. Blair8b5408c2016-08-08 15:37:46 -07001670 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1671 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1672 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1673 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001674 self.waitUntilSettled()
1675
1676 B.addPatchset()
1677 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1678 self.waitUntilSettled()
1679
James E. Blair08d19992016-08-10 15:25:31 -07001680 self.launch_server.hold_jobs_in_build = False
1681 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001682 self.waitUntilSettled()
1683
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001684 self.assertEqual(A.data['status'], 'MERGED')
1685 self.assertEqual(A.reported, 2)
1686 self.assertEqual(B.data['status'], 'NEW')
1687 self.assertEqual(B.reported, 2)
1688 self.assertEqual(C.data['status'], 'NEW')
1689 self.assertEqual(C.reported, 2)
1690 self.assertEqual(D.data['status'], 'MERGED')
1691 self.assertEqual(D.reported, 2)
1692 self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
James E. Blair2fa50962013-01-30 21:50:41 -08001693
James E. Blairec056492016-07-22 09:45:56 -07001694 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001695 def test_new_patchset_check(self):
1696 "Test a new patchset in check"
Antoine Mussobd86a312014-01-08 14:51:33 +01001697
James E. Blair08d19992016-08-10 15:25:31 -07001698 self.launch_server.hold_jobs_in_build = True
Antoine Mussobd86a312014-01-08 14:51:33 +01001699
1700 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blairba437362015-02-07 11:41:52 -08001701 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1702 check_pipeline = self.sched.layout.pipelines['check']
1703
1704 # Add two git-dependent changes
1705 B.setDependsOn(A, 1)
1706 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1707 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001708 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1709 self.waitUntilSettled()
James E. Blairba437362015-02-07 11:41:52 -08001710
1711 # A live item, and a non-live/live pair
1712 items = check_pipeline.getAllItems()
1713 self.assertEqual(len(items), 3)
1714
1715 self.assertEqual(items[0].change.number, '1')
1716 self.assertEqual(items[0].change.patchset, '1')
1717 self.assertFalse(items[0].live)
1718
1719 self.assertEqual(items[1].change.number, '2')
1720 self.assertEqual(items[1].change.patchset, '1')
1721 self.assertTrue(items[1].live)
1722
1723 self.assertEqual(items[2].change.number, '1')
1724 self.assertEqual(items[2].change.patchset, '1')
1725 self.assertTrue(items[2].live)
1726
1727 # Add a new patchset to A
1728 A.addPatchset()
1729 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1730 self.waitUntilSettled()
1731
1732 # The live copy of A,1 should be gone, but the non-live and B
1733 # should continue, and we should have a new A,2
1734 items = check_pipeline.getAllItems()
1735 self.assertEqual(len(items), 3)
1736
1737 self.assertEqual(items[0].change.number, '1')
1738 self.assertEqual(items[0].change.patchset, '1')
1739 self.assertFalse(items[0].live)
1740
1741 self.assertEqual(items[1].change.number, '2')
1742 self.assertEqual(items[1].change.patchset, '1')
1743 self.assertTrue(items[1].live)
1744
1745 self.assertEqual(items[2].change.number, '1')
1746 self.assertEqual(items[2].change.patchset, '2')
1747 self.assertTrue(items[2].live)
1748
1749 # Add a new patchset to B
1750 B.addPatchset()
1751 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1752 self.waitUntilSettled()
1753
1754 # The live copy of B,1 should be gone, and it's non-live copy of A,1
1755 # but we should have a new B,2 (still based on A,1)
1756 items = check_pipeline.getAllItems()
1757 self.assertEqual(len(items), 3)
1758
1759 self.assertEqual(items[0].change.number, '1')
1760 self.assertEqual(items[0].change.patchset, '2')
1761 self.assertTrue(items[0].live)
1762
1763 self.assertEqual(items[1].change.number, '1')
1764 self.assertEqual(items[1].change.patchset, '1')
1765 self.assertFalse(items[1].live)
1766
1767 self.assertEqual(items[2].change.number, '2')
1768 self.assertEqual(items[2].change.patchset, '2')
1769 self.assertTrue(items[2].live)
1770
1771 self.builds[0].release()
1772 self.waitUntilSettled()
1773 self.builds[0].release()
1774 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07001775 self.launch_server.hold_jobs_in_build = False
1776 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001777 self.waitUntilSettled()
1778
1779 self.assertEqual(A.reported, 1)
1780 self.assertEqual(B.reported, 1)
1781 self.assertEqual(self.history[0].result, 'ABORTED')
1782 self.assertEqual(self.history[0].changes, '1,1')
1783 self.assertEqual(self.history[1].result, 'ABORTED')
1784 self.assertEqual(self.history[1].changes, '1,1 2,1')
1785 self.assertEqual(self.history[2].result, 'SUCCESS')
1786 self.assertEqual(self.history[2].changes, '1,2')
1787 self.assertEqual(self.history[3].result, 'SUCCESS')
1788 self.assertEqual(self.history[3].changes, '1,1 2,2')
1789
James E. Blairec056492016-07-22 09:45:56 -07001790 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001791 def test_abandoned_gate(self):
1792 "Test that an abandoned change is dequeued from gate"
1793
James E. Blair08d19992016-08-10 15:25:31 -07001794 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001795
1796 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001797 A.addApproval('code-review', 2)
1798 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairba437362015-02-07 11:41:52 -08001799 self.waitUntilSettled()
Antoine Mussobd86a312014-01-08 14:51:33 +01001800 self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
1801 self.assertEqual(self.builds[0].name, 'project-merge')
1802
1803 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1804 self.waitUntilSettled()
1805
James E. Blair08d19992016-08-10 15:25:31 -07001806 self.launch_server.release('.*-merge')
Antoine Mussobd86a312014-01-08 14:51:33 +01001807 self.waitUntilSettled()
1808
1809 self.assertEqual(len(self.builds), 0, "No job running")
Antoine Mussobd86a312014-01-08 14:51:33 +01001810 self.assertEqual(len(self.history), 1, "Only one build in history")
1811 self.assertEqual(self.history[0].result, 'ABORTED',
James E. Blairba437362015-02-07 11:41:52 -08001812 "Build should have been aborted")
1813 self.assertEqual(A.reported, 1,
1814 "Abandoned gate change should report only start")
1815
James E. Blairec056492016-07-22 09:45:56 -07001816 @skip("Disabled for early v3 development")
James E. Blairba437362015-02-07 11:41:52 -08001817 def test_abandoned_check(self):
1818 "Test that an abandoned change is dequeued from check"
1819
James E. Blair08d19992016-08-10 15:25:31 -07001820 self.launch_server.hold_jobs_in_build = True
James E. Blairba437362015-02-07 11:41:52 -08001821
1822 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1823 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1824 check_pipeline = self.sched.layout.pipelines['check']
1825
1826 # Add two git-dependent changes
1827 B.setDependsOn(A, 1)
1828 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
1829 self.waitUntilSettled()
1830 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1831 self.waitUntilSettled()
1832 # A live item, and a non-live/live pair
1833 items = check_pipeline.getAllItems()
1834 self.assertEqual(len(items), 3)
1835
1836 self.assertEqual(items[0].change.number, '1')
1837 self.assertFalse(items[0].live)
1838
1839 self.assertEqual(items[1].change.number, '2')
1840 self.assertTrue(items[1].live)
1841
1842 self.assertEqual(items[2].change.number, '1')
1843 self.assertTrue(items[2].live)
1844
1845 # Abandon A
1846 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1847 self.waitUntilSettled()
1848
1849 # The live copy of A should be gone, but the non-live and B
1850 # should continue
1851 items = check_pipeline.getAllItems()
1852 self.assertEqual(len(items), 2)
1853
1854 self.assertEqual(items[0].change.number, '1')
1855 self.assertFalse(items[0].live)
1856
1857 self.assertEqual(items[1].change.number, '2')
1858 self.assertTrue(items[1].live)
1859
James E. Blair08d19992016-08-10 15:25:31 -07001860 self.launch_server.hold_jobs_in_build = False
1861 self.launch_server.release()
James E. Blairba437362015-02-07 11:41:52 -08001862 self.waitUntilSettled()
1863
1864 self.assertEqual(len(self.history), 4)
1865 self.assertEqual(self.history[0].result, 'ABORTED',
Antoine Mussobd86a312014-01-08 14:51:33 +01001866 'Build should have been aborted')
1867 self.assertEqual(A.reported, 0, "Abandoned change should not report")
James E. Blairba437362015-02-07 11:41:52 -08001868 self.assertEqual(B.reported, 1, "Change should report")
Antoine Mussobd86a312014-01-08 14:51:33 +01001869
James E. Blairec056492016-07-22 09:45:56 -07001870 @skip("Disabled for early v3 development")
Steve Varnau7b78b312015-04-03 14:49:46 -07001871 def test_abandoned_not_timer(self):
1872 "Test that an abandoned change does not cancel timer jobs"
1873
James E. Blair08d19992016-08-10 15:25:31 -07001874 self.launch_server.hold_jobs_in_build = True
Steve Varnau7b78b312015-04-03 14:49:46 -07001875
1876 # Start timer trigger - also org/project
James E. Blairf84026c2015-12-08 16:11:46 -08001877 self.updateConfigLayout(
1878 'tests/fixtures/layout-idle.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001879 self.sched.reconfigure(self.config)
1880 self.registerJobs()
1881 # The pipeline triggers every second, so we should have seen
1882 # several by now.
1883 time.sleep(5)
1884 self.waitUntilSettled()
1885 # Stop queuing timer triggered jobs so that the assertions
1886 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08001887 self.updateConfigLayout(
1888 'tests/fixtures/layout-no-timer.yaml')
Steve Varnau7b78b312015-04-03 14:49:46 -07001889 self.sched.reconfigure(self.config)
1890 self.registerJobs()
1891 self.assertEqual(len(self.builds), 2, "Two timer jobs")
1892
1893 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1894 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
1895 self.waitUntilSettled()
1896 self.assertEqual(len(self.builds), 3, "One change plus two timer jobs")
1897
1898 self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
1899 self.waitUntilSettled()
1900
1901 self.assertEqual(len(self.builds), 2, "Two timer jobs remain")
1902
James E. Blair08d19992016-08-10 15:25:31 -07001903 self.launch_server.release()
Steve Varnau7b78b312015-04-03 14:49:46 -07001904 self.waitUntilSettled()
1905
James E. Blairec056492016-07-22 09:45:56 -07001906 @skip("Disabled for early v3 development")
Arx Cruzb1b010d2013-10-28 19:49:59 -02001907 def test_zuul_url_return(self):
1908 "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
James E. Blair4076e2b2014-01-28 12:42:20 -08001909 self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))
James E. Blair08d19992016-08-10 15:25:31 -07001910 self.launch_server.hold_jobs_in_build = True
Arx Cruzb1b010d2013-10-28 19:49:59 -02001911
1912 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07001913 A.addApproval('code-review', 2)
1914 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Arx Cruzb1b010d2013-10-28 19:49:59 -02001915 self.waitUntilSettled()
1916
1917 self.assertEqual(len(self.builds), 1)
1918 for build in self.builds:
1919 self.assertTrue('ZUUL_URL' in build.parameters)
1920
James E. Blair08d19992016-08-10 15:25:31 -07001921 self.launch_server.hold_jobs_in_build = False
1922 self.launch_server.release()
Arx Cruzb1b010d2013-10-28 19:49:59 -02001923 self.waitUntilSettled()
1924
James E. Blairec056492016-07-22 09:45:56 -07001925 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001926 def test_new_patchset_dequeues_old_on_head(self):
1927 "Test that a new patchset causes the old to be dequeued (at head)"
1928 # D -> C (depends on B) -> B (depends on A) -> A -> M
James E. Blair08d19992016-08-10 15:25:31 -07001929 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001930 M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M')
1931 M.setMerged()
1932 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1933 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1934 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
1935 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07001936 A.addApproval('code-review', 2)
1937 B.addApproval('code-review', 2)
1938 C.addApproval('code-review', 2)
1939 D.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001940
1941 C.setDependsOn(B, 1)
1942 B.setDependsOn(A, 1)
1943 A.setDependsOn(M, 1)
1944
James E. Blair8b5408c2016-08-08 15:37:46 -07001945 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
1946 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1947 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1948 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001949 self.waitUntilSettled()
1950
1951 A.addPatchset()
1952 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
1953 self.waitUntilSettled()
1954
James E. Blair08d19992016-08-10 15:25:31 -07001955 self.launch_server.hold_jobs_in_build = False
1956 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001957 self.waitUntilSettled()
1958
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001959 self.assertEqual(A.data['status'], 'NEW')
1960 self.assertEqual(A.reported, 2)
1961 self.assertEqual(B.data['status'], 'NEW')
1962 self.assertEqual(B.reported, 2)
1963 self.assertEqual(C.data['status'], 'NEW')
1964 self.assertEqual(C.reported, 2)
1965 self.assertEqual(D.data['status'], 'MERGED')
1966 self.assertEqual(D.reported, 2)
1967 self.assertEqual(len(self.history), 7)
James E. Blair2fa50962013-01-30 21:50:41 -08001968
James E. Blairec056492016-07-22 09:45:56 -07001969 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08001970 def test_new_patchset_dequeues_old_without_dependents(self):
1971 "Test that a new patchset causes only the old to be dequeued"
James E. Blair08d19992016-08-10 15:25:31 -07001972 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08001973 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
1974 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
1975 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07001976 A.addApproval('code-review', 2)
1977 B.addApproval('code-review', 2)
1978 C.addApproval('code-review', 2)
James E. Blair2fa50962013-01-30 21:50:41 -08001979
James E. Blair8b5408c2016-08-08 15:37:46 -07001980 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
1981 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
1982 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair2fa50962013-01-30 21:50:41 -08001983 self.waitUntilSettled()
1984
1985 B.addPatchset()
1986 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
1987 self.waitUntilSettled()
1988
James E. Blair08d19992016-08-10 15:25:31 -07001989 self.launch_server.hold_jobs_in_build = False
1990 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08001991 self.waitUntilSettled()
1992
Monty Taylor98f0f3e2013-07-06 16:02:31 -04001993 self.assertEqual(A.data['status'], 'MERGED')
1994 self.assertEqual(A.reported, 2)
1995 self.assertEqual(B.data['status'], 'NEW')
1996 self.assertEqual(B.reported, 2)
1997 self.assertEqual(C.data['status'], 'MERGED')
1998 self.assertEqual(C.reported, 2)
1999 self.assertEqual(len(self.history), 9)
James E. Blair2fa50962013-01-30 21:50:41 -08002000
James E. Blairec056492016-07-22 09:45:56 -07002001 @skip("Disabled for early v3 development")
James E. Blair2fa50962013-01-30 21:50:41 -08002002 def test_new_patchset_dequeues_old_independent_queue(self):
2003 "Test that a new patchset causes the old to be dequeued (independent)"
James E. Blair08d19992016-08-10 15:25:31 -07002004 self.launch_server.hold_jobs_in_build = True
James E. Blair2fa50962013-01-30 21:50:41 -08002005 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2006 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2007 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
2008 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2009 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2010 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2011 self.waitUntilSettled()
2012
2013 B.addPatchset()
2014 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
2015 self.waitUntilSettled()
2016
James E. Blair08d19992016-08-10 15:25:31 -07002017 self.launch_server.hold_jobs_in_build = False
2018 self.launch_server.release()
James E. Blair2fa50962013-01-30 21:50:41 -08002019 self.waitUntilSettled()
2020
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002021 self.assertEqual(A.data['status'], 'NEW')
2022 self.assertEqual(A.reported, 1)
2023 self.assertEqual(B.data['status'], 'NEW')
2024 self.assertEqual(B.reported, 1)
2025 self.assertEqual(C.data['status'], 'NEW')
2026 self.assertEqual(C.reported, 1)
2027 self.assertEqual(len(self.history), 10)
2028 self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002029
James E. Blairec056492016-07-22 09:45:56 -07002030 @skip("Disabled for early v3 development")
James E. Blair18c64442014-03-18 10:14:45 -07002031 def test_noop_job(self):
2032 "Test that the internal noop job works"
2033 A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002034 A.addApproval('code-review', 2)
2035 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair18c64442014-03-18 10:14:45 -07002036 self.waitUntilSettled()
2037
2038 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2039 self.assertTrue(self.sched._areAllBuildsComplete())
2040 self.assertEqual(len(self.history), 0)
2041 self.assertEqual(A.data['status'], 'MERGED')
2042 self.assertEqual(A.reported, 2)
2043
James E. Blairec056492016-07-22 09:45:56 -07002044 @skip("Disabled for early v3 development")
Evgeny Antyshevd6e546c2015-06-11 15:13:57 +00002045 def test_no_job_project(self):
2046 "Test that reports with no jobs don't get sent"
2047 A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
2048 'master', 'A')
2049 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2050 self.waitUntilSettled()
2051
2052 # Change wasn't reported to
2053 self.assertEqual(A.reported, False)
2054
2055 # Check queue is empty afterwards
2056 check_pipeline = self.sched.layout.pipelines['check']
2057 items = check_pipeline.getAllItems()
2058 self.assertEqual(len(items), 0)
2059
2060 self.assertEqual(len(self.history), 0)
2061
James E. Blairec056492016-07-22 09:45:56 -07002062 @skip("Disabled for early v3 development")
James E. Blair7d0dedc2013-02-21 17:26:09 -08002063 def test_zuul_refs(self):
2064 "Test that zuul refs exist and have the right changes"
James E. Blair08d19992016-08-10 15:25:31 -07002065 self.launch_server.hold_jobs_in_build = True
James E. Blair7d0dedc2013-02-21 17:26:09 -08002066 M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1')
2067 M1.setMerged()
2068 M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2')
2069 M2.setMerged()
2070
2071 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2072 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2073 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
2074 D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D')
James E. Blair8b5408c2016-08-08 15:37:46 -07002075 A.addApproval('code-review', 2)
2076 B.addApproval('code-review', 2)
2077 C.addApproval('code-review', 2)
2078 D.addApproval('code-review', 2)
2079 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2080 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
2081 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
2082 self.fake_gerrit.addEvent(D.addApproval('approved', 1))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002083
2084 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002085 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002086 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002087 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002088 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002089 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002090 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002091 self.launch_server.release('.*-merge')
James E. Blair7d0dedc2013-02-21 17:26:09 -08002092 self.waitUntilSettled()
2093
James E. Blair7d0dedc2013-02-21 17:26:09 -08002094 a_zref = b_zref = c_zref = d_zref = None
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002095 for x in self.builds:
James E. Blair7d0dedc2013-02-21 17:26:09 -08002096 if x.parameters['ZUUL_CHANGE'] == '3':
2097 a_zref = x.parameters['ZUUL_REF']
2098 if x.parameters['ZUUL_CHANGE'] == '4':
2099 b_zref = x.parameters['ZUUL_REF']
2100 if x.parameters['ZUUL_CHANGE'] == '5':
2101 c_zref = x.parameters['ZUUL_REF']
2102 if x.parameters['ZUUL_CHANGE'] == '6':
2103 d_zref = x.parameters['ZUUL_REF']
2104
2105 # There are... four... refs.
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002106 self.assertIsNotNone(a_zref)
2107 self.assertIsNotNone(b_zref)
2108 self.assertIsNotNone(c_zref)
2109 self.assertIsNotNone(d_zref)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002110
2111 # And they should all be different
2112 refs = set([a_zref, b_zref, c_zref, d_zref])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002113 self.assertEqual(len(refs), 4)
James E. Blair7d0dedc2013-02-21 17:26:09 -08002114
2115 # a ref should have a, not b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002116 self.assertTrue(self.ref_has_change(a_zref, A))
2117 self.assertFalse(self.ref_has_change(a_zref, B))
2118 self.assertFalse(self.ref_has_change(a_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002119
2120 # b ref should have a and b, and should not be in project2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002121 self.assertTrue(self.ref_has_change(b_zref, A))
2122 self.assertTrue(self.ref_has_change(b_zref, B))
2123 self.assertFalse(self.ref_has_change(b_zref, M2))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002124
2125 # c ref should have a and b in 1, c in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002126 self.assertTrue(self.ref_has_change(c_zref, A))
2127 self.assertTrue(self.ref_has_change(c_zref, B))
2128 self.assertTrue(self.ref_has_change(c_zref, C))
2129 self.assertFalse(self.ref_has_change(c_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002130
2131 # d ref should have a and b in 1, c and d in 2
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002132 self.assertTrue(self.ref_has_change(d_zref, A))
2133 self.assertTrue(self.ref_has_change(d_zref, B))
2134 self.assertTrue(self.ref_has_change(d_zref, C))
2135 self.assertTrue(self.ref_has_change(d_zref, D))
James E. Blair7d0dedc2013-02-21 17:26:09 -08002136
James E. Blair08d19992016-08-10 15:25:31 -07002137 self.launch_server.hold_jobs_in_build = False
2138 self.launch_server.release()
James E. Blair7d0dedc2013-02-21 17:26:09 -08002139 self.waitUntilSettled()
2140
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002141 self.assertEqual(A.data['status'], 'MERGED')
2142 self.assertEqual(A.reported, 2)
2143 self.assertEqual(B.data['status'], 'MERGED')
2144 self.assertEqual(B.reported, 2)
2145 self.assertEqual(C.data['status'], 'MERGED')
2146 self.assertEqual(C.reported, 2)
2147 self.assertEqual(D.data['status'], 'MERGED')
2148 self.assertEqual(D.reported, 2)
James E. Blair70c71582013-03-06 08:50:50 -08002149
James E. Blairec056492016-07-22 09:45:56 -07002150 @skip("Disabled for early v3 development")
James E. Blair4a28a882013-08-23 15:17:33 -07002151 def test_rerun_on_error(self):
2152 "Test that if a worker fails to run a job, it is run again"
James E. Blair08d19992016-08-10 15:25:31 -07002153 self.launch_server.hold_jobs_in_build = True
James E. Blair4a28a882013-08-23 15:17:33 -07002154 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002155 A.addApproval('code-review', 2)
2156 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair4a28a882013-08-23 15:17:33 -07002157 self.waitUntilSettled()
2158
2159 self.builds[0].run_error = True
James E. Blair08d19992016-08-10 15:25:31 -07002160 self.launch_server.hold_jobs_in_build = False
2161 self.launch_server.release()
James E. Blair4a28a882013-08-23 15:17:33 -07002162 self.waitUntilSettled()
2163 self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1)
2164 self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3)
2165
James E. Blairec056492016-07-22 09:45:56 -07002166 @skip("Disabled for early v3 development")
James E. Blair412e5582013-04-22 15:50:12 -07002167 def test_statsd(self):
2168 "Test each of the statsd methods used in the scheduler"
2169 import extras
2170 statsd = extras.try_import('statsd.statsd')
2171 statsd.incr('test-incr')
2172 statsd.timing('test-timing', 3)
Alex Gaynor813d39b2014-05-17 16:17:16 -07002173 statsd.gauge('test-gauge', 12)
James E. Blair412e5582013-04-22 15:50:12 -07002174 self.assertReportedStat('test-incr', '1|c')
2175 self.assertReportedStat('test-timing', '3|ms')
Alex Gaynor813d39b2014-05-17 16:17:16 -07002176 self.assertReportedStat('test-gauge', '12|g')
James E. Blair412e5582013-04-22 15:50:12 -07002177
James E. Blairec056492016-07-22 09:45:56 -07002178 @skip("Disabled for early v3 development")
James E. Blairdad52252014-02-07 16:59:17 -08002179 def test_stuck_job_cleanup(self):
2180 "Test that pending jobs are cleaned up if removed from layout"
James E. Blair18c64442014-03-18 10:14:45 -07002181 # This job won't be registered at startup because it is not in
2182 # the standard layout, but we need it to already be registerd
2183 # for when we reconfigure, as that is when Zuul will attempt
2184 # to run the new job.
2185 self.worker.registerFunction('build:gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002186 self.gearman_server.hold_jobs_in_queue = True
2187 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002188 A.addApproval('code-review', 2)
2189 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blairdad52252014-02-07 16:59:17 -08002190 self.waitUntilSettled()
2191 self.assertEqual(len(self.gearman_server.getQueue()), 1)
2192
James E. Blairf84026c2015-12-08 16:11:46 -08002193 self.updateConfigLayout(
2194 'tests/fixtures/layout-no-jobs.yaml')
James E. Blairdad52252014-02-07 16:59:17 -08002195 self.sched.reconfigure(self.config)
2196 self.waitUntilSettled()
2197
James E. Blair18c64442014-03-18 10:14:45 -07002198 self.gearman_server.release('gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002199 self.waitUntilSettled()
2200 self.assertEqual(len(self.gearman_server.getQueue()), 0)
2201 self.assertTrue(self.sched._areAllBuildsComplete())
2202
2203 self.assertEqual(len(self.history), 1)
James E. Blair18c64442014-03-18 10:14:45 -07002204 self.assertEqual(self.history[0].name, 'gate-noop')
James E. Blairdad52252014-02-07 16:59:17 -08002205 self.assertEqual(self.history[0].result, 'SUCCESS')
2206
James E. Blairec056492016-07-22 09:45:56 -07002207 @skip("Disabled for early v3 development")
James E. Blair879dafb2015-07-17 14:04:49 -07002208 def test_file_head(self):
2209 # This is a regression test for an observed bug. A change
2210 # with a file named "HEAD" in the root directory of the repo
2211 # was processed by a merger. It then was unable to reset the
2212 # repo because of:
2213 # GitCommandError: 'git reset --hard HEAD' returned
2214 # with exit code 128
2215 # stderr: 'fatal: ambiguous argument 'HEAD': both revision
2216 # and filename
2217 # Use '--' to separate filenames from revisions'
2218
2219 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2220 A.addPatchset(['HEAD'])
2221 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2222
2223 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
2224 self.waitUntilSettled()
2225
2226 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2227 self.waitUntilSettled()
2228
2229 self.assertIn('Build succeeded', A.messages[0])
2230 self.assertIn('Build succeeded', B.messages[0])
2231
James E. Blairec056492016-07-22 09:45:56 -07002232 @skip("Disabled for early v3 development")
James E. Blair70c71582013-03-06 08:50:50 -08002233 def test_file_jobs(self):
2234 "Test that file jobs run only when appropriate"
2235 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2236 A.addPatchset(['pip-requires'])
2237 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002238 A.addApproval('code-review', 2)
2239 B.addApproval('code-review', 2)
2240 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2241 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair70c71582013-03-06 08:50:50 -08002242 self.waitUntilSettled()
2243
Monty Taylor6bef8ef2013-06-02 08:17:12 -04002244 testfile_jobs = [x for x in self.history
James E. Blair70c71582013-03-06 08:50:50 -08002245 if x.name == 'project-testfile']
2246
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002247 self.assertEqual(len(testfile_jobs), 1)
2248 self.assertEqual(testfile_jobs[0].changes, '1,2')
2249 self.assertEqual(A.data['status'], 'MERGED')
2250 self.assertEqual(A.reported, 2)
2251 self.assertEqual(B.data['status'], 'MERGED')
2252 self.assertEqual(B.reported, 2)
James E. Blair3c5e5b52013-04-26 11:17:03 -07002253
James E. Blairec056492016-07-22 09:45:56 -07002254 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002255 def _test_skip_if_jobs(self, branch, should_skip):
2256 "Test that jobs with a skip-if filter run only when appropriate"
James E. Blairf84026c2015-12-08 16:11:46 -08002257 self.updateConfigLayout(
2258 'tests/fixtures/layout-skip-if.yaml')
Maru Newby3fe5f852015-01-13 04:22:14 +00002259 self.sched.reconfigure(self.config)
2260 self.registerJobs()
2261
2262 change = self.fake_gerrit.addFakeChange('org/project',
2263 branch,
2264 'test skip-if')
2265 self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1))
2266 self.waitUntilSettled()
2267
2268 tested_change_ids = [x.changes[0] for x in self.history
2269 if x.name == 'project-test-skip-if']
2270
2271 if should_skip:
2272 self.assertEqual([], tested_change_ids)
2273 else:
2274 self.assertIn(change.data['number'], tested_change_ids)
2275
James E. Blairec056492016-07-22 09:45:56 -07002276 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002277 def test_skip_if_match_skips_job(self):
2278 self._test_skip_if_jobs(branch='master', should_skip=True)
2279
James E. Blairec056492016-07-22 09:45:56 -07002280 @skip("Disabled for early v3 development")
Maru Newby3fe5f852015-01-13 04:22:14 +00002281 def test_skip_if_no_match_runs_job(self):
2282 self._test_skip_if_jobs(branch='mp', should_skip=False)
2283
James E. Blairec056492016-07-22 09:45:56 -07002284 @skip("Disabled for early v3 development")
James E. Blair3c5e5b52013-04-26 11:17:03 -07002285 def test_test_config(self):
2286 "Test that we can test the config"
James E. Blairf84026c2015-12-08 16:11:46 -08002287 self.sched.testConfig(self.config.get('zuul', 'tenant_config'),
Joshua Hesketh352264b2015-08-11 23:42:08 +10002288 self.connections)
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002289
James E. Blairec056492016-07-22 09:45:56 -07002290 @skip("Disabled for early v3 development")
James E. Blairc8a1e052014-02-25 09:29:26 -08002291 def test_queue_names(self):
2292 "Test shared change queue names"
2293 project1 = self.sched.layout.projects['org/project1']
2294 project2 = self.sched.layout.projects['org/project2']
2295 q1 = self.sched.layout.pipelines['gate'].getQueue(project1)
2296 q2 = self.sched.layout.pipelines['gate'].getQueue(project2)
2297 self.assertEqual(q1.name, 'integration')
2298 self.assertEqual(q2.name, 'integration')
2299
James E. Blairf84026c2015-12-08 16:11:46 -08002300 self.updateConfigLayout(
2301 'tests/fixtures/layout-bad-queue.yaml')
James E. Blairc8a1e052014-02-25 09:29:26 -08002302 with testtools.ExpectedException(
2303 Exception, "More than one name assigned to change queue"):
2304 self.sched.reconfigure(self.config)
2305
James E. Blairec056492016-07-22 09:45:56 -07002306 @skip("Disabled for early v3 development")
James E. Blair64ed6f22013-07-10 14:07:23 -07002307 def test_queue_precedence(self):
2308 "Test that queue precedence works"
2309
2310 self.gearman_server.hold_jobs_in_queue = True
James E. Blair08d19992016-08-10 15:25:31 -07002311 self.launch_server.hold_jobs_in_build = True
James E. Blair64ed6f22013-07-10 14:07:23 -07002312 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2313 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
James E. Blair8b5408c2016-08-08 15:37:46 -07002314 A.addApproval('code-review', 2)
2315 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair64ed6f22013-07-10 14:07:23 -07002316
2317 self.waitUntilSettled()
2318 self.gearman_server.hold_jobs_in_queue = False
2319 self.gearman_server.release()
2320 self.waitUntilSettled()
2321
James E. Blair8de58bd2013-07-18 16:23:33 -07002322 # Run one build at a time to ensure non-race order:
James E. Blairb8c16472015-05-05 14:55:26 -07002323 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07002324 self.launch_server.hold_jobs_in_build = False
James E. Blair8de58bd2013-07-18 16:23:33 -07002325 self.waitUntilSettled()
2326
James E. Blair64ed6f22013-07-10 14:07:23 -07002327 self.log.debug(self.history)
2328 self.assertEqual(self.history[0].pipeline, 'gate')
2329 self.assertEqual(self.history[1].pipeline, 'check')
2330 self.assertEqual(self.history[2].pipeline, 'gate')
2331 self.assertEqual(self.history[3].pipeline, 'gate')
2332 self.assertEqual(self.history[4].pipeline, 'check')
2333 self.assertEqual(self.history[5].pipeline, 'check')
2334
James E. Blairec056492016-07-22 09:45:56 -07002335 @skip("Disabled for early v3 development")
Clark Boylana5edbe42014-06-03 16:39:10 -07002336 def test_json_status(self):
James E. Blair1843a552013-07-03 14:19:52 -07002337 "Test that we can retrieve JSON status info"
James E. Blair08d19992016-08-10 15:25:31 -07002338 self.launch_server.hold_jobs_in_build = True
James E. Blair1843a552013-07-03 14:19:52 -07002339 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002340 A.addApproval('code-review', 2)
2341 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1843a552013-07-03 14:19:52 -07002342 self.waitUntilSettled()
2343
James E. Blair08d19992016-08-10 15:25:31 -07002344 self.launch_server.release('project-merge')
James E. Blairb7273ef2016-04-19 08:58:51 -07002345 self.waitUntilSettled()
2346
James E. Blair1843a552013-07-03 14:19:52 -07002347 port = self.webapp.server.socket.getsockname()[1]
2348
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002349 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2350 f = urllib.request.urlopen(req)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002351 headers = f.info()
2352 self.assertIn('Content-Length', headers)
2353 self.assertIn('Content-Type', headers)
Sachi Kingdc963fc2016-03-23 16:00:33 +11002354 self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$',
2355 headers['Content-Type']))
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002356 self.assertIn('Access-Control-Allow-Origin', headers)
2357 self.assertIn('Cache-Control', headers)
Clark Boylanaa4f2e72014-06-03 21:22:40 -07002358 self.assertIn('Last-Modified', headers)
Timo Tijhof0ebd2932015-04-02 12:11:21 +01002359 self.assertIn('Expires', headers)
James E. Blair1843a552013-07-03 14:19:52 -07002360 data = f.read()
2361
James E. Blair08d19992016-08-10 15:25:31 -07002362 self.launch_server.hold_jobs_in_build = False
2363 self.launch_server.release()
James E. Blair1843a552013-07-03 14:19:52 -07002364 self.waitUntilSettled()
2365
2366 data = json.loads(data)
James E. Blairb7273ef2016-04-19 08:58:51 -07002367 status_jobs = []
James E. Blair1843a552013-07-03 14:19:52 -07002368 for p in data['pipelines']:
2369 for q in p['change_queues']:
James E. Blairbfb8e042014-12-30 17:01:44 -08002370 if p['name'] in ['gate', 'conflict']:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002371 self.assertEqual(q['window'], 20)
2372 else:
2373 self.assertEqual(q['window'], 0)
James E. Blair1843a552013-07-03 14:19:52 -07002374 for head in q['heads']:
2375 for change in head:
Clark Boylanaf2476f2014-01-23 14:47:36 -08002376 self.assertTrue(change['active'])
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002377 self.assertEqual(change['id'], '1,1')
James E. Blair1843a552013-07-03 14:19:52 -07002378 for job in change['jobs']:
James E. Blairb7273ef2016-04-19 08:58:51 -07002379 status_jobs.append(job)
2380 self.assertEqual('project-merge', status_jobs[0]['name'])
2381 self.assertEqual('https://server/job/project-merge/0/',
2382 status_jobs[0]['url'])
2383 self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0',
2384 status_jobs[0]['report_url'])
2385
2386 self.assertEqual('project-test1', status_jobs[1]['name'])
2387 self.assertEqual('https://server/job/project-test1/1/',
2388 status_jobs[1]['url'])
2389 self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1',
2390 status_jobs[1]['report_url'])
2391
2392 self.assertEqual('project-test2', status_jobs[2]['name'])
2393 self.assertEqual('https://server/job/project-test2/2/',
2394 status_jobs[2]['url'])
2395 self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2',
2396 status_jobs[2]['report_url'])
James E. Blair1843a552013-07-03 14:19:52 -07002397
James E. Blairec056492016-07-22 09:45:56 -07002398 @skip("Disabled for early v3 development")
James E. Blairc3d428e2013-12-03 15:06:48 -08002399 def test_merging_queues(self):
2400 "Test that transitively-connected change queues are merged"
James E. Blairf84026c2015-12-08 16:11:46 -08002401 self.updateConfigLayout(
2402 'tests/fixtures/layout-merge-queues.yaml')
James E. Blairc3d428e2013-12-03 15:06:48 -08002403 self.sched.reconfigure(self.config)
2404 self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1)
2405
James E. Blairec056492016-07-22 09:45:56 -07002406 @skip("Disabled for early v3 development")
James E. Blairaf17a972016-02-03 15:07:18 -08002407 def test_mutex(self):
2408 "Test job mutexes"
2409 self.config.set('zuul', 'layout_config',
2410 'tests/fixtures/layout-mutex.yaml')
2411 self.sched.reconfigure(self.config)
2412
James E. Blair08d19992016-08-10 15:25:31 -07002413 self.launch_server.hold_jobs_in_build = True
James E. Blairaf17a972016-02-03 15:07:18 -08002414 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2415 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2416 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2417
2418 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2419 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2420 self.waitUntilSettled()
2421 self.assertEqual(len(self.builds), 3)
2422 self.assertEqual(self.builds[0].name, 'project-test1')
2423 self.assertEqual(self.builds[1].name, 'mutex-one')
2424 self.assertEqual(self.builds[2].name, 'project-test1')
2425
James E. Blair08d19992016-08-10 15:25:31 -07002426 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002427 self.waitUntilSettled()
2428
2429 self.assertEqual(len(self.builds), 3)
2430 self.assertEqual(self.builds[0].name, 'project-test1')
2431 self.assertEqual(self.builds[1].name, 'project-test1')
2432 self.assertEqual(self.builds[2].name, 'mutex-two')
2433 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2434
James E. Blair08d19992016-08-10 15:25:31 -07002435 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002436 self.waitUntilSettled()
2437
2438 self.assertEqual(len(self.builds), 3)
2439 self.assertEqual(self.builds[0].name, 'project-test1')
2440 self.assertEqual(self.builds[1].name, 'project-test1')
2441 self.assertEqual(self.builds[2].name, 'mutex-one')
2442 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2443
James E. Blair08d19992016-08-10 15:25:31 -07002444 self.launch_server.release('mutex-one')
James E. Blairaf17a972016-02-03 15:07:18 -08002445 self.waitUntilSettled()
2446
2447 self.assertEqual(len(self.builds), 3)
2448 self.assertEqual(self.builds[0].name, 'project-test1')
2449 self.assertEqual(self.builds[1].name, 'project-test1')
2450 self.assertEqual(self.builds[2].name, 'mutex-two')
2451 self.assertTrue('test-mutex' in self.sched.mutex.mutexes)
2452
James E. Blair08d19992016-08-10 15:25:31 -07002453 self.launch_server.release('mutex-two')
James E. Blairaf17a972016-02-03 15:07:18 -08002454 self.waitUntilSettled()
2455
2456 self.assertEqual(len(self.builds), 2)
2457 self.assertEqual(self.builds[0].name, 'project-test1')
2458 self.assertEqual(self.builds[1].name, 'project-test1')
2459 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2460
James E. Blair08d19992016-08-10 15:25:31 -07002461 self.launch_server.hold_jobs_in_build = False
2462 self.launch_server.release()
James E. Blairaf17a972016-02-03 15:07:18 -08002463
2464 self.waitUntilSettled()
2465 self.assertEqual(len(self.builds), 0)
2466
2467 self.assertEqual(A.reported, 1)
2468 self.assertEqual(B.reported, 1)
2469 self.assertFalse('test-mutex' in self.sched.mutex.mutexes)
2470
James E. Blairec056492016-07-22 09:45:56 -07002471 @skip("Disabled for early v3 development")
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002472 def test_node_label(self):
2473 "Test that a job runs on a specific node label"
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002474 self.worker.registerFunction('build:node-project-test1:debian')
2475
2476 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002477 A.addApproval('code-review', 2)
2478 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair1f4c2bb2013-04-26 08:40:46 -07002479 self.waitUntilSettled()
James E. Blair4ca985f2013-05-30 12:27:43 -07002480
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002481 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2482 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2483 'debian')
2484 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
James E. Blaircdccd972013-07-01 12:10:22 -07002485
James E. Blairec056492016-07-22 09:45:56 -07002486 @skip("Disabled for early v3 development")
James E. Blaircdccd972013-07-01 12:10:22 -07002487 def test_live_reconfiguration(self):
2488 "Test that live reconfiguration works"
James E. Blair08d19992016-08-10 15:25:31 -07002489 self.launch_server.hold_jobs_in_build = True
James E. Blaircdccd972013-07-01 12:10:22 -07002490 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002491 A.addApproval('code-review', 2)
2492 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaircdccd972013-07-01 12:10:22 -07002493 self.waitUntilSettled()
2494
2495 self.sched.reconfigure(self.config)
2496
James E. Blair08d19992016-08-10 15:25:31 -07002497 self.launch_server.hold_jobs_in_build = False
2498 self.launch_server.release()
James E. Blaircdccd972013-07-01 12:10:22 -07002499 self.waitUntilSettled()
Monty Taylor98f0f3e2013-07-06 16:02:31 -04002500 self.assertEqual(self.getJobFromHistory('project-merge').result,
2501 'SUCCESS')
2502 self.assertEqual(self.getJobFromHistory('project-test1').result,
2503 'SUCCESS')
2504 self.assertEqual(self.getJobFromHistory('project-test2').result,
2505 'SUCCESS')
2506 self.assertEqual(A.data['status'], 'MERGED')
2507 self.assertEqual(A.reported, 2)
James E. Blair287c06d2013-07-24 10:39:30 -07002508
James E. Blairec056492016-07-22 09:45:56 -07002509 @skip("Disabled for early v3 development")
James E. Blair6bc782d2015-07-17 16:20:21 -07002510 def test_live_reconfiguration_merge_conflict(self):
2511 # A real-world bug: a change in a gate queue has a merge
2512 # conflict and a job is added to its project while it's
2513 # sitting in the queue. The job gets added to the change and
2514 # enqueued and the change gets stuck.
2515 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002516 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002517
2518 # This change is fine. It's here to stop the queue long
2519 # enough for the next change to be subject to the
2520 # reconfiguration, as well as to provide a conflict for the
2521 # next change. This change will succeed and merge.
2522 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2523 A.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002524 A.addApproval('code-review', 2)
James E. Blair6bc782d2015-07-17 16:20:21 -07002525
2526 # This change will be in merge conflict. During the
2527 # reconfiguration, we will add a job. We want to make sure
2528 # that doesn't cause it to get stuck.
2529 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
2530 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002531 B.addApproval('code-review', 2)
James E. Blair4eb21fa2015-07-27 14:56:47 -07002532
James E. Blair8b5408c2016-08-08 15:37:46 -07002533 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
2534 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002535
2536 self.waitUntilSettled()
2537
2538 # No jobs have run yet
2539 self.assertEqual(A.data['status'], 'NEW')
2540 self.assertEqual(A.reported, 1)
2541 self.assertEqual(B.data['status'], 'NEW')
2542 self.assertEqual(B.reported, 1)
2543 self.assertEqual(len(self.history), 0)
2544
2545 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002546 self.updateConfigLayout(
2547 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002548 self.sched.reconfigure(self.config)
2549 self.waitUntilSettled()
2550
James E. Blair08d19992016-08-10 15:25:31 -07002551 self.launch_server.hold_jobs_in_build = False
2552 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002553 self.waitUntilSettled()
2554
2555 self.assertEqual(A.data['status'], 'MERGED')
2556 self.assertEqual(A.reported, 2)
2557 self.assertEqual(B.data['status'], 'NEW')
2558 self.assertEqual(B.reported, 2)
2559 self.assertEqual(self.getJobFromHistory('project-merge').result,
2560 'SUCCESS')
2561 self.assertEqual(self.getJobFromHistory('project-test1').result,
2562 'SUCCESS')
2563 self.assertEqual(self.getJobFromHistory('project-test2').result,
2564 'SUCCESS')
2565 self.assertEqual(self.getJobFromHistory('project-test3').result,
2566 'SUCCESS')
2567 self.assertEqual(len(self.history), 4)
2568
James E. Blairec056492016-07-22 09:45:56 -07002569 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002570 def test_live_reconfiguration_failed_root(self):
James E. Blair6bc782d2015-07-17 16:20:21 -07002571 # An extrapolation of test_live_reconfiguration_merge_conflict
2572 # that tests a job added to a job tree with a failed root does
2573 # not run.
2574 self.worker.registerFunction('build:project-test3')
James E. Blair08d19992016-08-10 15:25:31 -07002575 self.launch_server.hold_jobs_in_build = True
James E. Blair6bc782d2015-07-17 16:20:21 -07002576
2577 # This change is fine. It's here to stop the queue long
2578 # enough for the next change to be subject to the
2579 # reconfiguration. This change will succeed and merge.
2580 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2581 A.addPatchset(['conflict'])
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. Blair6bc782d2015-07-17 16:20:21 -07002584 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002585 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002586 self.waitUntilSettled()
2587
2588 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair08d19992016-08-10 15:25:31 -07002589 self.launch_server.failJob('project-merge', B)
James E. Blair8b5408c2016-08-08 15:37:46 -07002590 B.addApproval('code-review', 2)
2591 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair6bc782d2015-07-17 16:20:21 -07002592 self.waitUntilSettled()
2593
James E. Blair08d19992016-08-10 15:25:31 -07002594 self.launch_server.release('.*-merge')
James E. Blair6bc782d2015-07-17 16:20:21 -07002595 self.waitUntilSettled()
2596
2597 # Both -merge jobs have run, but no others.
2598 self.assertEqual(A.data['status'], 'NEW')
2599 self.assertEqual(A.reported, 1)
2600 self.assertEqual(B.data['status'], 'NEW')
2601 self.assertEqual(B.reported, 1)
2602 self.assertEqual(self.history[0].result, 'SUCCESS')
2603 self.assertEqual(self.history[0].name, 'project-merge')
2604 self.assertEqual(self.history[1].result, 'FAILURE')
2605 self.assertEqual(self.history[1].name, 'project-merge')
2606 self.assertEqual(len(self.history), 2)
2607
2608 # Add the "project-test3" job.
James E. Blairf84026c2015-12-08 16:11:46 -08002609 self.updateConfigLayout(
2610 'tests/fixtures/layout-live-reconfiguration-add-job.yaml')
James E. Blair6bc782d2015-07-17 16:20:21 -07002611 self.sched.reconfigure(self.config)
2612 self.waitUntilSettled()
2613
James E. Blair08d19992016-08-10 15:25:31 -07002614 self.launch_server.hold_jobs_in_build = False
2615 self.launch_server.release()
James E. Blair6bc782d2015-07-17 16:20:21 -07002616 self.waitUntilSettled()
2617
2618 self.assertEqual(A.data['status'], 'MERGED')
2619 self.assertEqual(A.reported, 2)
2620 self.assertEqual(B.data['status'], 'NEW')
2621 self.assertEqual(B.reported, 2)
2622 self.assertEqual(self.history[0].result, 'SUCCESS')
2623 self.assertEqual(self.history[0].name, 'project-merge')
2624 self.assertEqual(self.history[1].result, 'FAILURE')
2625 self.assertEqual(self.history[1].name, 'project-merge')
2626 self.assertEqual(self.history[2].result, 'SUCCESS')
2627 self.assertEqual(self.history[3].result, 'SUCCESS')
2628 self.assertEqual(self.history[4].result, 'SUCCESS')
2629 self.assertEqual(len(self.history), 5)
2630
James E. Blairec056492016-07-22 09:45:56 -07002631 @skip("Disabled for early v3 development")
James E. Blair400e8fd2015-07-30 17:44:45 -07002632 def test_live_reconfiguration_failed_job(self):
2633 # Test that a change with a removed failing job does not
2634 # disrupt reconfiguration. If a change has a failed job and
2635 # that job is removed during a reconfiguration, we observed a
2636 # bug where the code to re-set build statuses would run on
2637 # that build and raise an exception because the job no longer
2638 # existed.
James E. Blair08d19992016-08-10 15:25:31 -07002639 self.launch_server.hold_jobs_in_build = True
James E. Blair400e8fd2015-07-30 17:44:45 -07002640
2641 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2642
2643 # This change will fail and later be removed by the reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002644 self.launch_server.failJob('project-test1', A)
James E. Blair400e8fd2015-07-30 17:44:45 -07002645
2646 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2647 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002648 self.launch_server.release('.*-merge')
James E. Blair400e8fd2015-07-30 17:44:45 -07002649 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002650 self.launch_server.release('project-test1')
James E. Blair400e8fd2015-07-30 17:44:45 -07002651 self.waitUntilSettled()
2652
2653 self.assertEqual(A.data['status'], 'NEW')
2654 self.assertEqual(A.reported, 0)
2655
2656 self.assertEqual(self.getJobFromHistory('project-merge').result,
2657 'SUCCESS')
2658 self.assertEqual(self.getJobFromHistory('project-test1').result,
2659 'FAILURE')
2660 self.assertEqual(len(self.history), 2)
2661
2662 # Remove the test1 job.
James E. Blairf84026c2015-12-08 16:11:46 -08002663 self.updateConfigLayout(
2664 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml')
James E. Blair400e8fd2015-07-30 17:44:45 -07002665 self.sched.reconfigure(self.config)
2666 self.waitUntilSettled()
2667
James E. Blair08d19992016-08-10 15:25:31 -07002668 self.launch_server.hold_jobs_in_build = False
2669 self.launch_server.release()
James E. Blair400e8fd2015-07-30 17:44:45 -07002670 self.waitUntilSettled()
2671
2672 self.assertEqual(self.getJobFromHistory('project-test2').result,
2673 'SUCCESS')
2674 self.assertEqual(self.getJobFromHistory('project-testfile').result,
2675 'SUCCESS')
2676 self.assertEqual(len(self.history), 4)
2677
2678 self.assertEqual(A.data['status'], 'NEW')
2679 self.assertEqual(A.reported, 1)
2680 self.assertIn('Build succeeded', A.messages[0])
2681 # Ensure the removed job was not included in the report.
2682 self.assertNotIn('project-test1', A.messages[0])
2683
James E. Blairec056492016-07-22 09:45:56 -07002684 @skip("Disabled for early v3 development")
James E. Blairfe707d12015-08-05 15:18:15 -07002685 def test_live_reconfiguration_shared_queue(self):
2686 # Test that a change with a failing job which was removed from
2687 # this project but otherwise still exists in the system does
2688 # not disrupt reconfiguration.
2689
James E. Blair08d19992016-08-10 15:25:31 -07002690 self.launch_server.hold_jobs_in_build = True
James E. Blairfe707d12015-08-05 15:18:15 -07002691
2692 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2693
James E. Blair08d19992016-08-10 15:25:31 -07002694 self.launch_server.failJob('project1-project2-integration', A)
James E. Blairfe707d12015-08-05 15:18:15 -07002695
2696 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2697 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002698 self.launch_server.release('.*-merge')
James E. Blairfe707d12015-08-05 15:18:15 -07002699 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002700 self.launch_server.release('project1-project2-integration')
James E. Blairfe707d12015-08-05 15:18:15 -07002701 self.waitUntilSettled()
2702
2703 self.assertEqual(A.data['status'], 'NEW')
2704 self.assertEqual(A.reported, 0)
2705
2706 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2707 'SUCCESS')
2708 self.assertEqual(self.getJobFromHistory(
2709 'project1-project2-integration').result, 'FAILURE')
2710 self.assertEqual(len(self.history), 2)
2711
2712 # Remove the integration job.
James E. Blairf84026c2015-12-08 16:11:46 -08002713 self.updateConfigLayout(
2714 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml')
James E. Blairfe707d12015-08-05 15:18:15 -07002715 self.sched.reconfigure(self.config)
2716 self.waitUntilSettled()
2717
James E. Blair08d19992016-08-10 15:25:31 -07002718 self.launch_server.hold_jobs_in_build = False
2719 self.launch_server.release()
James E. Blairfe707d12015-08-05 15:18:15 -07002720 self.waitUntilSettled()
2721
2722 self.assertEqual(self.getJobFromHistory('project1-merge').result,
2723 'SUCCESS')
2724 self.assertEqual(self.getJobFromHistory('project1-test1').result,
2725 'SUCCESS')
2726 self.assertEqual(self.getJobFromHistory('project1-test2').result,
2727 'SUCCESS')
2728 self.assertEqual(self.getJobFromHistory(
2729 'project1-project2-integration').result, 'FAILURE')
2730 self.assertEqual(len(self.history), 4)
2731
2732 self.assertEqual(A.data['status'], 'NEW')
2733 self.assertEqual(A.reported, 1)
2734 self.assertIn('Build succeeded', A.messages[0])
2735 # Ensure the removed job was not included in the report.
2736 self.assertNotIn('project1-project2-integration', A.messages[0])
2737
James E. Blairec056492016-07-22 09:45:56 -07002738 @skip("Disabled for early v3 development")
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002739 def test_double_live_reconfiguration_shared_queue(self):
2740 # This was a real-world regression. A change is added to
2741 # gate; a reconfigure happens, a second change which depends
2742 # on the first is added, and a second reconfiguration happens.
2743 # Ensure that both changes merge.
2744
2745 # A failure may indicate incorrect caching or cleaning up of
2746 # references during a reconfiguration.
James E. Blair08d19992016-08-10 15:25:31 -07002747 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002748
2749 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2750 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2751 B.setDependsOn(A, 1)
James E. Blair8b5408c2016-08-08 15:37:46 -07002752 A.addApproval('code-review', 2)
2753 B.addApproval('code-review', 2)
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002754
2755 # Add the parent change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002756 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002757 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002758 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002759 self.waitUntilSettled()
2760
2761 # Reconfigure (with only one change in the pipeline).
2762 self.sched.reconfigure(self.config)
2763 self.waitUntilSettled()
2764
2765 # Add the child change.
James E. Blair8b5408c2016-08-08 15:37:46 -07002766 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002767 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002768 self.launch_server.release('.*-merge')
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002769 self.waitUntilSettled()
2770
2771 # Reconfigure (with both in the pipeline).
2772 self.sched.reconfigure(self.config)
2773 self.waitUntilSettled()
2774
James E. Blair08d19992016-08-10 15:25:31 -07002775 self.launch_server.hold_jobs_in_build = False
2776 self.launch_server.release()
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11002777 self.waitUntilSettled()
2778
2779 self.assertEqual(len(self.history), 8)
2780
2781 self.assertEqual(A.data['status'], 'MERGED')
2782 self.assertEqual(A.reported, 2)
2783 self.assertEqual(B.data['status'], 'MERGED')
2784 self.assertEqual(B.reported, 2)
2785
James E. Blairec056492016-07-22 09:45:56 -07002786 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002787 def test_live_reconfiguration_del_project(self):
2788 # Test project deletion from layout
2789 # while changes are enqueued
2790
James E. Blair08d19992016-08-10 15:25:31 -07002791 self.launch_server.hold_jobs_in_build = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002792 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
2793 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
2794 C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C')
2795
2796 # A Depends-On: B
2797 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
2798 A.subject, B.data['id'])
James E. Blair8b5408c2016-08-08 15:37:46 -07002799 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002800
2801 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2802 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
2803 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07002804 self.launch_server.release('.*-merge')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002805 self.waitUntilSettled()
2806 self.assertEqual(len(self.builds), 5)
2807
2808 # This layout defines only org/project, not org/project1
James E. Blairf84026c2015-12-08 16:11:46 -08002809 self.updateConfigLayout(
2810 'tests/fixtures/layout-live-reconfiguration-del-project.yaml')
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002811 self.sched.reconfigure(self.config)
2812 self.waitUntilSettled()
2813
2814 # Builds for C aborted, builds for A succeed,
2815 # and have change B applied ahead
2816 job_c = self.getJobFromHistory('project1-test1')
2817 self.assertEqual(job_c.changes, '3,1')
2818 self.assertEqual(job_c.result, 'ABORTED')
2819
James E. Blair08d19992016-08-10 15:25:31 -07002820 self.launch_server.hold_jobs_in_build = False
2821 self.launch_server.release()
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00002822 self.waitUntilSettled()
2823
2824 self.assertEqual(self.getJobFromHistory('project-test1').changes,
2825 '2,1 1,1')
2826
2827 self.assertEqual(A.data['status'], 'NEW')
2828 self.assertEqual(B.data['status'], 'NEW')
2829 self.assertEqual(C.data['status'], 'NEW')
2830 self.assertEqual(A.reported, 1)
2831 self.assertEqual(B.reported, 0)
2832 self.assertEqual(C.reported, 0)
2833
2834 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
2835 self.assertIn('Build succeeded', A.messages[0])
2836
James E. Blairec056492016-07-22 09:45:56 -07002837 @skip("Disabled for early v3 development")
James E. Blaire712d9f2013-07-31 11:40:11 -07002838 def test_live_reconfiguration_functions(self):
2839 "Test live reconfiguration with a custom function"
2840 self.worker.registerFunction('build:node-project-test1:debian')
2841 self.worker.registerFunction('build:node-project-test1:wheezy')
2842 A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07002843 A.addApproval('code-review', 2)
2844 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002845 self.waitUntilSettled()
2846
2847 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2848 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2849 'debian')
2850 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2851
James E. Blairf84026c2015-12-08 16:11:46 -08002852 self.updateConfigLayout(
2853 'tests/fixtures/layout-live-reconfiguration-functions.yaml')
James E. Blaire712d9f2013-07-31 11:40:11 -07002854 self.sched.reconfigure(self.config)
2855 self.worker.build_history = []
2856
2857 B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07002858 B.addApproval('code-review', 2)
2859 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blaire712d9f2013-07-31 11:40:11 -07002860 self.waitUntilSettled()
2861
2862 self.assertIsNone(self.getJobFromHistory('node-project-merge').node)
2863 self.assertEqual(self.getJobFromHistory('node-project-test1').node,
2864 'wheezy')
2865 self.assertIsNone(self.getJobFromHistory('node-project-test2').node)
2866
James E. Blairec056492016-07-22 09:45:56 -07002867 @skip("Disabled for early v3 development")
James E. Blair287c06d2013-07-24 10:39:30 -07002868 def test_delayed_repo_init(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002869 self.updateConfigLayout(
2870 'tests/fixtures/layout-delayed-repo-init.yaml')
James E. Blair287c06d2013-07-24 10:39:30 -07002871 self.sched.reconfigure(self.config)
2872
2873 self.init_repo("org/new-project")
2874 A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A')
2875
James E. Blair8b5408c2016-08-08 15:37:46 -07002876 A.addApproval('code-review', 2)
2877 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair287c06d2013-07-24 10:39:30 -07002878 self.waitUntilSettled()
2879 self.assertEqual(self.getJobFromHistory('project-merge').result,
2880 'SUCCESS')
2881 self.assertEqual(self.getJobFromHistory('project-test1').result,
2882 'SUCCESS')
2883 self.assertEqual(self.getJobFromHistory('project-test2').result,
2884 'SUCCESS')
2885 self.assertEqual(A.data['status'], 'MERGED')
2886 self.assertEqual(A.reported, 2)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002887
James E. Blairec056492016-07-22 09:45:56 -07002888 @skip("Disabled for early v3 development")
Clark Boylan6dbbc482013-10-18 10:57:31 -07002889 def test_repo_deleted(self):
James E. Blairf84026c2015-12-08 16:11:46 -08002890 self.updateConfigLayout(
2891 'tests/fixtures/layout-repo-deleted.yaml')
Clark Boylan6dbbc482013-10-18 10:57:31 -07002892 self.sched.reconfigure(self.config)
2893
2894 self.init_repo("org/delete-project")
2895 A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A')
2896
James E. Blair8b5408c2016-08-08 15:37:46 -07002897 A.addApproval('code-review', 2)
2898 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002899 self.waitUntilSettled()
2900 self.assertEqual(self.getJobFromHistory('project-merge').result,
2901 'SUCCESS')
2902 self.assertEqual(self.getJobFromHistory('project-test1').result,
2903 'SUCCESS')
2904 self.assertEqual(self.getJobFromHistory('project-test2').result,
2905 'SUCCESS')
2906 self.assertEqual(A.data['status'], 'MERGED')
2907 self.assertEqual(A.reported, 2)
2908
2909 # Delete org/new-project zuul repo. Should be recloned.
2910 shutil.rmtree(os.path.join(self.git_root, "org/delete-project"))
2911
2912 B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B')
2913
James E. Blair8b5408c2016-08-08 15:37:46 -07002914 B.addApproval('code-review', 2)
2915 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Clark Boylan6dbbc482013-10-18 10:57:31 -07002916 self.waitUntilSettled()
2917 self.assertEqual(self.getJobFromHistory('project-merge').result,
2918 'SUCCESS')
2919 self.assertEqual(self.getJobFromHistory('project-test1').result,
2920 'SUCCESS')
2921 self.assertEqual(self.getJobFromHistory('project-test2').result,
2922 'SUCCESS')
2923 self.assertEqual(B.data['status'], 'MERGED')
2924 self.assertEqual(B.reported, 2)
2925
James E. Blairec056492016-07-22 09:45:56 -07002926 @skip("Disabled for early v3 development")
James E. Blair456f2fb2016-02-09 09:29:33 -08002927 def test_tags(self):
2928 "Test job tags"
2929 self.config.set('zuul', 'layout_config',
2930 'tests/fixtures/layout-tags.yaml')
2931 self.sched.reconfigure(self.config)
2932
2933 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
2934 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
2935 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
2936 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
2937 self.waitUntilSettled()
2938
2939 results = {'project1-merge': 'extratag merge project1',
2940 'project2-merge': 'merge'}
2941
2942 for build in self.history:
2943 self.assertEqual(results.get(build.name, ''),
2944 build.parameters.get('BUILD_TAGS'))
2945
James E. Blairec056492016-07-22 09:45:56 -07002946 @skip("Disabled for early v3 development")
James E. Blair63bb0ef2013-07-29 17:14:51 -07002947 def test_timer(self):
2948 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07002949 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08002950 self.updateConfigLayout(
2951 'tests/fixtures/layout-timer.yaml')
James E. Blair63bb0ef2013-07-29 17:14:51 -07002952 self.sched.reconfigure(self.config)
2953 self.registerJobs()
2954
Clark Boylan3ee090a2014-04-03 20:55:09 -07002955 # The pipeline triggers every second, so we should have seen
2956 # several by now.
2957 time.sleep(5)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002958 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07002959
2960 self.assertEqual(len(self.builds), 2)
2961
James E. Blair63bb0ef2013-07-29 17:14:51 -07002962 port = self.webapp.server.socket.getsockname()[1]
2963
Morgan Fainberg293f7f82016-05-30 14:01:22 -07002964 req = urllib.request.Request("http://localhost:%s/status.json" % port)
2965 f = urllib.request.urlopen(req)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002966 data = f.read()
2967
James E. Blair08d19992016-08-10 15:25:31 -07002968 self.launch_server.hold_jobs_in_build = False
Clark Boylan3ee090a2014-04-03 20:55:09 -07002969 # Stop queuing timer triggered jobs so that the assertions
2970 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08002971 self.updateConfigLayout(
2972 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07002973 self.sched.reconfigure(self.config)
2974 self.registerJobs()
James E. Blair08d19992016-08-10 15:25:31 -07002975 self.launch_server.release()
James E. Blair63bb0ef2013-07-29 17:14:51 -07002976 self.waitUntilSettled()
2977
2978 self.assertEqual(self.getJobFromHistory(
2979 'project-bitrot-stable-old').result, 'SUCCESS')
2980 self.assertEqual(self.getJobFromHistory(
2981 'project-bitrot-stable-older').result, 'SUCCESS')
2982
2983 data = json.loads(data)
2984 status_jobs = set()
2985 for p in data['pipelines']:
2986 for q in p['change_queues']:
2987 for head in q['heads']:
2988 for change in head:
Alex Gaynorddb9ef32013-09-16 21:04:58 -07002989 self.assertEqual(change['id'], None)
James E. Blair63bb0ef2013-07-29 17:14:51 -07002990 for job in change['jobs']:
2991 status_jobs.add(job['name'])
2992 self.assertIn('project-bitrot-stable-old', status_jobs)
2993 self.assertIn('project-bitrot-stable-older', status_jobs)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10002994
James E. Blairec056492016-07-22 09:45:56 -07002995 @skip("Disabled for early v3 development")
James E. Blair4f6033c2014-03-27 15:49:09 -07002996 def test_idle(self):
2997 "Test that frequent periodic jobs work"
James E. Blair08d19992016-08-10 15:25:31 -07002998 self.launch_server.hold_jobs_in_build = True
James E. Blair4f6033c2014-03-27 15:49:09 -07002999
Clark Boylan3ee090a2014-04-03 20:55:09 -07003000 for x in range(1, 3):
3001 # Test that timer triggers periodic jobs even across
3002 # layout config reloads.
3003 # Start timer trigger
James E. Blairf84026c2015-12-08 16:11:46 -08003004 self.updateConfigLayout(
3005 'tests/fixtures/layout-idle.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003006 self.sched.reconfigure(self.config)
3007 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003008 self.waitUntilSettled()
James E. Blair4f6033c2014-03-27 15:49:09 -07003009
Clark Boylan3ee090a2014-04-03 20:55:09 -07003010 # The pipeline triggers every second, so we should have seen
3011 # several by now.
3012 time.sleep(5)
Clark Boylan3ee090a2014-04-03 20:55:09 -07003013
3014 # Stop queuing timer triggered jobs so that the assertions
3015 # below don't race against more jobs being queued.
James E. Blairf84026c2015-12-08 16:11:46 -08003016 self.updateConfigLayout(
3017 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003018 self.sched.reconfigure(self.config)
3019 self.registerJobs()
James E. Blair995fc0f2016-02-04 16:48:31 -08003020 self.waitUntilSettled()
Clark Boylan3ee090a2014-04-03 20:55:09 -07003021
3022 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003023 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003024 self.waitUntilSettled()
3025 self.assertEqual(len(self.builds), 0)
3026 self.assertEqual(len(self.history), x * 2)
James E. Blair4f6033c2014-03-27 15:49:09 -07003027
James E. Blairec056492016-07-22 09:45:56 -07003028 @skip("Disabled for early v3 development")
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003029 def test_check_smtp_pool(self):
James E. Blairf84026c2015-12-08 16:11:46 -08003030 self.updateConfigLayout(
3031 'tests/fixtures/layout-smtp.yaml')
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003032 self.sched.reconfigure(self.config)
3033
3034 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3035 self.waitUntilSettled()
3036
3037 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3038 self.waitUntilSettled()
3039
James E. Blairff80a2f2013-12-27 13:24:06 -08003040 self.assertEqual(len(self.smtp_messages), 2)
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003041
3042 # A.messages only holds what FakeGerrit places in it. Thus we
3043 # work on the knowledge of what the first message should be as
3044 # it is only configured to go to SMTP.
3045
3046 self.assertEqual('zuul@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003047 self.smtp_messages[0]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003048 self.assertEqual(['you@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003049 self.smtp_messages[0]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003050 self.assertEqual('Starting check jobs.',
James E. Blairff80a2f2013-12-27 13:24:06 -08003051 self.smtp_messages[0]['body'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003052
3053 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003054 self.smtp_messages[1]['from_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003055 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003056 self.smtp_messages[1]['to_email'])
Joshua Hesketh5fea8672013-08-19 17:32:01 +10003057 self.assertEqual(A.messages[0],
James E. Blairff80a2f2013-12-27 13:24:06 -08003058 self.smtp_messages[1]['body'])
James E. Blairad28e912013-11-27 10:43:22 -08003059
James E. Blairec056492016-07-22 09:45:56 -07003060 @skip("Disabled for early v3 development")
James E. Blaire5910202013-12-27 09:50:31 -08003061 def test_timer_smtp(self):
3062 "Test that a periodic job is triggered"
James E. Blair08d19992016-08-10 15:25:31 -07003063 self.launch_server.hold_jobs_in_build = True
James E. Blairf84026c2015-12-08 16:11:46 -08003064 self.updateConfigLayout(
3065 'tests/fixtures/layout-timer-smtp.yaml')
James E. Blaire5910202013-12-27 09:50:31 -08003066 self.sched.reconfigure(self.config)
3067 self.registerJobs()
3068
Clark Boylan3ee090a2014-04-03 20:55:09 -07003069 # The pipeline triggers every second, so we should have seen
3070 # several by now.
3071 time.sleep(5)
James E. Blaire5910202013-12-27 09:50:31 -08003072 self.waitUntilSettled()
3073
Clark Boylan3ee090a2014-04-03 20:55:09 -07003074 self.assertEqual(len(self.builds), 2)
James E. Blair08d19992016-08-10 15:25:31 -07003075 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003076 self.waitUntilSettled()
3077 self.assertEqual(len(self.history), 2)
3078
James E. Blaire5910202013-12-27 09:50:31 -08003079 self.assertEqual(self.getJobFromHistory(
3080 'project-bitrot-stable-old').result, 'SUCCESS')
3081 self.assertEqual(self.getJobFromHistory(
3082 'project-bitrot-stable-older').result, 'SUCCESS')
3083
James E. Blairff80a2f2013-12-27 13:24:06 -08003084 self.assertEqual(len(self.smtp_messages), 1)
James E. Blaire5910202013-12-27 09:50:31 -08003085
3086 # A.messages only holds what FakeGerrit places in it. Thus we
3087 # work on the knowledge of what the first message should be as
3088 # it is only configured to go to SMTP.
3089
3090 self.assertEqual('zuul_from@example.com',
James E. Blairff80a2f2013-12-27 13:24:06 -08003091 self.smtp_messages[0]['from_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003092 self.assertEqual(['alternative_me@example.com'],
James E. Blairff80a2f2013-12-27 13:24:06 -08003093 self.smtp_messages[0]['to_email'])
James E. Blaire5910202013-12-27 09:50:31 -08003094 self.assertIn('Subject: Periodic check for org/project succeeded',
James E. Blairff80a2f2013-12-27 13:24:06 -08003095 self.smtp_messages[0]['headers'])
James E. Blaire5910202013-12-27 09:50:31 -08003096
Clark Boylan3ee090a2014-04-03 20:55:09 -07003097 # Stop queuing timer triggered jobs and let any that may have
3098 # queued through so that end of test assertions pass.
James E. Blairf84026c2015-12-08 16:11:46 -08003099 self.updateConfigLayout(
3100 'tests/fixtures/layout-no-timer.yaml')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003101 self.sched.reconfigure(self.config)
3102 self.registerJobs()
James E. Blairf8058972014-08-15 16:09:16 -07003103 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003104 self.launch_server.release('.*')
Clark Boylan3ee090a2014-04-03 20:55:09 -07003105 self.waitUntilSettled()
3106
James E. Blairec056492016-07-22 09:45:56 -07003107 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003108 def test_client_enqueue_change(self):
James E. Blairad28e912013-11-27 10:43:22 -08003109 "Test that the RPC client can enqueue a change"
3110 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003111 A.addApproval('code-review', 2)
3112 A.addApproval('approved', 1)
James E. Blairad28e912013-11-27 10:43:22 -08003113
3114 client = zuul.rpcclient.RPCClient('127.0.0.1',
3115 self.gearman_server.port)
3116 r = client.enqueue(pipeline='gate',
3117 project='org/project',
3118 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003119 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003120 self.waitUntilSettled()
3121 self.assertEqual(self.getJobFromHistory('project-merge').result,
3122 'SUCCESS')
3123 self.assertEqual(self.getJobFromHistory('project-test1').result,
3124 'SUCCESS')
3125 self.assertEqual(self.getJobFromHistory('project-test2').result,
3126 'SUCCESS')
3127 self.assertEqual(A.data['status'], 'MERGED')
3128 self.assertEqual(A.reported, 2)
3129 self.assertEqual(r, True)
3130
James E. Blairec056492016-07-22 09:45:56 -07003131 @skip("Disabled for early v3 development")
James E. Blair91e34592015-07-31 16:45:59 -07003132 def test_client_enqueue_ref(self):
3133 "Test that the RPC client can enqueue a ref"
3134
3135 client = zuul.rpcclient.RPCClient('127.0.0.1',
3136 self.gearman_server.port)
3137 r = client.enqueue_ref(
3138 pipeline='post',
3139 project='org/project',
3140 trigger='gerrit',
3141 ref='master',
3142 oldrev='90f173846e3af9154517b88543ffbd1691f31366',
3143 newrev='d479a0bfcb34da57a31adb2a595c0cf687812543')
3144 self.waitUntilSettled()
3145 job_names = [x.name for x in self.history]
3146 self.assertEqual(len(self.history), 1)
3147 self.assertIn('project-post', job_names)
3148 self.assertEqual(r, True)
3149
James E. Blairec056492016-07-22 09:45:56 -07003150 @skip("Disabled for early v3 development")
James E. Blairad28e912013-11-27 10:43:22 -08003151 def test_client_enqueue_negative(self):
3152 "Test that the RPC client returns errors"
3153 client = zuul.rpcclient.RPCClient('127.0.0.1',
3154 self.gearman_server.port)
3155 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3156 "Invalid project"):
3157 r = client.enqueue(pipeline='gate',
3158 project='project-does-not-exist',
3159 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003160 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003161 client.shutdown()
3162 self.assertEqual(r, False)
3163
3164 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3165 "Invalid pipeline"):
3166 r = client.enqueue(pipeline='pipeline-does-not-exist',
3167 project='org/project',
3168 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003169 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003170 client.shutdown()
3171 self.assertEqual(r, False)
3172
3173 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3174 "Invalid trigger"):
3175 r = client.enqueue(pipeline='gate',
3176 project='org/project',
3177 trigger='trigger-does-not-exist',
James E. Blair36658cf2013-12-06 17:53:48 -08003178 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003179 client.shutdown()
3180 self.assertEqual(r, False)
3181
3182 with testtools.ExpectedException(zuul.rpcclient.RPCFailure,
3183 "Invalid change"):
3184 r = client.enqueue(pipeline='gate',
3185 project='org/project',
3186 trigger='gerrit',
James E. Blair36658cf2013-12-06 17:53:48 -08003187 change='1,1')
James E. Blairad28e912013-11-27 10:43:22 -08003188 client.shutdown()
3189 self.assertEqual(r, False)
3190
3191 self.waitUntilSettled()
3192 self.assertEqual(len(self.history), 0)
3193 self.assertEqual(len(self.builds), 0)
James E. Blair36658cf2013-12-06 17:53:48 -08003194
James E. Blairec056492016-07-22 09:45:56 -07003195 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003196 def test_client_promote(self):
3197 "Test that the RPC client can promote a change"
James E. Blair08d19992016-08-10 15:25:31 -07003198 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003199 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3200 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3201 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003202 A.addApproval('code-review', 2)
3203 B.addApproval('code-review', 2)
3204 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003205
James E. Blair8b5408c2016-08-08 15:37:46 -07003206 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3207 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3208 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003209
3210 self.waitUntilSettled()
3211
Sean Daguef39b9ca2014-01-10 21:34:35 -05003212 items = self.sched.layout.pipelines['gate'].getAllItems()
3213 enqueue_times = {}
3214 for item in items:
3215 enqueue_times[str(item.change)] = item.enqueue_time
3216
James E. Blair36658cf2013-12-06 17:53:48 -08003217 client = zuul.rpcclient.RPCClient('127.0.0.1',
3218 self.gearman_server.port)
3219 r = client.promote(pipeline='gate',
3220 change_ids=['2,1', '3,1'])
3221
Sean Daguef39b9ca2014-01-10 21:34:35 -05003222 # ensure that enqueue times are durable
3223 items = self.sched.layout.pipelines['gate'].getAllItems()
3224 for item in items:
3225 self.assertEqual(
3226 enqueue_times[str(item.change)], item.enqueue_time)
3227
James E. Blair78acec92014-02-06 07:11:32 -08003228 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003229 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003230 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003231 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003232 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003233 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003234 self.waitUntilSettled()
3235
3236 self.assertEqual(len(self.builds), 6)
3237 self.assertEqual(self.builds[0].name, 'project-test1')
3238 self.assertEqual(self.builds[1].name, 'project-test2')
3239 self.assertEqual(self.builds[2].name, 'project-test1')
3240 self.assertEqual(self.builds[3].name, 'project-test2')
3241 self.assertEqual(self.builds[4].name, 'project-test1')
3242 self.assertEqual(self.builds[5].name, 'project-test2')
3243
3244 self.assertTrue(self.job_has_changes(self.builds[0], B))
3245 self.assertFalse(self.job_has_changes(self.builds[0], A))
3246 self.assertFalse(self.job_has_changes(self.builds[0], C))
3247
3248 self.assertTrue(self.job_has_changes(self.builds[2], B))
3249 self.assertTrue(self.job_has_changes(self.builds[2], C))
3250 self.assertFalse(self.job_has_changes(self.builds[2], A))
3251
3252 self.assertTrue(self.job_has_changes(self.builds[4], B))
3253 self.assertTrue(self.job_has_changes(self.builds[4], C))
3254 self.assertTrue(self.job_has_changes(self.builds[4], A))
3255
James E. Blair08d19992016-08-10 15:25:31 -07003256 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003257 self.waitUntilSettled()
3258
3259 self.assertEqual(A.data['status'], 'MERGED')
3260 self.assertEqual(A.reported, 2)
3261 self.assertEqual(B.data['status'], 'MERGED')
3262 self.assertEqual(B.reported, 2)
3263 self.assertEqual(C.data['status'], 'MERGED')
3264 self.assertEqual(C.reported, 2)
3265
3266 client.shutdown()
3267 self.assertEqual(r, True)
3268
James E. Blairec056492016-07-22 09:45:56 -07003269 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003270 def test_client_promote_dependent(self):
3271 "Test that the RPC client can promote a dependent change"
3272 # C (depends on B) -> B -> A ; then promote C to get:
3273 # A -> C (depends on B) -> B
James E. Blair08d19992016-08-10 15:25:31 -07003274 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003275 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3276 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3277 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3278
3279 C.setDependsOn(B, 1)
3280
James E. Blair8b5408c2016-08-08 15:37:46 -07003281 A.addApproval('code-review', 2)
3282 B.addApproval('code-review', 2)
3283 C.addApproval('code-review', 2)
James E. Blair36658cf2013-12-06 17:53:48 -08003284
James E. Blair8b5408c2016-08-08 15:37:46 -07003285 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3286 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3287 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003288
3289 self.waitUntilSettled()
3290
3291 client = zuul.rpcclient.RPCClient('127.0.0.1',
3292 self.gearman_server.port)
3293 r = client.promote(pipeline='gate',
3294 change_ids=['3,1'])
3295
James E. Blair78acec92014-02-06 07:11:32 -08003296 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003297 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003298 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003299 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003300 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003301 self.launch_server.release('.*-merge')
James E. Blair36658cf2013-12-06 17:53:48 -08003302 self.waitUntilSettled()
3303
3304 self.assertEqual(len(self.builds), 6)
3305 self.assertEqual(self.builds[0].name, 'project-test1')
3306 self.assertEqual(self.builds[1].name, 'project-test2')
3307 self.assertEqual(self.builds[2].name, 'project-test1')
3308 self.assertEqual(self.builds[3].name, 'project-test2')
3309 self.assertEqual(self.builds[4].name, 'project-test1')
3310 self.assertEqual(self.builds[5].name, 'project-test2')
3311
3312 self.assertTrue(self.job_has_changes(self.builds[0], B))
3313 self.assertFalse(self.job_has_changes(self.builds[0], A))
3314 self.assertFalse(self.job_has_changes(self.builds[0], C))
3315
3316 self.assertTrue(self.job_has_changes(self.builds[2], B))
3317 self.assertTrue(self.job_has_changes(self.builds[2], C))
3318 self.assertFalse(self.job_has_changes(self.builds[2], A))
3319
3320 self.assertTrue(self.job_has_changes(self.builds[4], B))
3321 self.assertTrue(self.job_has_changes(self.builds[4], C))
3322 self.assertTrue(self.job_has_changes(self.builds[4], A))
3323
James E. Blair08d19992016-08-10 15:25:31 -07003324 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003325 self.waitUntilSettled()
3326
3327 self.assertEqual(A.data['status'], 'MERGED')
3328 self.assertEqual(A.reported, 2)
3329 self.assertEqual(B.data['status'], 'MERGED')
3330 self.assertEqual(B.reported, 2)
3331 self.assertEqual(C.data['status'], 'MERGED')
3332 self.assertEqual(C.reported, 2)
3333
3334 client.shutdown()
3335 self.assertEqual(r, True)
3336
James E. Blairec056492016-07-22 09:45:56 -07003337 @skip("Disabled for early v3 development")
James E. Blair36658cf2013-12-06 17:53:48 -08003338 def test_client_promote_negative(self):
3339 "Test that the RPC client returns errors for promotion"
James E. Blair08d19992016-08-10 15:25:31 -07003340 self.launch_server.hold_jobs_in_build = True
James E. Blair36658cf2013-12-06 17:53:48 -08003341 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003342 A.addApproval('code-review', 2)
3343 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair36658cf2013-12-06 17:53:48 -08003344 self.waitUntilSettled()
3345
3346 client = zuul.rpcclient.RPCClient('127.0.0.1',
3347 self.gearman_server.port)
3348
3349 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3350 r = client.promote(pipeline='nonexistent',
3351 change_ids=['2,1', '3,1'])
3352 client.shutdown()
3353 self.assertEqual(r, False)
3354
3355 with testtools.ExpectedException(zuul.rpcclient.RPCFailure):
3356 r = client.promote(pipeline='gate',
3357 change_ids=['4,1'])
3358 client.shutdown()
3359 self.assertEqual(r, False)
3360
James E. Blair08d19992016-08-10 15:25:31 -07003361 self.launch_server.hold_jobs_in_build = False
3362 self.launch_server.release()
James E. Blair36658cf2013-12-06 17:53:48 -08003363 self.waitUntilSettled()
Clark Boylan7603a372014-01-21 11:43:20 -08003364
James E. Blairec056492016-07-22 09:45:56 -07003365 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003366 def test_queue_rate_limiting(self):
3367 "Test that DependentPipelines are rate limited with dep across window"
James E. Blairf84026c2015-12-08 16:11:46 -08003368 self.updateConfigLayout(
3369 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003370 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003371 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003372 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3373 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3374 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3375
3376 C.setDependsOn(B, 1)
James E. Blair08d19992016-08-10 15:25:31 -07003377 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003378
James E. Blair8b5408c2016-08-08 15:37:46 -07003379 A.addApproval('code-review', 2)
3380 B.addApproval('code-review', 2)
3381 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003382
James E. Blair8b5408c2016-08-08 15:37:46 -07003383 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3384 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3385 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003386 self.waitUntilSettled()
3387
3388 # Only A and B will have their merge jobs queued because
3389 # window is 2.
3390 self.assertEqual(len(self.builds), 2)
3391 self.assertEqual(self.builds[0].name, 'project-merge')
3392 self.assertEqual(self.builds[1].name, 'project-merge')
3393
James E. Blair08d19992016-08-10 15:25:31 -07003394 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003395 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003396 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003397 self.waitUntilSettled()
3398
3399 # Only A and B will have their test jobs queued because
3400 # window is 2.
3401 self.assertEqual(len(self.builds), 4)
3402 self.assertEqual(self.builds[0].name, 'project-test1')
3403 self.assertEqual(self.builds[1].name, 'project-test2')
3404 self.assertEqual(self.builds[2].name, 'project-test1')
3405 self.assertEqual(self.builds[3].name, 'project-test2')
3406
James E. Blair08d19992016-08-10 15:25:31 -07003407 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003408 self.waitUntilSettled()
3409
3410 queue = self.sched.layout.pipelines['gate'].queues[0]
3411 # A failed so window is reduced by 1 to 1.
3412 self.assertEqual(queue.window, 1)
3413 self.assertEqual(queue.window_floor, 1)
3414 self.assertEqual(A.data['status'], 'NEW')
3415
3416 # Gate is reset and only B's merge job is queued because
3417 # window shrunk to 1.
3418 self.assertEqual(len(self.builds), 1)
3419 self.assertEqual(self.builds[0].name, 'project-merge')
3420
James E. Blair08d19992016-08-10 15:25:31 -07003421 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003422 self.waitUntilSettled()
3423
3424 # Only B's test jobs are queued because window is still 1.
3425 self.assertEqual(len(self.builds), 2)
3426 self.assertEqual(self.builds[0].name, 'project-test1')
3427 self.assertEqual(self.builds[1].name, 'project-test2')
3428
James E. Blair08d19992016-08-10 15:25:31 -07003429 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003430 self.waitUntilSettled()
3431
3432 # B was successfully merged so window is increased to 2.
3433 self.assertEqual(queue.window, 2)
3434 self.assertEqual(queue.window_floor, 1)
3435 self.assertEqual(B.data['status'], 'MERGED')
3436
3437 # Only C is left and its merge job is queued.
3438 self.assertEqual(len(self.builds), 1)
3439 self.assertEqual(self.builds[0].name, 'project-merge')
3440
James E. Blair08d19992016-08-10 15:25:31 -07003441 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003442 self.waitUntilSettled()
3443
3444 # After successful merge job the test jobs for C are queued.
3445 self.assertEqual(len(self.builds), 2)
3446 self.assertEqual(self.builds[0].name, 'project-test1')
3447 self.assertEqual(self.builds[1].name, 'project-test2')
3448
James E. Blair08d19992016-08-10 15:25:31 -07003449 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003450 self.waitUntilSettled()
3451
3452 # C successfully merged so window is bumped to 3.
3453 self.assertEqual(queue.window, 3)
3454 self.assertEqual(queue.window_floor, 1)
3455 self.assertEqual(C.data['status'], 'MERGED')
3456
James E. Blairec056492016-07-22 09:45:56 -07003457 @skip("Disabled for early v3 development")
Clark Boylan7603a372014-01-21 11:43:20 -08003458 def test_queue_rate_limiting_dependent(self):
3459 "Test that DependentPipelines are rate limited with dep in window"
James E. Blairf84026c2015-12-08 16:11:46 -08003460 self.updateConfigLayout(
3461 'tests/fixtures/layout-rate-limit.yaml')
Clark Boylan7603a372014-01-21 11:43:20 -08003462 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07003463 self.launch_server.hold_jobs_in_build = True
Clark Boylan7603a372014-01-21 11:43:20 -08003464 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3465 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3466 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3467
3468 B.setDependsOn(A, 1)
3469
James E. Blair08d19992016-08-10 15:25:31 -07003470 self.launch_server.failJob('project-test1', A)
Clark Boylan7603a372014-01-21 11:43:20 -08003471
James E. Blair8b5408c2016-08-08 15:37:46 -07003472 A.addApproval('code-review', 2)
3473 B.addApproval('code-review', 2)
3474 C.addApproval('code-review', 2)
Clark Boylan7603a372014-01-21 11:43:20 -08003475
James E. Blair8b5408c2016-08-08 15:37:46 -07003476 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3477 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3478 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Clark Boylan7603a372014-01-21 11:43:20 -08003479 self.waitUntilSettled()
3480
3481 # Only A and B will have their merge jobs queued because
3482 # window is 2.
3483 self.assertEqual(len(self.builds), 2)
3484 self.assertEqual(self.builds[0].name, 'project-merge')
3485 self.assertEqual(self.builds[1].name, 'project-merge')
3486
James E. Blair08d19992016-08-10 15:25:31 -07003487 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003488 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003489 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003490 self.waitUntilSettled()
3491
3492 # Only A and B will have their test jobs queued because
3493 # window is 2.
3494 self.assertEqual(len(self.builds), 4)
3495 self.assertEqual(self.builds[0].name, 'project-test1')
3496 self.assertEqual(self.builds[1].name, 'project-test2')
3497 self.assertEqual(self.builds[2].name, 'project-test1')
3498 self.assertEqual(self.builds[3].name, 'project-test2')
3499
James E. Blair08d19992016-08-10 15:25:31 -07003500 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003501 self.waitUntilSettled()
3502
3503 queue = self.sched.layout.pipelines['gate'].queues[0]
3504 # A failed so window is reduced by 1 to 1.
3505 self.assertEqual(queue.window, 1)
3506 self.assertEqual(queue.window_floor, 1)
3507 self.assertEqual(A.data['status'], 'NEW')
3508 self.assertEqual(B.data['status'], 'NEW')
3509
3510 # Gate is reset and only C's merge job is queued because
3511 # window shrunk to 1 and A and B were dequeued.
3512 self.assertEqual(len(self.builds), 1)
3513 self.assertEqual(self.builds[0].name, 'project-merge')
3514
James E. Blair08d19992016-08-10 15:25:31 -07003515 self.launch_server.release('.*-merge')
Clark Boylan7603a372014-01-21 11:43:20 -08003516 self.waitUntilSettled()
3517
3518 # Only C's test jobs are queued because window is still 1.
3519 self.assertEqual(len(self.builds), 2)
3520 self.assertEqual(self.builds[0].name, 'project-test1')
3521 self.assertEqual(self.builds[1].name, 'project-test2')
3522
James E. Blair08d19992016-08-10 15:25:31 -07003523 self.launch_server.release('project-.*')
Clark Boylan7603a372014-01-21 11:43:20 -08003524 self.waitUntilSettled()
3525
3526 # C was successfully merged so window is increased to 2.
3527 self.assertEqual(queue.window, 2)
3528 self.assertEqual(queue.window_floor, 1)
3529 self.assertEqual(C.data['status'], 'MERGED')
Joshua Heskethba8776a2014-01-12 14:35:40 +08003530
James E. Blairec056492016-07-22 09:45:56 -07003531 @skip("Disabled for early v3 development")
Joshua Heskethba8776a2014-01-12 14:35:40 +08003532 def test_worker_update_metadata(self):
3533 "Test if a worker can send back metadata about itself"
James E. Blair08d19992016-08-10 15:25:31 -07003534 self.launch_server.hold_jobs_in_build = True
Joshua Heskethba8776a2014-01-12 14:35:40 +08003535
3536 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003537 A.addApproval('code-review', 2)
3538 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethba8776a2014-01-12 14:35:40 +08003539 self.waitUntilSettled()
3540
3541 self.assertEqual(len(self.launcher.builds), 1)
3542
3543 self.log.debug('Current builds:')
3544 self.log.debug(self.launcher.builds)
3545
3546 start = time.time()
3547 while True:
3548 if time.time() - start > 10:
3549 raise Exception("Timeout waiting for gearman server to report "
3550 + "back to the client")
3551 build = self.launcher.builds.values()[0]
3552 if build.worker.name == "My Worker":
3553 break
3554 else:
3555 time.sleep(0)
3556
3557 self.log.debug(build)
3558 self.assertEqual("My Worker", build.worker.name)
3559 self.assertEqual("localhost", build.worker.hostname)
3560 self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips)
3561 self.assertEqual("zuul.example.org", build.worker.fqdn)
3562 self.assertEqual("FakeBuilder", build.worker.program)
3563 self.assertEqual("v1.1", build.worker.version)
3564 self.assertEqual({'something': 'else'}, build.worker.extra)
3565
James E. Blair08d19992016-08-10 15:25:31 -07003566 self.launch_server.hold_jobs_in_build = False
3567 self.launch_server.release()
Joshua Heskethba8776a2014-01-12 14:35:40 +08003568 self.waitUntilSettled()
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003569
James E. Blairec056492016-07-22 09:45:56 -07003570 @skip("Disabled for early v3 development")
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003571 def test_footer_message(self):
3572 "Test a pipeline's footer message is correctly added to the report."
James E. Blairf84026c2015-12-08 16:11:46 -08003573 self.updateConfigLayout(
3574 'tests/fixtures/layout-footer-message.yaml')
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003575 self.sched.reconfigure(self.config)
3576 self.registerJobs()
3577
3578 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003579 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003580 self.launch_server.failJob('test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003581 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003582 self.waitUntilSettled()
3583
3584 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003585 B.addApproval('code-review', 2)
3586 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Joshua Hesketh3979e3e2014-03-04 11:21:10 +11003587 self.waitUntilSettled()
3588
3589 self.assertEqual(2, len(self.smtp_messages))
3590
3591 failure_body = """\
3592Build failed. For information on how to proceed, see \
3593http://wiki.example.org/Test_Failures
3594
3595- test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s
3596- test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s
3597
3598For CI problems and help debugging, contact ci@example.org"""
3599
3600 success_body = """\
3601Build succeeded.
3602
3603- test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s
3604- test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s
3605
3606For CI problems and help debugging, contact ci@example.org"""
3607
3608 self.assertEqual(failure_body, self.smtp_messages[0]['body'])
3609 self.assertEqual(success_body, self.smtp_messages[1]['body'])
Joshua Heskethb7179772014-01-30 23:30:46 +11003610
James E. Blairec056492016-07-22 09:45:56 -07003611 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003612 def test_merge_failure_reporters(self):
3613 """Check that the config is set up correctly"""
3614
James E. Blairf84026c2015-12-08 16:11:46 -08003615 self.updateConfigLayout(
3616 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003617 self.sched.reconfigure(self.config)
3618 self.registerJobs()
3619
3620 self.assertEqual(
Jeremy Stanley1c2c3c22015-06-15 21:23:19 +00003621 "Merge Failed.\n\nThis change or one of its cross-repo "
3622 "dependencies was unable to be automatically merged with the "
3623 "current state of its repository. Please rebase the change and "
3624 "upload a new patchset.",
Joshua Heskethb7179772014-01-30 23:30:46 +11003625 self.sched.layout.pipelines['check'].merge_failure_message)
3626 self.assertEqual(
3627 "The merge failed! For more information...",
3628 self.sched.layout.pipelines['gate'].merge_failure_message)
3629
3630 self.assertEqual(
3631 len(self.sched.layout.pipelines['check'].merge_failure_actions), 1)
3632 self.assertEqual(
3633 len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2)
3634
3635 self.assertTrue(isinstance(
Joshua Heskethde958652015-11-10 19:19:50 +11003636 self.sched.layout.pipelines['check'].merge_failure_actions[0],
3637 zuul.reporter.gerrit.GerritReporter))
Joshua Heskethb7179772014-01-30 23:30:46 +11003638
3639 self.assertTrue(
3640 (
3641 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003642 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003643 zuul.reporter.smtp.SMTPReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003644 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003645 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003646 zuul.reporter.gerrit.GerritReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003647 ) or (
3648 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003649 merge_failure_actions[0],
Joshua Heskethffe42062014-09-05 21:43:52 +10003650 zuul.reporter.gerrit.GerritReporter) and
Joshua Heskethb7179772014-01-30 23:30:46 +11003651 isinstance(self.sched.layout.pipelines['gate'].
Joshua Heskethde958652015-11-10 19:19:50 +11003652 merge_failure_actions[1],
Joshua Heskethffe42062014-09-05 21:43:52 +10003653 zuul.reporter.smtp.SMTPReporter)
Joshua Heskethb7179772014-01-30 23:30:46 +11003654 )
3655 )
3656
James E. Blairec056492016-07-22 09:45:56 -07003657 @skip("Disabled for early v3 development")
Joshua Heskethb7179772014-01-30 23:30:46 +11003658 def test_merge_failure_reports(self):
3659 """Check that when a change fails to merge the correct message is sent
3660 to the correct reporter"""
James E. Blairf84026c2015-12-08 16:11:46 -08003661 self.updateConfigLayout(
3662 'tests/fixtures/layout-merge-failure.yaml')
Joshua Heskethb7179772014-01-30 23:30:46 +11003663 self.sched.reconfigure(self.config)
3664 self.registerJobs()
3665
3666 # Check a test failure isn't reported to SMTP
3667 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003668 A.addApproval('code-review', 2)
James E. Blair08d19992016-08-10 15:25:31 -07003669 self.launch_server.failJob('project-test1', A)
James E. Blair8b5408c2016-08-08 15:37:46 -07003670 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003671 self.waitUntilSettled()
3672
3673 self.assertEqual(3, len(self.history)) # 3 jobs
3674 self.assertEqual(0, len(self.smtp_messages))
3675
3676 # Check a merge failure is reported to SMTP
3677 # B should be merged, but C will conflict with B
3678 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3679 B.addPatchset(['conflict'])
3680 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
3681 C.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003682 B.addApproval('code-review', 2)
3683 C.addApproval('code-review', 2)
3684 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
3685 self.fake_gerrit.addEvent(C.addApproval('approved', 1))
Joshua Heskethb7179772014-01-30 23:30:46 +11003686 self.waitUntilSettled()
3687
3688 self.assertEqual(6, len(self.history)) # A and B jobs
3689 self.assertEqual(1, len(self.smtp_messages))
3690 self.assertEqual('The merge failed! For more information...',
3691 self.smtp_messages[0]['body'])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003692
James E. Blairec056492016-07-22 09:45:56 -07003693 @skip("Disabled for early v3 development")
James E. Blairf760f0e2016-02-09 08:44:52 -08003694 def test_default_merge_failure_reports(self):
3695 """Check that the default merge failure reports are correct."""
3696
3697 # A should report success, B should report merge failure.
3698 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3699 A.addPatchset(['conflict'])
3700 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
3701 B.addPatchset(['conflict'])
James E. Blair8b5408c2016-08-08 15:37:46 -07003702 A.addApproval('code-review', 2)
3703 B.addApproval('code-review', 2)
3704 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
3705 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blairf760f0e2016-02-09 08:44:52 -08003706 self.waitUntilSettled()
3707
3708 self.assertEqual(3, len(self.history)) # A jobs
3709 self.assertEqual(A.reported, 2)
3710 self.assertEqual(B.reported, 2)
3711 self.assertEqual(A.data['status'], 'MERGED')
3712 self.assertEqual(B.data['status'], 'NEW')
3713 self.assertIn('Build succeeded', A.messages[1])
3714 self.assertIn('Merge Failed', B.messages[1])
3715 self.assertIn('automatically merged', B.messages[1])
3716 self.assertNotIn('logs.example.com', B.messages[1])
3717 self.assertNotIn('SKIPPED', B.messages[1])
3718
James E. Blairec056492016-07-22 09:45:56 -07003719 @skip("Disabled for early v3 development")
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003720 def test_swift_instructions(self):
3721 "Test that the correct swift instructions are sent to the workers"
James E. Blairf84026c2015-12-08 16:11:46 -08003722 self.updateConfigLayout(
3723 'tests/fixtures/layout-swift.yaml')
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003724 self.sched.reconfigure(self.config)
3725 self.registerJobs()
3726
James E. Blair08d19992016-08-10 15:25:31 -07003727 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003728 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
3729
James E. Blair8b5408c2016-08-08 15:37:46 -07003730 A.addApproval('code-review', 2)
3731 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003732 self.waitUntilSettled()
3733
3734 self.assertEqual(
3735 "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/"
3736 "gate/test-merge/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003737 self.builds[0].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003738 self.assertEqual(5,
3739 len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY'].
3740 split('\n')))
3741 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters)
3742
3743 self.assertEqual(
3744 "https://storage.example.org/V1/AUTH_account/logs/1/1/1/"
3745 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003746 self.builds[1].parameters['SWIFT_logs_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003747 self.assertEqual(5,
3748 len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY'].
3749 split('\n')))
3750 self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters)
3751
3752 self.assertEqual(
3753 "https://storage.example.org/V1/AUTH_account/stash/1/1/1/"
3754 "gate/test-test/",
Joshua Hesketh76dee532014-07-03 15:39:13 +10003755 self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7])
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003756 self.assertEqual(5,
3757 len(self.builds[1].
3758 parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n')))
3759 self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters)
3760
James E. Blair08d19992016-08-10 15:25:31 -07003761 self.launch_server.hold_jobs_in_build = False
3762 self.launch_server.release()
Joshua Hesketh36c3fa52014-01-22 11:40:52 +11003763 self.waitUntilSettled()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003764
James E. Blairec056492016-07-22 09:45:56 -07003765 @skip("Disabled for early v3 development")
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003766 def test_client_get_running_jobs(self):
3767 "Test that the RPC client can get a list of running jobs"
James E. Blair08d19992016-08-10 15:25:31 -07003768 self.launch_server.hold_jobs_in_build = True
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003769 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
James E. Blair8b5408c2016-08-08 15:37:46 -07003770 A.addApproval('code-review', 2)
3771 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003772 self.waitUntilSettled()
3773
3774 client = zuul.rpcclient.RPCClient('127.0.0.1',
3775 self.gearman_server.port)
3776
3777 # Wait for gearman server to send the initial workData back to zuul
3778 start = time.time()
3779 while True:
3780 if time.time() - start > 10:
3781 raise Exception("Timeout waiting for gearman server to report "
3782 + "back to the client")
3783 build = self.launcher.builds.values()[0]
3784 if build.worker.name == "My Worker":
3785 break
3786 else:
3787 time.sleep(0)
3788
3789 running_items = client.get_running_jobs()
3790
3791 self.assertEqual(1, len(running_items))
3792 running_item = running_items[0]
3793 self.assertEqual([], running_item['failing_reasons'])
3794 self.assertEqual([], running_item['items_behind'])
3795 self.assertEqual('https://hostname/1', running_item['url'])
3796 self.assertEqual(None, running_item['item_ahead'])
3797 self.assertEqual('org/project', running_item['project'])
3798 self.assertEqual(None, running_item['remaining_time'])
3799 self.assertEqual(True, running_item['active'])
3800 self.assertEqual('1,1', running_item['id'])
3801
3802 self.assertEqual(3, len(running_item['jobs']))
3803 for job in running_item['jobs']:
3804 if job['name'] == 'project-merge':
3805 self.assertEqual('project-merge', job['name'])
3806 self.assertEqual('gate', job['pipeline'])
3807 self.assertEqual(False, job['retry'])
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003808 self.assertEqual('https://server/job/project-merge/0/',
3809 job['url'])
3810 self.assertEqual(7, len(job['worker']))
3811 self.assertEqual(False, job['canceled'])
3812 self.assertEqual(True, job['voting'])
3813 self.assertEqual(None, job['result'])
3814 self.assertEqual('gate', job['pipeline'])
3815 break
3816
James E. Blair08d19992016-08-10 15:25:31 -07003817 self.launch_server.hold_jobs_in_build = False
3818 self.launch_server.release()
Joshua Hesketh85af4e92014-02-21 08:28:58 -08003819 self.waitUntilSettled()
3820
3821 running_items = client.get_running_jobs()
3822 self.assertEqual(0, len(running_items))
James E. Blairbadc1ad2014-04-28 13:55:14 -07003823
James E. Blairec056492016-07-22 09:45:56 -07003824 @skip("Disabled for early v3 development")
James E. Blairbadc1ad2014-04-28 13:55:14 -07003825 def test_nonvoting_pipeline(self):
3826 "Test that a nonvoting pipeline (experimental) can still report"
3827
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003828 A = self.fake_gerrit.addFakeChange('org/experimental-project',
3829 'master', 'A')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003830 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
3831 self.waitUntilSettled()
Joshua Heskethcc017ea2014-04-30 19:55:25 +10003832 self.assertEqual(
3833 self.getJobFromHistory('experimental-project-test').result,
3834 'SUCCESS')
James E. Blairbadc1ad2014-04-28 13:55:14 -07003835 self.assertEqual(A.reported, 1)
James E. Blair5ee24252014-12-30 10:12:29 -08003836
James E. Blairec056492016-07-22 09:45:56 -07003837 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003838 def test_crd_gate(self):
3839 "Test cross-repo dependencies"
3840 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3841 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003842 A.addApproval('code-review', 2)
3843 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003844
3845 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
3846 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
3847 AM2.setMerged()
3848 AM1.setMerged()
3849
3850 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
3851 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
3852 BM2.setMerged()
3853 BM1.setMerged()
3854
3855 # A -> AM1 -> AM2
3856 # B -> BM1 -> BM2
3857 # A Depends-On: B
3858 # M2 is here to make sure it is never queried. If it is, it
3859 # means zuul is walking down the entire history of merged
3860 # changes.
3861
3862 B.setDependsOn(BM1, 1)
3863 BM1.setDependsOn(BM2, 1)
3864
3865 A.setDependsOn(AM1, 1)
3866 AM1.setDependsOn(AM2, 1)
3867
3868 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3869 A.subject, B.data['id'])
3870
James E. Blair8b5408c2016-08-08 15:37:46 -07003871 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003872 self.waitUntilSettled()
3873
3874 self.assertEqual(A.data['status'], 'NEW')
3875 self.assertEqual(B.data['status'], 'NEW')
3876
Joshua Hesketh4bd7da32016-02-17 20:58:47 +11003877 for connection in self.connections.values():
3878 connection.maintainCache([])
James E. Blair5ee24252014-12-30 10:12:29 -08003879
James E. Blair08d19992016-08-10 15:25:31 -07003880 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003881 B.addApproval('approved', 1)
3882 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08003883 self.waitUntilSettled()
3884
James E. Blair08d19992016-08-10 15:25:31 -07003885 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003886 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003887 self.launch_server.release('.*-merge')
James E. Blair5ee24252014-12-30 10:12:29 -08003888 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003889 self.launch_server.hold_jobs_in_build = False
3890 self.launch_server.release()
James E. Blair5ee24252014-12-30 10:12:29 -08003891 self.waitUntilSettled()
3892
3893 self.assertEqual(AM2.queried, 0)
3894 self.assertEqual(BM2.queried, 0)
3895 self.assertEqual(A.data['status'], 'MERGED')
3896 self.assertEqual(B.data['status'], 'MERGED')
3897 self.assertEqual(A.reported, 2)
3898 self.assertEqual(B.reported, 2)
3899
James E. Blair8f78d882015-02-05 08:51:37 -08003900 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3901 '2,1 1,1')
3902
James E. Blairec056492016-07-22 09:45:56 -07003903 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003904 def test_crd_branch(self):
3905 "Test cross-repo dependencies in multiple branches"
3906 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3907 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3908 C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C')
3909 C.data['id'] = B.data['id']
James E. Blair8b5408c2016-08-08 15:37:46 -07003910 A.addApproval('code-review', 2)
3911 B.addApproval('code-review', 2)
3912 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003913
3914 # A Depends-On: B+C
3915 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3916 A.subject, B.data['id'])
3917
James E. Blair08d19992016-08-10 15:25:31 -07003918 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003919 B.addApproval('approved', 1)
3920 C.addApproval('approved', 1)
3921 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003922 self.waitUntilSettled()
3923
James E. Blair08d19992016-08-10 15:25:31 -07003924 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003925 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003926 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003927 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003928 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003929 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003930 self.launch_server.hold_jobs_in_build = False
3931 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003932 self.waitUntilSettled()
3933
3934 self.assertEqual(A.data['status'], 'MERGED')
3935 self.assertEqual(B.data['status'], 'MERGED')
3936 self.assertEqual(C.data['status'], 'MERGED')
3937 self.assertEqual(A.reported, 2)
3938 self.assertEqual(B.reported, 2)
3939 self.assertEqual(C.reported, 2)
3940
3941 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3942 '2,1 3,1 1,1')
3943
James E. Blairec056492016-07-22 09:45:56 -07003944 @skip("Disabled for early v3 development")
James E. Blair8f78d882015-02-05 08:51:37 -08003945 def test_crd_multiline(self):
3946 "Test multiple depends-on lines in commit"
3947 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3948 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
3949 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
James E. Blair8b5408c2016-08-08 15:37:46 -07003950 A.addApproval('code-review', 2)
3951 B.addApproval('code-review', 2)
3952 C.addApproval('code-review', 2)
James E. Blair8f78d882015-02-05 08:51:37 -08003953
3954 # A Depends-On: B+C
3955 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
3956 A.subject, B.data['id'], C.data['id'])
3957
James E. Blair08d19992016-08-10 15:25:31 -07003958 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07003959 B.addApproval('approved', 1)
3960 C.addApproval('approved', 1)
3961 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair8f78d882015-02-05 08:51:37 -08003962 self.waitUntilSettled()
3963
James E. Blair08d19992016-08-10 15:25:31 -07003964 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003965 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003966 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003967 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003968 self.launch_server.release('.*-merge')
James E. Blair8f78d882015-02-05 08:51:37 -08003969 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07003970 self.launch_server.hold_jobs_in_build = False
3971 self.launch_server.release()
James E. Blair8f78d882015-02-05 08:51:37 -08003972 self.waitUntilSettled()
3973
3974 self.assertEqual(A.data['status'], 'MERGED')
3975 self.assertEqual(B.data['status'], 'MERGED')
3976 self.assertEqual(C.data['status'], 'MERGED')
3977 self.assertEqual(A.reported, 2)
3978 self.assertEqual(B.reported, 2)
3979 self.assertEqual(C.reported, 2)
3980
3981 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
3982 '2,1 3,1 1,1')
James E. Blair5ee24252014-12-30 10:12:29 -08003983
James E. Blairec056492016-07-22 09:45:56 -07003984 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08003985 def test_crd_unshared_gate(self):
3986 "Test cross-repo dependencies in unshared gate queues"
3987 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
3988 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07003989 A.addApproval('code-review', 2)
3990 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08003991
3992 # A Depends-On: B
3993 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
3994 A.subject, B.data['id'])
3995
3996 # A and B do not share a queue, make sure that A is unable to
3997 # enqueue B (and therefore, A is unable to be enqueued).
James E. Blair8b5408c2016-08-08 15:37:46 -07003998 B.addApproval('approved', 1)
3999 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004000 self.waitUntilSettled()
4001
4002 self.assertEqual(A.data['status'], 'NEW')
4003 self.assertEqual(B.data['status'], 'NEW')
4004 self.assertEqual(A.reported, 0)
4005 self.assertEqual(B.reported, 0)
4006 self.assertEqual(len(self.history), 0)
4007
4008 # Enqueue and merge B alone.
James E. Blair8b5408c2016-08-08 15:37:46 -07004009 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004010 self.waitUntilSettled()
4011
4012 self.assertEqual(B.data['status'], 'MERGED')
4013 self.assertEqual(B.reported, 2)
4014
4015 # Now that B is merged, A should be able to be enqueued and
4016 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004017 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004018 self.waitUntilSettled()
4019
4020 self.assertEqual(A.data['status'], 'MERGED')
4021 self.assertEqual(A.reported, 2)
4022
James E. Blairec056492016-07-22 09:45:56 -07004023 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004024 def test_crd_gate_reverse(self):
4025 "Test reverse cross-repo dependencies"
4026 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4027 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004028 A.addApproval('code-review', 2)
4029 B.addApproval('code-review', 2)
James E. Blair96698e22015-04-02 07:48:21 -07004030
4031 # A Depends-On: B
4032
4033 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4034 A.subject, B.data['id'])
4035
James E. Blair8b5408c2016-08-08 15:37:46 -07004036 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004037 self.waitUntilSettled()
4038
4039 self.assertEqual(A.data['status'], 'NEW')
4040 self.assertEqual(B.data['status'], 'NEW')
4041
James E. Blair08d19992016-08-10 15:25:31 -07004042 self.launch_server.hold_jobs_in_build = True
James E. Blair8b5408c2016-08-08 15:37:46 -07004043 A.addApproval('approved', 1)
4044 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
James E. Blair96698e22015-04-02 07:48:21 -07004045 self.waitUntilSettled()
4046
James E. Blair08d19992016-08-10 15:25:31 -07004047 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004048 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004049 self.launch_server.release('.*-merge')
James E. Blair96698e22015-04-02 07:48:21 -07004050 self.waitUntilSettled()
James E. Blair08d19992016-08-10 15:25:31 -07004051 self.launch_server.hold_jobs_in_build = False
4052 self.launch_server.release()
James E. Blair96698e22015-04-02 07:48:21 -07004053 self.waitUntilSettled()
4054
4055 self.assertEqual(A.data['status'], 'MERGED')
4056 self.assertEqual(B.data['status'], 'MERGED')
4057 self.assertEqual(A.reported, 2)
4058 self.assertEqual(B.reported, 2)
4059
4060 self.assertEqual(self.getJobFromHistory('project1-merge').changes,
4061 '2,1 1,1')
4062
James E. Blairec056492016-07-22 09:45:56 -07004063 @skip("Disabled for early v3 development")
James E. Blair5ee24252014-12-30 10:12:29 -08004064 def test_crd_cycle(self):
4065 "Test cross-repo dependency cycles"
4066 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4067 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004068 A.addApproval('code-review', 2)
4069 B.addApproval('code-review', 2)
James E. Blair5ee24252014-12-30 10:12:29 -08004070
4071 # A -> B -> A (via commit-depends)
4072
4073 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4074 A.subject, B.data['id'])
4075 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4076 B.subject, A.data['id'])
4077
James E. Blair8b5408c2016-08-08 15:37:46 -07004078 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
James E. Blair5ee24252014-12-30 10:12:29 -08004079 self.waitUntilSettled()
4080
4081 self.assertEqual(A.reported, 0)
4082 self.assertEqual(B.reported, 0)
4083 self.assertEqual(A.data['status'], 'NEW')
4084 self.assertEqual(B.data['status'], 'NEW')
James E. Blairbfb8e042014-12-30 17:01:44 -08004085
James E. Blairec056492016-07-22 09:45:56 -07004086 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004087 def test_crd_gate_unknown(self):
4088 "Test unknown projects in dependent pipeline"
4089 self.init_repo("org/unknown")
4090 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4091 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
James E. Blair8b5408c2016-08-08 15:37:46 -07004092 A.addApproval('code-review', 2)
4093 B.addApproval('code-review', 2)
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004094
4095 # A Depends-On: B
4096 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4097 A.subject, B.data['id'])
4098
James E. Blair8b5408c2016-08-08 15:37:46 -07004099 B.addApproval('approved', 1)
4100 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004101 self.waitUntilSettled()
4102
4103 # Unknown projects cannot share a queue with any other
4104 # since they don't have common jobs with any other (they have no jobs).
4105 # Changes which depend on unknown project changes
4106 # should not be processed in dependent pipeline
4107 self.assertEqual(A.data['status'], 'NEW')
4108 self.assertEqual(B.data['status'], 'NEW')
4109 self.assertEqual(A.reported, 0)
4110 self.assertEqual(B.reported, 0)
4111 self.assertEqual(len(self.history), 0)
4112
4113 # Simulate change B being gated outside this layout
James E. Blair8b5408c2016-08-08 15:37:46 -07004114 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004115 B.setMerged()
4116 self.waitUntilSettled()
4117 self.assertEqual(len(self.history), 0)
4118
4119 # Now that B is merged, A should be able to be enqueued and
4120 # merged.
James E. Blair8b5408c2016-08-08 15:37:46 -07004121 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004122 self.waitUntilSettled()
4123
4124 self.assertEqual(A.data['status'], 'MERGED')
4125 self.assertEqual(A.reported, 2)
4126 self.assertEqual(B.data['status'], 'MERGED')
4127 self.assertEqual(B.reported, 0)
4128
James E. Blairec056492016-07-22 09:45:56 -07004129 @skip("Disabled for early v3 development")
James E. Blairbfb8e042014-12-30 17:01:44 -08004130 def test_crd_check(self):
4131 "Test cross-repo dependencies in independent pipelines"
4132
4133 self.gearman_server.hold_jobs_in_queue = True
4134 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4135 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4136
4137 # A Depends-On: B
4138 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4139 A.subject, B.data['id'])
4140
4141 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4142 self.waitUntilSettled()
4143
4144 queue = self.gearman_server.getQueue()
4145 ref = self.getParameter(queue[-1], 'ZUUL_REF')
4146 self.gearman_server.hold_jobs_in_queue = False
4147 self.gearman_server.release()
4148 self.waitUntilSettled()
4149
4150 path = os.path.join(self.git_root, "org/project1")
4151 repo = git.Repo(path)
4152 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4153 repo_messages.reverse()
4154 correct_messages = ['initial commit', 'A-1']
4155 self.assertEqual(repo_messages, correct_messages)
4156
4157 path = os.path.join(self.git_root, "org/project2")
4158 repo = git.Repo(path)
4159 repo_messages = [c.message.strip() for c in repo.iter_commits(ref)]
4160 repo_messages.reverse()
4161 correct_messages = ['initial commit', 'B-1']
4162 self.assertEqual(repo_messages, correct_messages)
4163
4164 self.assertEqual(A.data['status'], 'NEW')
4165 self.assertEqual(B.data['status'], 'NEW')
4166 self.assertEqual(A.reported, 1)
4167 self.assertEqual(B.reported, 0)
4168
4169 self.assertEqual(self.history[0].changes, '2,1 1,1')
4170 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair8f78d882015-02-05 08:51:37 -08004171
James E. Blairec056492016-07-22 09:45:56 -07004172 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004173 def test_crd_check_git_depends(self):
4174 "Test single-repo dependencies in independent pipelines"
James E. Blairb8c16472015-05-05 14:55:26 -07004175 self.gearman_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004176 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4177 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4178
4179 # Add two git-dependent changes and make sure they both report
4180 # success.
4181 B.setDependsOn(A, 1)
4182 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4183 self.waitUntilSettled()
4184 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4185 self.waitUntilSettled()
4186
James E. Blairb8c16472015-05-05 14:55:26 -07004187 self.orderedRelease()
4188 self.gearman_server.hold_jobs_in_build = False
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004189 self.waitUntilSettled()
4190
4191 self.assertEqual(A.data['status'], 'NEW')
4192 self.assertEqual(B.data['status'], 'NEW')
4193 self.assertEqual(A.reported, 1)
4194 self.assertEqual(B.reported, 1)
4195
4196 self.assertEqual(self.history[0].changes, '1,1')
4197 self.assertEqual(self.history[-1].changes, '1,1 2,1')
4198 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4199
4200 self.assertIn('Build succeeded', A.messages[0])
4201 self.assertIn('Build succeeded', B.messages[0])
4202
James E. Blairec056492016-07-22 09:45:56 -07004203 @skip("Disabled for early v3 development")
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004204 def test_crd_check_duplicate(self):
4205 "Test duplicate check in independent pipelines"
James E. Blair08d19992016-08-10 15:25:31 -07004206 self.launch_server.hold_jobs_in_build = True
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004207 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4208 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4209 check_pipeline = self.sched.layout.pipelines['check']
4210
4211 # Add two git-dependent changes...
4212 B.setDependsOn(A, 1)
4213 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4214 self.waitUntilSettled()
4215 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4216
4217 # ...make sure the live one is not duplicated...
4218 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4219 self.waitUntilSettled()
4220 self.assertEqual(len(check_pipeline.getAllItems()), 2)
4221
4222 # ...but the non-live one is able to be.
4223 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4224 self.waitUntilSettled()
4225 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4226
Clark Boylandd849822015-03-02 12:38:14 -08004227 # Release jobs in order to avoid races with change A jobs
4228 # finishing before change B jobs.
James E. Blaird7650852015-05-07 15:47:37 -07004229 self.orderedRelease()
James E. Blair08d19992016-08-10 15:25:31 -07004230 self.launch_server.hold_jobs_in_build = False
4231 self.launch_server.release()
James E. Blairdbfe1cd2015-02-07 11:41:19 -08004232 self.waitUntilSettled()
4233
4234 self.assertEqual(A.data['status'], 'NEW')
4235 self.assertEqual(B.data['status'], 'NEW')
4236 self.assertEqual(A.reported, 1)
4237 self.assertEqual(B.reported, 1)
4238
4239 self.assertEqual(self.history[0].changes, '1,1 2,1')
4240 self.assertEqual(self.history[1].changes, '1,1')
4241 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
4242
4243 self.assertIn('Build succeeded', A.messages[0])
4244 self.assertIn('Build succeeded', B.messages[0])
4245
James E. Blairec056492016-07-22 09:45:56 -07004246 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004247 def _test_crd_check_reconfiguration(self, project1, project2):
James E. Blair8f78d882015-02-05 08:51:37 -08004248 "Test cross-repo dependencies re-enqueued in independent pipelines"
4249
4250 self.gearman_server.hold_jobs_in_queue = True
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004251 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
4252 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
James E. Blair8f78d882015-02-05 08:51:37 -08004253
4254 # A Depends-On: B
4255 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4256 A.subject, B.data['id'])
4257
4258 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4259 self.waitUntilSettled()
4260
4261 self.sched.reconfigure(self.config)
4262
4263 # Make sure the items still share a change queue, and the
4264 # first one is not live.
4265 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1)
4266 queue = self.sched.layout.pipelines['check'].queues[0]
4267 first_item = queue.queue[0]
4268 for item in queue.queue:
4269 self.assertEqual(item.queue, first_item.queue)
4270 self.assertFalse(first_item.live)
4271 self.assertTrue(queue.queue[1].live)
4272
4273 self.gearman_server.hold_jobs_in_queue = False
4274 self.gearman_server.release()
4275 self.waitUntilSettled()
4276
4277 self.assertEqual(A.data['status'], 'NEW')
4278 self.assertEqual(B.data['status'], 'NEW')
4279 self.assertEqual(A.reported, 1)
4280 self.assertEqual(B.reported, 0)
4281
4282 self.assertEqual(self.history[0].changes, '2,1 1,1')
4283 self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0)
James E. Blair17dd6772015-02-09 14:45:18 -08004284
James E. Blairec056492016-07-22 09:45:56 -07004285 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004286 def test_crd_check_reconfiguration(self):
4287 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
4288
James E. Blairec056492016-07-22 09:45:56 -07004289 @skip("Disabled for early v3 development")
Evgeny Antyshev0deaaad2015-08-03 20:22:56 +00004290 def test_crd_undefined_project(self):
4291 """Test that undefined projects in dependencies are handled for
4292 independent pipelines"""
4293 # It's a hack for fake gerrit,
4294 # as it implies repo creation upon the creation of any change
4295 self.init_repo("org/unknown")
4296 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
4297
James E. Blairec056492016-07-22 09:45:56 -07004298 @skip("Disabled for early v3 development")
James E. Blair17dd6772015-02-09 14:45:18 -08004299 def test_crd_check_ignore_dependencies(self):
4300 "Test cross-repo dependencies can be ignored"
James E. Blairf84026c2015-12-08 16:11:46 -08004301 self.updateConfigLayout(
4302 'tests/fixtures/layout-ignore-dependencies.yaml')
James E. Blair17dd6772015-02-09 14:45:18 -08004303 self.sched.reconfigure(self.config)
4304 self.registerJobs()
4305
4306 self.gearman_server.hold_jobs_in_queue = True
4307 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4308 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4309 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
4310
4311 # A Depends-On: B
4312 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4313 A.subject, B.data['id'])
4314 # C git-depends on B
4315 C.setDependsOn(B, 1)
4316 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4317 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4318 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4319 self.waitUntilSettled()
4320
4321 # Make sure none of the items share a change queue, and all
4322 # are live.
4323 check_pipeline = self.sched.layout.pipelines['check']
4324 self.assertEqual(len(check_pipeline.queues), 3)
4325 self.assertEqual(len(check_pipeline.getAllItems()), 3)
4326 for item in check_pipeline.getAllItems():
4327 self.assertTrue(item.live)
4328
4329 self.gearman_server.hold_jobs_in_queue = False
4330 self.gearman_server.release()
4331 self.waitUntilSettled()
4332
4333 self.assertEqual(A.data['status'], 'NEW')
4334 self.assertEqual(B.data['status'], 'NEW')
4335 self.assertEqual(C.data['status'], 'NEW')
4336 self.assertEqual(A.reported, 1)
4337 self.assertEqual(B.reported, 1)
4338 self.assertEqual(C.reported, 1)
4339
4340 # Each job should have tested exactly one change
4341 for job in self.history:
4342 self.assertEqual(len(job.changes.split()), 1)
James E. Blair96698e22015-04-02 07:48:21 -07004343
James E. Blairec056492016-07-22 09:45:56 -07004344 @skip("Disabled for early v3 development")
James E. Blair96698e22015-04-02 07:48:21 -07004345 def test_crd_check_transitive(self):
4346 "Test transitive cross-repo dependencies"
4347 # Specifically, if A -> B -> C, and C gets a new patchset and
4348 # A gets a new patchset, ensure the test of A,2 includes B,1
4349 # and C,2 (not C,1 which would indicate stale data in the
4350 # cache for B).
4351 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
4352 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4353 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
4354
4355 # A Depends-On: B
4356 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4357 A.subject, B.data['id'])
4358
4359 # B Depends-On: C
4360 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4361 B.subject, C.data['id'])
4362
4363 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4364 self.waitUntilSettled()
4365 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
4366
4367 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4368 self.waitUntilSettled()
4369 self.assertEqual(self.history[-1].changes, '3,1 2,1')
4370
4371 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4372 self.waitUntilSettled()
4373 self.assertEqual(self.history[-1].changes, '3,1')
4374
4375 C.addPatchset()
4376 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
4377 self.waitUntilSettled()
4378 self.assertEqual(self.history[-1].changes, '3,2')
4379
4380 A.addPatchset()
4381 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
4382 self.waitUntilSettled()
4383 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004384
James E. Blairec056492016-07-22 09:45:56 -07004385 @skip("Disabled for early v3 development")
James E. Blair92464a22016-04-05 10:21:26 -07004386 def test_crd_cycle_join(self):
4387 "Test an updated change creates a cycle"
4388 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
4389
4390 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4391 self.waitUntilSettled()
4392
4393 # Create B->A
4394 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
4395 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4396 B.subject, A.data['id'])
4397 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4398 self.waitUntilSettled()
4399
4400 # Update A to add A->B (a cycle).
4401 A.addPatchset()
4402 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
4403 A.subject, B.data['id'])
4404 # Normally we would submit the patchset-created event for
4405 # processing here, however, we have no way of noting whether
4406 # the dependency cycle detection correctly raised an
4407 # exception, so instead, we reach into the source driver and
4408 # call the method that would ultimately be called by the event
4409 # processing.
4410
4411 source = self.sched.layout.pipelines['gate'].source
4412 with testtools.ExpectedException(
4413 Exception, "Dependency cycle detected"):
4414 source._getChange(u'1', u'2', True)
4415 self.log.debug("Got expected dependency cycle exception")
4416
4417 # Now if we update B to remove the depends-on, everything
4418 # should be okay. B; A->B
4419
4420 B.addPatchset()
4421 B.data['commitMessage'] = '%s\n' % (B.subject,)
4422 source._getChange(u'1', u'2', True)
4423 source._getChange(u'2', u'2', True)
4424
James E. Blairec056492016-07-22 09:45:56 -07004425 @skip("Disabled for early v3 development")
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004426 def test_disable_at(self):
4427 "Test a pipeline will only report to the disabled trigger when failing"
4428
James E. Blairf84026c2015-12-08 16:11:46 -08004429 self.updateConfigLayout(
4430 'tests/fixtures/layout-disable-at.yaml')
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004431 self.sched.reconfigure(self.config)
4432
4433 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4434 self.assertEqual(
4435 0, self.sched.layout.pipelines['check']._consecutive_failures)
4436 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4437
4438 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
4439 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
4440 C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C')
4441 D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D')
4442 E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E')
4443 F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F')
4444 G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G')
4445 H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H')
4446 I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I')
4447 J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J')
4448 K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K')
4449
James E. Blair08d19992016-08-10 15:25:31 -07004450 self.launch_server.failJob('project-test1', A)
4451 self.launch_server.failJob('project-test1', B)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004452 # Let C pass, resetting the counter
James E. Blair08d19992016-08-10 15:25:31 -07004453 self.launch_server.failJob('project-test1', D)
4454 self.launch_server.failJob('project-test1', E)
4455 self.launch_server.failJob('project-test1', F)
4456 self.launch_server.failJob('project-test1', G)
4457 self.launch_server.failJob('project-test1', H)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004458 # I also passes but should only report to the disabled reporters
James E. Blair08d19992016-08-10 15:25:31 -07004459 self.launch_server.failJob('project-test1', J)
4460 self.launch_server.failJob('project-test1', K)
Joshua Hesketh89e829d2015-02-10 16:29:45 +11004461
4462 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4463 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4464 self.waitUntilSettled()
4465
4466 self.assertEqual(
4467 2, self.sched.layout.pipelines['check']._consecutive_failures)
4468 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4469
4470 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
4471 self.waitUntilSettled()
4472
4473 self.assertEqual(
4474 0, self.sched.layout.pipelines['check']._consecutive_failures)
4475 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4476
4477 self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1))
4478 self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1))
4479 self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1))
4480 self.waitUntilSettled()
4481
4482 # We should be disabled now
4483 self.assertEqual(
4484 3, self.sched.layout.pipelines['check']._consecutive_failures)
4485 self.assertTrue(self.sched.layout.pipelines['check']._disabled)
4486
4487 # We need to wait between each of these patches to make sure the
4488 # smtp messages come back in an expected order
4489 self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1))
4490 self.waitUntilSettled()
4491 self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1))
4492 self.waitUntilSettled()
4493 self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1))
4494 self.waitUntilSettled()
4495
4496 # The first 6 (ABCDEF) jobs should have reported back to gerrt thus
4497 # leaving a message on each change
4498 self.assertEqual(1, len(A.messages))
4499 self.assertIn('Build failed.', A.messages[0])
4500 self.assertEqual(1, len(B.messages))
4501 self.assertIn('Build failed.', B.messages[0])
4502 self.assertEqual(1, len(C.messages))
4503 self.assertIn('Build succeeded.', C.messages[0])
4504 self.assertEqual(1, len(D.messages))
4505 self.assertIn('Build failed.', D.messages[0])
4506 self.assertEqual(1, len(E.messages))
4507 self.assertIn('Build failed.', E.messages[0])
4508 self.assertEqual(1, len(F.messages))
4509 self.assertIn('Build failed.', F.messages[0])
4510
4511 # The last 3 (GHI) would have only reported via smtp.
4512 self.assertEqual(3, len(self.smtp_messages))
4513 self.assertEqual(0, len(G.messages))
4514 self.assertIn('Build failed.', self.smtp_messages[0]['body'])
4515 self.assertIn('/7/1/check', self.smtp_messages[0]['body'])
4516 self.assertEqual(0, len(H.messages))
4517 self.assertIn('Build failed.', self.smtp_messages[1]['body'])
4518 self.assertIn('/8/1/check', self.smtp_messages[1]['body'])
4519 self.assertEqual(0, len(I.messages))
4520 self.assertIn('Build succeeded.', self.smtp_messages[2]['body'])
4521 self.assertIn('/9/1/check', self.smtp_messages[2]['body'])
4522
4523 # Now reload the configuration (simulate a HUP) to check the pipeline
4524 # comes out of disabled
4525 self.sched.reconfigure(self.config)
4526
4527 self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at)
4528 self.assertEqual(
4529 0, self.sched.layout.pipelines['check']._consecutive_failures)
4530 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4531
4532 self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1))
4533 self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1))
4534 self.waitUntilSettled()
4535
4536 self.assertEqual(
4537 2, self.sched.layout.pipelines['check']._consecutive_failures)
4538 self.assertFalse(self.sched.layout.pipelines['check']._disabled)
4539
4540 # J and K went back to gerrit
4541 self.assertEqual(1, len(J.messages))
4542 self.assertIn('Build failed.', J.messages[0])
4543 self.assertEqual(1, len(K.messages))
4544 self.assertIn('Build failed.', K.messages[0])
4545 # No more messages reported via smtp
4546 self.assertEqual(3, len(self.smtp_messages))
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004547
James E. Blairec056492016-07-22 09:45:56 -07004548 @skip("Disabled for early v3 development")
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004549 def test_success_pattern(self):
4550 "Ensure bad build params are ignored"
4551
4552 # Use SMTP reporter to grab the result message easier
4553 self.init_repo("org/docs")
4554 self.config.set('zuul', 'layout_config',
4555 'tests/fixtures/layout-success-pattern.yaml')
4556 self.sched.reconfigure(self.config)
James E. Blair08d19992016-08-10 15:25:31 -07004557 self.launch_server.hold_jobs_in_build = True
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004558 self.registerJobs()
4559
4560 A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A')
4561 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4562 self.waitUntilSettled()
4563
4564 # Grab build id
4565 self.assertEqual(len(self.builds), 1)
4566 uuid = self.builds[0].unique[:7]
4567
James E. Blair08d19992016-08-10 15:25:31 -07004568 self.launch_server.hold_jobs_in_build = False
4569 self.launch_server.release()
Joshua Heskethd6dbd682015-12-22 10:06:54 +11004570 self.waitUntilSettled()
4571
4572 self.assertEqual(len(self.smtp_messages), 1)
4573 body = self.smtp_messages[0]['body'].splitlines()
4574 self.assertEqual('Build succeeded.', body[0])
4575
4576 self.assertIn(
4577 '- docs-draft-test http://docs-draft.example.org/1/1/1/check/'
4578 'docs-draft-test/%s/publish-docs/' % uuid,
4579 body[2])
4580 self.assertIn(
4581 '- docs-draft-test2 https://server/job/docs-draft-test2/1/',
4582 body[3])