blob: 90c93ecaea554092eff4a3ddb61e1ebcd3a5b1b7 [file] [log] [blame]
James E. Blair351d47d2018-01-08 09:31:30 -08001#!/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
17from tests.base import (
18 ZuulTestCase,
19 simple_layout,
20)
21
22
23class TestGerritLegacyCRD(ZuulTestCase):
24 tenant_config_file = 'config/single-tenant/main.yaml'
25
26 def test_crd_gate(self):
27 "Test cross-repo dependencies"
28 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
29 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
30 A.addApproval('Code-Review', 2)
31 B.addApproval('Code-Review', 2)
32
33 AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2')
34 AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1')
35 AM2.setMerged()
36 AM1.setMerged()
37
38 BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2')
39 BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1')
40 BM2.setMerged()
41 BM1.setMerged()
42
43 # A -> AM1 -> AM2
44 # B -> BM1 -> BM2
45 # A Depends-On: B
46 # M2 is here to make sure it is never queried. If it is, it
47 # means zuul is walking down the entire history of merged
48 # changes.
49
50 B.setDependsOn(BM1, 1)
51 BM1.setDependsOn(BM2, 1)
52
53 A.setDependsOn(AM1, 1)
54 AM1.setDependsOn(AM2, 1)
55
56 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
57 A.subject, B.data['id'])
58
59 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
60 self.waitUntilSettled()
61
62 self.assertEqual(A.data['status'], 'NEW')
63 self.assertEqual(B.data['status'], 'NEW')
64
65 for connection in self.connections.connections.values():
66 connection.maintainCache([])
67
68 self.executor_server.hold_jobs_in_build = True
69 B.addApproval('Approved', 1)
70 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
71 self.waitUntilSettled()
72
73 self.executor_server.release('.*-merge')
74 self.waitUntilSettled()
75 self.executor_server.release('.*-merge')
76 self.waitUntilSettled()
77 self.executor_server.hold_jobs_in_build = False
78 self.executor_server.release()
79 self.waitUntilSettled()
80
81 self.assertEqual(AM2.queried, 0)
82 self.assertEqual(BM2.queried, 0)
83 self.assertEqual(A.data['status'], 'MERGED')
84 self.assertEqual(B.data['status'], 'MERGED')
85 self.assertEqual(A.reported, 2)
86 self.assertEqual(B.reported, 2)
87
88 changes = self.getJobFromHistory(
89 'project-merge', 'org/project1').changes
90 self.assertEqual(changes, '2,1 1,1')
91
92 def test_crd_branch(self):
93 "Test cross-repo dependencies in multiple branches"
94
95 self.create_branch('org/project2', 'mp')
96 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
97 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
98 C1 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C1')
99 C2 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C2',
100 status='ABANDONED')
101 C1.data['id'] = B.data['id']
102 C2.data['id'] = B.data['id']
103
104 A.addApproval('Code-Review', 2)
105 B.addApproval('Code-Review', 2)
106 C1.addApproval('Code-Review', 2)
107
108 # A Depends-On: B+C1
109 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
110 A.subject, B.data['id'])
111
112 self.executor_server.hold_jobs_in_build = True
113 B.addApproval('Approved', 1)
114 C1.addApproval('Approved', 1)
115 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
116 self.waitUntilSettled()
117
118 self.executor_server.release('.*-merge')
119 self.waitUntilSettled()
120 self.executor_server.release('.*-merge')
121 self.waitUntilSettled()
122 self.executor_server.release('.*-merge')
123 self.waitUntilSettled()
124 self.executor_server.hold_jobs_in_build = False
125 self.executor_server.release()
126 self.waitUntilSettled()
127
128 self.assertEqual(A.data['status'], 'MERGED')
129 self.assertEqual(B.data['status'], 'MERGED')
130 self.assertEqual(C1.data['status'], 'MERGED')
131 self.assertEqual(A.reported, 2)
132 self.assertEqual(B.reported, 2)
133 self.assertEqual(C1.reported, 2)
134
135 changes = self.getJobFromHistory(
136 'project-merge', 'org/project1').changes
137 self.assertEqual(changes, '2,1 3,1 1,1')
138
139 def test_crd_multiline(self):
140 "Test multiple depends-on lines in commit"
141 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
142 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
143 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
144 A.addApproval('Code-Review', 2)
145 B.addApproval('Code-Review', 2)
146 C.addApproval('Code-Review', 2)
147
148 # A Depends-On: B+C
149 A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % (
150 A.subject, B.data['id'], C.data['id'])
151
152 self.executor_server.hold_jobs_in_build = True
153 B.addApproval('Approved', 1)
154 C.addApproval('Approved', 1)
155 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
156 self.waitUntilSettled()
157
158 self.executor_server.release('.*-merge')
159 self.waitUntilSettled()
160 self.executor_server.release('.*-merge')
161 self.waitUntilSettled()
162 self.executor_server.release('.*-merge')
163 self.waitUntilSettled()
164 self.executor_server.hold_jobs_in_build = False
165 self.executor_server.release()
166 self.waitUntilSettled()
167
168 self.assertEqual(A.data['status'], 'MERGED')
169 self.assertEqual(B.data['status'], 'MERGED')
170 self.assertEqual(C.data['status'], 'MERGED')
171 self.assertEqual(A.reported, 2)
172 self.assertEqual(B.reported, 2)
173 self.assertEqual(C.reported, 2)
174
175 changes = self.getJobFromHistory(
176 'project-merge', 'org/project1').changes
177 self.assertEqual(changes, '2,1 3,1 1,1')
178
179 def test_crd_unshared_gate(self):
180 "Test cross-repo dependencies in unshared gate queues"
181 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
182 B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B')
183 A.addApproval('Code-Review', 2)
184 B.addApproval('Code-Review', 2)
185
186 # A Depends-On: B
187 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
188 A.subject, B.data['id'])
189
190 # A and B do not share a queue, make sure that A is unable to
191 # enqueue B (and therefore, A is unable to be enqueued).
192 B.addApproval('Approved', 1)
193 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
194 self.waitUntilSettled()
195
196 self.assertEqual(A.data['status'], 'NEW')
197 self.assertEqual(B.data['status'], 'NEW')
198 self.assertEqual(A.reported, 0)
199 self.assertEqual(B.reported, 0)
200 self.assertEqual(len(self.history), 0)
201
202 # Enqueue and merge B alone.
203 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
204 self.waitUntilSettled()
205
206 self.assertEqual(B.data['status'], 'MERGED')
207 self.assertEqual(B.reported, 2)
208
209 # Now that B is merged, A should be able to be enqueued and
210 # merged.
211 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
212 self.waitUntilSettled()
213
214 self.assertEqual(A.data['status'], 'MERGED')
215 self.assertEqual(A.reported, 2)
216
217 def test_crd_gate_reverse(self):
218 "Test reverse cross-repo dependencies"
219 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
220 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
221 A.addApproval('Code-Review', 2)
222 B.addApproval('Code-Review', 2)
223
224 # A Depends-On: B
225
226 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
227 A.subject, B.data['id'])
228
229 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
230 self.waitUntilSettled()
231
232 self.assertEqual(A.data['status'], 'NEW')
233 self.assertEqual(B.data['status'], 'NEW')
234
235 self.executor_server.hold_jobs_in_build = True
236 A.addApproval('Approved', 1)
237 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
238 self.waitUntilSettled()
239
240 self.executor_server.release('.*-merge')
241 self.waitUntilSettled()
242 self.executor_server.release('.*-merge')
243 self.waitUntilSettled()
244 self.executor_server.hold_jobs_in_build = False
245 self.executor_server.release()
246 self.waitUntilSettled()
247
248 self.assertEqual(A.data['status'], 'MERGED')
249 self.assertEqual(B.data['status'], 'MERGED')
250 self.assertEqual(A.reported, 2)
251 self.assertEqual(B.reported, 2)
252
253 changes = self.getJobFromHistory(
254 'project-merge', 'org/project1').changes
255 self.assertEqual(changes, '2,1 1,1')
256
257 def test_crd_cycle(self):
258 "Test cross-repo dependency cycles"
259 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
260 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
261 A.addApproval('Code-Review', 2)
262 B.addApproval('Code-Review', 2)
James E. Blaira86134f2018-01-16 13:32:14 -0800263 B.addApproval('Approved', 1)
James E. Blair351d47d2018-01-08 09:31:30 -0800264
265 # A -> B -> A (via commit-depends)
266
267 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
268 A.subject, B.data['id'])
269 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
270 B.subject, A.data['id'])
271
272 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
273 self.waitUntilSettled()
274
275 self.assertEqual(A.reported, 0)
276 self.assertEqual(B.reported, 0)
277 self.assertEqual(A.data['status'], 'NEW')
278 self.assertEqual(B.data['status'], 'NEW')
279
280 def test_crd_gate_unknown(self):
281 "Test unknown projects in dependent pipeline"
282 self.init_repo("org/unknown", tag='init')
283 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
284 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B')
285 A.addApproval('Code-Review', 2)
286 B.addApproval('Code-Review', 2)
287
288 # A Depends-On: B
289 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
290 A.subject, B.data['id'])
291
292 B.addApproval('Approved', 1)
293 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
294 self.waitUntilSettled()
295
296 # Unknown projects cannot share a queue with any other
297 # since they don't have common jobs with any other (they have no jobs).
298 # Changes which depend on unknown project changes
299 # should not be processed in dependent pipeline
300 self.assertEqual(A.data['status'], 'NEW')
301 self.assertEqual(B.data['status'], 'NEW')
302 self.assertEqual(A.reported, 0)
303 self.assertEqual(B.reported, 0)
304 self.assertEqual(len(self.history), 0)
305
306 # Simulate change B being gated outside this layout Set the
307 # change merged before submitting the event so that when the
308 # event triggers a gerrit query to update the change, we get
309 # the information that it was merged.
310 B.setMerged()
311 self.fake_gerrit.addEvent(B.addApproval('Approved', 1))
312 self.waitUntilSettled()
313 self.assertEqual(len(self.history), 0)
314
315 # Now that B is merged, A should be able to be enqueued and
316 # merged.
317 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
318 self.waitUntilSettled()
319
320 self.assertEqual(A.data['status'], 'MERGED')
321 self.assertEqual(A.reported, 2)
322 self.assertEqual(B.data['status'], 'MERGED')
323 self.assertEqual(B.reported, 0)
324
325 def test_crd_check(self):
326 "Test cross-repo dependencies in independent pipelines"
327
328 self.executor_server.hold_jobs_in_build = True
329 self.gearman_server.hold_jobs_in_queue = True
330 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
331 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
332
333 # A Depends-On: B
334 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
335 A.subject, B.data['id'])
336
337 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
338 self.waitUntilSettled()
339
340 self.gearman_server.hold_jobs_in_queue = False
341 self.gearman_server.release()
342 self.waitUntilSettled()
343
344 self.executor_server.release('.*-merge')
345 self.waitUntilSettled()
346
347 self.assertTrue(self.builds[0].hasChanges(A, B))
348
349 self.executor_server.hold_jobs_in_build = False
350 self.executor_server.release()
351 self.waitUntilSettled()
352
353 self.assertEqual(A.data['status'], 'NEW')
354 self.assertEqual(B.data['status'], 'NEW')
355 self.assertEqual(A.reported, 1)
356 self.assertEqual(B.reported, 0)
357
358 self.assertEqual(self.history[0].changes, '2,1 1,1')
359 tenant = self.sched.abide.tenants.get('tenant-one')
360 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
361
362 def test_crd_check_git_depends(self):
363 "Test single-repo dependencies in independent pipelines"
364 self.gearman_server.hold_jobs_in_build = True
365 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
366 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
367
368 # Add two git-dependent changes and make sure they both report
369 # success.
370 B.setDependsOn(A, 1)
371 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
372 self.waitUntilSettled()
373 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
374 self.waitUntilSettled()
375
376 self.orderedRelease()
377 self.gearman_server.hold_jobs_in_build = False
378 self.waitUntilSettled()
379
380 self.assertEqual(A.data['status'], 'NEW')
381 self.assertEqual(B.data['status'], 'NEW')
382 self.assertEqual(A.reported, 1)
383 self.assertEqual(B.reported, 1)
384
385 self.assertEqual(self.history[0].changes, '1,1')
386 self.assertEqual(self.history[-1].changes, '1,1 2,1')
387 tenant = self.sched.abide.tenants.get('tenant-one')
388 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
389
390 self.assertIn('Build succeeded', A.messages[0])
391 self.assertIn('Build succeeded', B.messages[0])
392
393 def test_crd_check_duplicate(self):
394 "Test duplicate check in independent pipelines"
395 self.executor_server.hold_jobs_in_build = True
396 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
397 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
398 tenant = self.sched.abide.tenants.get('tenant-one')
399 check_pipeline = tenant.layout.pipelines['check']
400
401 # Add two git-dependent changes...
402 B.setDependsOn(A, 1)
403 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
404 self.waitUntilSettled()
405 self.assertEqual(len(check_pipeline.getAllItems()), 2)
406
407 # ...make sure the live one is not duplicated...
408 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
409 self.waitUntilSettled()
410 self.assertEqual(len(check_pipeline.getAllItems()), 2)
411
412 # ...but the non-live one is able to be.
413 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
414 self.waitUntilSettled()
415 self.assertEqual(len(check_pipeline.getAllItems()), 3)
416
417 # Release jobs in order to avoid races with change A jobs
418 # finishing before change B jobs.
419 self.orderedRelease()
420 self.executor_server.hold_jobs_in_build = False
421 self.executor_server.release()
422 self.waitUntilSettled()
423
424 self.assertEqual(A.data['status'], 'NEW')
425 self.assertEqual(B.data['status'], 'NEW')
426 self.assertEqual(A.reported, 1)
427 self.assertEqual(B.reported, 1)
428
429 self.assertEqual(self.history[0].changes, '1,1 2,1')
430 self.assertEqual(self.history[1].changes, '1,1')
431 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
432
433 self.assertIn('Build succeeded', A.messages[0])
434 self.assertIn('Build succeeded', B.messages[0])
435
436 def _test_crd_check_reconfiguration(self, project1, project2):
437 "Test cross-repo dependencies re-enqueued in independent pipelines"
438
439 self.gearman_server.hold_jobs_in_queue = True
440 A = self.fake_gerrit.addFakeChange(project1, 'master', 'A')
441 B = self.fake_gerrit.addFakeChange(project2, 'master', 'B')
442
443 # A Depends-On: B
444 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
445 A.subject, B.data['id'])
446
447 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
448 self.waitUntilSettled()
449
450 self.sched.reconfigure(self.config)
451
452 # Make sure the items still share a change queue, and the
453 # first one is not live.
454 tenant = self.sched.abide.tenants.get('tenant-one')
455 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1)
456 queue = tenant.layout.pipelines['check'].queues[0]
457 first_item = queue.queue[0]
458 for item in queue.queue:
459 self.assertEqual(item.queue, first_item.queue)
460 self.assertFalse(first_item.live)
461 self.assertTrue(queue.queue[1].live)
462
463 self.gearman_server.hold_jobs_in_queue = False
464 self.gearman_server.release()
465 self.waitUntilSettled()
466
467 self.assertEqual(A.data['status'], 'NEW')
468 self.assertEqual(B.data['status'], 'NEW')
469 self.assertEqual(A.reported, 1)
470 self.assertEqual(B.reported, 0)
471
472 self.assertEqual(self.history[0].changes, '2,1 1,1')
473 self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
474
475 def test_crd_check_reconfiguration(self):
476 self._test_crd_check_reconfiguration('org/project1', 'org/project2')
477
478 def test_crd_undefined_project(self):
479 """Test that undefined projects in dependencies are handled for
480 independent pipelines"""
481 # It's a hack for fake gerrit,
482 # as it implies repo creation upon the creation of any change
483 self.init_repo("org/unknown", tag='init')
484 self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
485
486 @simple_layout('layouts/ignore-dependencies.yaml')
487 def test_crd_check_ignore_dependencies(self):
488 "Test cross-repo dependencies can be ignored"
489
490 self.gearman_server.hold_jobs_in_queue = True
491 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
492 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
493 C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
494
495 # A Depends-On: B
496 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
497 A.subject, B.data['id'])
498 # C git-depends on B
499 C.setDependsOn(B, 1)
500 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
501 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
502 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
503 self.waitUntilSettled()
504
505 # Make sure none of the items share a change queue, and all
506 # are live.
507 tenant = self.sched.abide.tenants.get('tenant-one')
508 check_pipeline = tenant.layout.pipelines['check']
509 self.assertEqual(len(check_pipeline.queues), 3)
510 self.assertEqual(len(check_pipeline.getAllItems()), 3)
511 for item in check_pipeline.getAllItems():
512 self.assertTrue(item.live)
513
514 self.gearman_server.hold_jobs_in_queue = False
515 self.gearman_server.release()
516 self.waitUntilSettled()
517
518 self.assertEqual(A.data['status'], 'NEW')
519 self.assertEqual(B.data['status'], 'NEW')
520 self.assertEqual(C.data['status'], 'NEW')
521 self.assertEqual(A.reported, 1)
522 self.assertEqual(B.reported, 1)
523 self.assertEqual(C.reported, 1)
524
525 # Each job should have tested exactly one change
526 for job in self.history:
527 self.assertEqual(len(job.changes.split()), 1)
528
529 @simple_layout('layouts/three-projects.yaml')
530 def test_crd_check_transitive(self):
531 "Test transitive cross-repo dependencies"
532 # Specifically, if A -> B -> C, and C gets a new patchset and
533 # A gets a new patchset, ensure the test of A,2 includes B,1
534 # and C,2 (not C,1 which would indicate stale data in the
535 # cache for B).
536 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
537 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
538 C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
539
540 # A Depends-On: B
541 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
542 A.subject, B.data['id'])
543
544 # B Depends-On: C
545 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
546 B.subject, C.data['id'])
547
548 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
549 self.waitUntilSettled()
550 self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1')
551
552 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
553 self.waitUntilSettled()
554 self.assertEqual(self.history[-1].changes, '3,1 2,1')
555
556 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1))
557 self.waitUntilSettled()
558 self.assertEqual(self.history[-1].changes, '3,1')
559
560 C.addPatchset()
561 self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2))
562 self.waitUntilSettled()
563 self.assertEqual(self.history[-1].changes, '3,2')
564
565 A.addPatchset()
566 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
567 self.waitUntilSettled()
568 self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2')
569
570 def test_crd_check_unknown(self):
571 "Test unknown projects in independent pipeline"
572 self.init_repo("org/unknown", tag='init')
573 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
574 B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D')
575 # A Depends-On: B
576 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
577 A.subject, B.data['id'])
578
579 # Make sure zuul has seen an event on B.
580 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
581 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
582 self.waitUntilSettled()
583
584 self.assertEqual(A.data['status'], 'NEW')
585 self.assertEqual(A.reported, 1)
586 self.assertEqual(B.data['status'], 'NEW')
587 self.assertEqual(B.reported, 0)
588
589 def test_crd_cycle_join(self):
590 "Test an updated change creates a cycle"
591 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
592
593 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
594 self.waitUntilSettled()
595 self.assertEqual(A.reported, 1)
596
597 # Create B->A
598 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
599 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
600 B.subject, A.data['id'])
601 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
602 self.waitUntilSettled()
603
604 # Dep is there so zuul should have reported on B
605 self.assertEqual(B.reported, 1)
606
607 # Update A to add A->B (a cycle).
608 A.addPatchset()
609 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
610 A.subject, B.data['id'])
611 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
612 self.waitUntilSettled()
613
614 # Dependency cycle injected so zuul should not have reported again on A
615 self.assertEqual(A.reported, 1)
616
617 # Now if we update B to remove the depends-on, everything
618 # should be okay. B; A->B
619
620 B.addPatchset()
621 B.data['commitMessage'] = '%s\n' % (B.subject,)
622 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2))
623 self.waitUntilSettled()
624
625 # Cycle was removed so now zuul should have reported again on A
626 self.assertEqual(A.reported, 2)
627
628 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2))
629 self.waitUntilSettled()
630 self.assertEqual(B.reported, 2)