James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2014 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 | |
| 17 | import logging |
| 18 | import time |
| 19 | |
| 20 | from tests.base import ZuulTestCase |
| 21 | |
| 22 | logging.basicConfig(level=logging.DEBUG, |
| 23 | format='%(asctime)s %(name)-32s ' |
| 24 | '%(levelname)-8s %(message)s') |
| 25 | |
| 26 | |
| 27 | class TestZuulTrigger(ZuulTestCase): |
| 28 | """Test Zuul Trigger""" |
| 29 | |
| 30 | def test_zuul_trigger_parent_change_enqueued(self): |
| 31 | "Test Zuul trigger event: parent-change-enqueued" |
| 32 | self.config.set('zuul', 'layout_config', |
| 33 | 'tests/fixtures/layout-zuultrigger-enqueued.yaml') |
| 34 | self.sched.reconfigure(self.config) |
| 35 | self.registerJobs() |
| 36 | |
| 37 | # This test has the following three changes: |
| 38 | # B1 -> A; B2 -> A |
| 39 | # When A is enqueued in the gate, B1 and B2 should both attempt |
| 40 | # to be enqueued in both pipelines. B1 should end up in check |
| 41 | # and B2 in gate because of differing pipeline requirements. |
| 42 | self.worker.hold_jobs_in_build = True |
| 43 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 44 | B1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B1') |
| 45 | B2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'B2') |
| 46 | A.addApproval('CRVW', 2) |
| 47 | B1.addApproval('CRVW', 2) |
| 48 | B2.addApproval('CRVW', 2) |
| 49 | A.addApproval('VRFY', 1) # required by gate |
| 50 | B1.addApproval('VRFY', -1) # should go to check |
| 51 | B2.addApproval('VRFY', 1) # should go to gate |
| 52 | B1.addApproval('APRV', 1) |
| 53 | B2.addApproval('APRV', 1) |
| 54 | B1.setDependsOn(A, 1) |
| 55 | B2.setDependsOn(A, 1) |
| 56 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 57 | # Jobs are being held in build to make sure that 3,1 has time |
| 58 | # to enqueue behind 1,1 so that the test is more |
| 59 | # deterministic. |
| 60 | self.waitUntilSettled() |
| 61 | self.worker.hold_jobs_in_build = False |
| 62 | self.worker.release() |
| 63 | self.waitUntilSettled() |
| 64 | |
| 65 | self.assertEqual(len(self.history), 3) |
| 66 | for job in self.history: |
| 67 | if job.changes == '1,1': |
| 68 | self.assertEqual(job.name, 'project-gate') |
| 69 | elif job.changes == '2,1': |
| 70 | self.assertEqual(job.name, 'project-check') |
| 71 | elif job.changes == '1,1 3,1': |
| 72 | self.assertEqual(job.name, 'project-gate') |
| 73 | else: |
| 74 | raise Exception("Unknown job") |
| 75 | |
| 76 | def test_zuul_trigger_project_change_merged(self): |
| 77 | "Test Zuul trigger event: project-change-merged" |
| 78 | self.config.set('zuul', 'layout_config', |
| 79 | 'tests/fixtures/layout-zuultrigger-merged.yaml') |
| 80 | self.sched.reconfigure(self.config) |
| 81 | self.registerJobs() |
| 82 | |
| 83 | # This test has the following three changes: |
| 84 | # A, B, C; B conflicts with A, but C does not. |
| 85 | # When A is merged, B and C should be checked for conflicts, |
| 86 | # and B should receive a -1. |
| 87 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 88 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 89 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 90 | A.addPatchset(['conflict']) |
| 91 | B.addPatchset(['conflict']) |
| 92 | A.addApproval('CRVW', 2) |
| 93 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 94 | self.waitUntilSettled() |
| 95 | |
| 96 | self.assertEqual(len(self.history), 1) |
| 97 | self.assertEqual(self.history[0].name, 'project-gate') |
| 98 | self.assertEqual(A.reported, 2) |
| 99 | self.assertEqual(B.reported, 1) |
| 100 | self.assertEqual(C.reported, 0) |
| 101 | self.assertEqual(B.messages[0], |
| 102 | "Merge Failed.\n\nThis change was unable to be automatically " |
| 103 | "merged with the current state of the repository. Please rebase " |
| 104 | "your change and upload a new patchset.") |