James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/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. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | import logging |
| 19 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 20 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 21 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 22 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 23 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 25 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 26 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 27 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 28 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 29 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 31 | import zuul.rpcclient |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 32 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 33 | import zuul.reporter.smtp |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 34 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
| 39 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 40 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 41 | logging.basicConfig(level=logging.DEBUG, |
| 42 | format='%(asctime)s %(name)-32s ' |
| 43 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
| 45 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 46 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 47 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 48 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 49 | def test_jobs_launched(self): |
| 50 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 51 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 52 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 53 | A.addApproval('code-review', 2) |
| 54 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 55 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 56 | 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. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 64 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 65 | 'image1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 66 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 67 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 68 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 70 | value='1|g') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 72 | kind='ms') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 74 | value='1|c') |
| 75 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 76 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 77 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 79 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 80 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 81 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 82 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 83 | for build in self.builds: |
| 84 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 85 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 86 | def test_initial_pipeline_gauges(self): |
| 87 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 88 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 89 | value='0|g') |
| 90 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 91 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 92 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 93 | def test_job_branch(self): |
| 94 | "Test the correct variant of a job runs on a branch" |
| 95 | self.create_branch('org/project', 'stable') |
| 96 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 97 | A.addApproval('code-review', 2) |
| 98 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 99 | self.waitUntilSettled() |
| 100 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 101 | 'SUCCESS') |
| 102 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 103 | 'SUCCESS') |
| 104 | self.assertEqual(A.data['status'], 'MERGED') |
| 105 | self.assertEqual(A.reported, 2, |
| 106 | "A should report start and success") |
| 107 | self.assertIn('gate', A.messages[1], |
| 108 | "A should transit gate") |
| 109 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 110 | 'image2') |
| 111 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 112 | def test_parallel_changes(self): |
| 113 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 114 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 115 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 116 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 117 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 118 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 119 | A.addApproval('code-review', 2) |
| 120 | B.addApproval('code-review', 2) |
| 121 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 122 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 123 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 124 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 125 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 126 | |
| 127 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 128 | self.assertEqual(len(self.builds), 1) |
| 129 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 130 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 131 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 132 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 133 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 134 | self.assertEqual(len(self.builds), 3) |
| 135 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 138 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 139 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 140 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 141 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 142 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 144 | self.assertEqual(len(self.builds), 5) |
| 145 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 146 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 147 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 148 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 149 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 150 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 152 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 153 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 154 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 155 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 158 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 159 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 160 | self.assertEqual(len(self.builds), 6) |
| 161 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 164 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 165 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 168 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 169 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 173 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 174 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 175 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 176 | self.launch_server.hold_jobs_in_build = False |
| 177 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 180 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 181 | self.assertEqual(len(self.history), 9) |
| 182 | self.assertEqual(A.data['status'], 'MERGED') |
| 183 | self.assertEqual(B.data['status'], 'MERGED') |
| 184 | self.assertEqual(C.data['status'], 'MERGED') |
| 185 | self.assertEqual(A.reported, 2) |
| 186 | self.assertEqual(B.reported, 2) |
| 187 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 188 | |
| 189 | def test_failed_changes(self): |
| 190 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 191 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 192 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 193 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 194 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 195 | A.addApproval('code-review', 2) |
| 196 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 197 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 198 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 199 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 200 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 201 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 202 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 203 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 204 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 205 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 206 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 207 | # A/project-merge is complete |
| 208 | self.assertBuilds([ |
| 209 | dict(name='project-test1', changes='1,1'), |
| 210 | dict(name='project-test2', changes='1,1'), |
| 211 | dict(name='project-merge', changes='1,1 2,1'), |
| 212 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 213 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 214 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 215 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 216 | # A/project-merge is complete |
| 217 | # B/project-merge is complete |
| 218 | self.assertBuilds([ |
| 219 | dict(name='project-test1', changes='1,1'), |
| 220 | dict(name='project-test2', changes='1,1'), |
| 221 | dict(name='project-test1', changes='1,1 2,1'), |
| 222 | dict(name='project-test2', changes='1,1 2,1'), |
| 223 | ]) |
| 224 | |
| 225 | # Release project-test1 for A which will fail. This will |
| 226 | # abort both running B jobs and relaunch project-merge for B. |
| 227 | self.builds[0].release() |
| 228 | self.waitUntilSettled() |
| 229 | |
| 230 | self.orderedRelease() |
| 231 | self.assertHistory([ |
| 232 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 233 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 234 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 235 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 236 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 237 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 238 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 239 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 240 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 241 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 242 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 243 | self.assertEqual(A.data['status'], 'NEW') |
| 244 | self.assertEqual(B.data['status'], 'MERGED') |
| 245 | self.assertEqual(A.reported, 2) |
| 246 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | |
| 248 | def test_independent_queues(self): |
| 249 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 250 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 251 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 253 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 254 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 255 | A.addApproval('code-review', 2) |
| 256 | B.addApproval('code-review', 2) |
| 257 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 258 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 259 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 260 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 261 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 262 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 263 | self.waitUntilSettled() |
| 264 | |
| 265 | # There should be one merge job at the head of each queue running |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 266 | self.assertBuilds([ |
| 267 | dict(name='project-merge', changes='1,1'), |
| 268 | dict(name='project-merge', changes='2,1'), |
| 269 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 270 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 271 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 272 | self.builds[0].release() |
| 273 | self.waitUntilSettled() |
| 274 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 275 | self.waitUntilSettled() |
| 276 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 277 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 278 | self.waitUntilSettled() |
| 279 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 280 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 281 | self.assertBuilds([ |
| 282 | dict(name='project-test1', changes='1,1'), |
| 283 | dict(name='project-test2', changes='1,1'), |
| 284 | dict(name='project-test1', changes='2,1'), |
| 285 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 286 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 287 | dict(name='project-test1', changes='2,1 3,1'), |
| 288 | dict(name='project-test2', changes='2,1 3,1'), |
| 289 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 290 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 291 | self.orderedRelease() |
| 292 | self.assertHistory([ |
| 293 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 294 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 295 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 296 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 298 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 299 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 300 | dict( |
| 301 | name='project1-project2-integration', |
| 302 | result='SUCCESS', |
| 303 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 304 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 305 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
| 306 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 307 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 308 | self.assertEqual(A.data['status'], 'MERGED') |
| 309 | self.assertEqual(B.data['status'], 'MERGED') |
| 310 | self.assertEqual(C.data['status'], 'MERGED') |
| 311 | self.assertEqual(A.reported, 2) |
| 312 | self.assertEqual(B.reported, 2) |
| 313 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 314 | |
| 315 | def test_failed_change_at_head(self): |
| 316 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 317 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 318 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 319 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 320 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 321 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 322 | A.addApproval('code-review', 2) |
| 323 | B.addApproval('code-review', 2) |
| 324 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 325 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 326 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 327 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 328 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 329 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 330 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 331 | |
| 332 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 333 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 334 | self.assertBuilds([ |
| 335 | dict(name='project-merge', changes='1,1'), |
| 336 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 338 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 339 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 340 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 341 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 342 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | self.waitUntilSettled() |
| 344 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 345 | self.assertBuilds([ |
| 346 | dict(name='project-test1', changes='1,1'), |
| 347 | dict(name='project-test2', changes='1,1'), |
| 348 | dict(name='project-test1', changes='1,1 2,1'), |
| 349 | dict(name='project-test2', changes='1,1 2,1'), |
| 350 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 351 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 352 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 354 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 355 | self.waitUntilSettled() |
| 356 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 357 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 358 | self.assertBuilds([ |
| 359 | dict(name='project-test2', changes='1,1'), |
| 360 | dict(name='project-merge', changes='2,1'), |
| 361 | ]) |
| 362 | # Unordered history comparison because the aborts can finish |
| 363 | # in any order. |
| 364 | self.assertHistory([ |
| 365 | dict(name='project-merge', result='SUCCESS', |
| 366 | changes='1,1'), |
| 367 | dict(name='project-merge', result='SUCCESS', |
| 368 | changes='1,1 2,1'), |
| 369 | dict(name='project-merge', result='SUCCESS', |
| 370 | changes='1,1 2,1 3,1'), |
| 371 | dict(name='project-test1', result='FAILURE', |
| 372 | changes='1,1'), |
| 373 | dict(name='project-test1', result='ABORTED', |
| 374 | changes='1,1 2,1'), |
| 375 | dict(name='project-test2', result='ABORTED', |
| 376 | changes='1,1 2,1'), |
| 377 | dict(name='project-test1', result='ABORTED', |
| 378 | changes='1,1 2,1 3,1'), |
| 379 | dict(name='project-test2', result='ABORTED', |
| 380 | changes='1,1 2,1 3,1'), |
| 381 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 383 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 384 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 385 | self.launch_server.release('.*-merge') |
| 386 | self.waitUntilSettled() |
| 387 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 389 | self.assertBuilds([]) |
| 390 | self.assertHistory([ |
| 391 | dict(name='project-merge', result='SUCCESS', |
| 392 | changes='1,1'), |
| 393 | dict(name='project-merge', result='SUCCESS', |
| 394 | changes='1,1 2,1'), |
| 395 | dict(name='project-merge', result='SUCCESS', |
| 396 | changes='1,1 2,1 3,1'), |
| 397 | dict(name='project-test1', result='FAILURE', |
| 398 | changes='1,1'), |
| 399 | dict(name='project-test1', result='ABORTED', |
| 400 | changes='1,1 2,1'), |
| 401 | dict(name='project-test2', result='ABORTED', |
| 402 | changes='1,1 2,1'), |
| 403 | dict(name='project-test1', result='ABORTED', |
| 404 | changes='1,1 2,1 3,1'), |
| 405 | dict(name='project-test2', result='ABORTED', |
| 406 | changes='1,1 2,1 3,1'), |
| 407 | dict(name='project-merge', result='SUCCESS', |
| 408 | changes='2,1'), |
| 409 | dict(name='project-merge', result='SUCCESS', |
| 410 | changes='2,1 3,1'), |
| 411 | dict(name='project-test2', result='SUCCESS', |
| 412 | changes='1,1'), |
| 413 | dict(name='project-test1', result='SUCCESS', |
| 414 | changes='2,1'), |
| 415 | dict(name='project-test2', result='SUCCESS', |
| 416 | changes='2,1'), |
| 417 | dict(name='project-test1', result='SUCCESS', |
| 418 | changes='2,1 3,1'), |
| 419 | dict(name='project-test2', result='SUCCESS', |
| 420 | changes='2,1 3,1'), |
| 421 | ], ordered=False) |
| 422 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 423 | self.assertEqual(A.data['status'], 'NEW') |
| 424 | self.assertEqual(B.data['status'], 'MERGED') |
| 425 | self.assertEqual(C.data['status'], 'MERGED') |
| 426 | self.assertEqual(A.reported, 2) |
| 427 | self.assertEqual(B.reported, 2) |
| 428 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 429 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 430 | def test_failed_change_in_middle(self): |
| 431 | "Test a failed change in the middle of the queue" |
| 432 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 433 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 434 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 435 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 436 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 437 | A.addApproval('code-review', 2) |
| 438 | B.addApproval('code-review', 2) |
| 439 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 440 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 441 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 442 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 443 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 444 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 445 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 446 | |
| 447 | self.waitUntilSettled() |
| 448 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 449 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 451 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 452 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 453 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 454 | self.waitUntilSettled() |
| 455 | |
| 456 | self.assertEqual(len(self.builds), 6) |
| 457 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 458 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 459 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 460 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 461 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 462 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 463 | |
| 464 | self.release(self.builds[2]) |
| 465 | self.waitUntilSettled() |
| 466 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 467 | # project-test1 and project-test2 for A |
| 468 | # project-test2 for B |
| 469 | # project-merge for C (without B) |
| 470 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 471 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 472 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 473 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 474 | self.waitUntilSettled() |
| 475 | |
| 476 | # project-test1 and project-test2 for A |
| 477 | # project-test2 for B |
| 478 | # project-test1 and project-test2 for C |
| 479 | self.assertEqual(len(self.builds), 5) |
| 480 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 481 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 482 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 483 | builds = items[0].current_build_set.getBuilds() |
| 484 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 485 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 486 | builds = items[1].current_build_set.getBuilds() |
| 487 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 488 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 489 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 490 | builds = items[2].current_build_set.getBuilds() |
| 491 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 492 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 493 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 494 | self.launch_server.hold_jobs_in_build = False |
| 495 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 496 | self.waitUntilSettled() |
| 497 | |
| 498 | self.assertEqual(len(self.builds), 0) |
| 499 | self.assertEqual(len(self.history), 12) |
| 500 | self.assertEqual(A.data['status'], 'MERGED') |
| 501 | self.assertEqual(B.data['status'], 'NEW') |
| 502 | self.assertEqual(C.data['status'], 'MERGED') |
| 503 | self.assertEqual(A.reported, 2) |
| 504 | self.assertEqual(B.reported, 2) |
| 505 | self.assertEqual(C.reported, 2) |
| 506 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 507 | def test_failed_change_at_head_with_queue(self): |
| 508 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 509 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 510 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 511 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 512 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 513 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 514 | A.addApproval('code-review', 2) |
| 515 | B.addApproval('code-review', 2) |
| 516 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 517 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 518 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 519 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 520 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 521 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 522 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 523 | |
| 524 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 525 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 526 | self.assertEqual(len(self.builds), 0) |
| 527 | self.assertEqual(len(queue), 1) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 528 | self.assertEqual(queue[0].name, 'launcher:launch') |
| 529 | job_args = json.loads(queue[0].arguments) |
| 530 | self.assertEqual(job_args['job'], 'project-merge') |
| 531 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 532 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 533 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 534 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 535 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 536 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 537 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 538 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 539 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 540 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 541 | self.assertEqual(len(self.builds), 0) |
| 542 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 543 | |
| 544 | self.assertEqual( |
| 545 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 546 | self.assertEqual( |
| 547 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 548 | self.assertEqual( |
| 549 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 550 | self.assertEqual( |
| 551 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 552 | self.assertEqual( |
| 553 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 554 | self.assertEqual( |
| 555 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 556 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 557 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 558 | self.waitUntilSettled() |
| 559 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 560 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 561 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 562 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 563 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 564 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 565 | self.gearman_server.hold_jobs_in_queue = False |
| 566 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 567 | self.waitUntilSettled() |
| 568 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 569 | self.assertEqual(len(self.builds), 0) |
| 570 | self.assertEqual(len(self.history), 11) |
| 571 | self.assertEqual(A.data['status'], 'NEW') |
| 572 | self.assertEqual(B.data['status'], 'MERGED') |
| 573 | self.assertEqual(C.data['status'], 'MERGED') |
| 574 | self.assertEqual(A.reported, 2) |
| 575 | self.assertEqual(B.reported, 2) |
| 576 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 577 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 578 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 579 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 580 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 582 | A.addApproval('code-review', 2) |
| 583 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 584 | self.waitUntilSettled() |
| 585 | time.sleep(2) |
| 586 | |
| 587 | data = json.loads(self.sched.formatStatusJSON()) |
| 588 | found_job = None |
| 589 | for pipeline in data['pipelines']: |
| 590 | if pipeline['name'] != 'gate': |
| 591 | continue |
| 592 | for queue in pipeline['change_queues']: |
| 593 | for head in queue['heads']: |
| 594 | for item in head: |
| 595 | for job in item['jobs']: |
| 596 | if job['name'] == 'project-merge': |
| 597 | found_job = job |
| 598 | break |
| 599 | |
| 600 | self.assertIsNotNone(found_job) |
| 601 | if iteration == 1: |
| 602 | self.assertIsNotNone(found_job['estimated_time']) |
| 603 | self.assertIsNone(found_job['remaining_time']) |
| 604 | else: |
| 605 | self.assertIsNotNone(found_job['estimated_time']) |
| 606 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 607 | self.assertIsNotNone(found_job['remaining_time']) |
| 608 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 609 | self.launch_server.hold_jobs_in_build = False |
| 610 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 611 | self.waitUntilSettled() |
| 612 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 613 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 614 | def test_time_database(self): |
| 615 | "Test the time database" |
| 616 | |
| 617 | self._test_time_database(1) |
| 618 | self._test_time_database(2) |
| 619 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 620 | def test_two_failed_changes_at_head(self): |
| 621 | "Test that changes are reparented correctly if 2 fail at head" |
| 622 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 623 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 624 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 625 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 626 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 627 | A.addApproval('code-review', 2) |
| 628 | B.addApproval('code-review', 2) |
| 629 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 630 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 631 | self.launch_server.failJob('project-test1', A) |
| 632 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 633 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 634 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 635 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 636 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 637 | self.waitUntilSettled() |
| 638 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 639 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 640 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 641 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 642 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 643 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
| 645 | |
| 646 | self.assertEqual(len(self.builds), 6) |
| 647 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 648 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 649 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 650 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 651 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 652 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 653 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 654 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 655 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 656 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 657 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 658 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 659 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 660 | |
| 661 | # Fail change B first |
| 662 | self.release(self.builds[2]) |
| 663 | self.waitUntilSettled() |
| 664 | |
| 665 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 666 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 667 | self.waitUntilSettled() |
| 668 | |
| 669 | self.assertEqual(len(self.builds), 5) |
| 670 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 671 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 672 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 673 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 674 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 675 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 676 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 677 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 678 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 679 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 680 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 681 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | |
| 683 | # Finish running all passing jobs for change A |
| 684 | self.release(self.builds[1]) |
| 685 | self.waitUntilSettled() |
| 686 | # Fail and report change A |
| 687 | self.release(self.builds[0]) |
| 688 | self.waitUntilSettled() |
| 689 | |
| 690 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 691 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 692 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 693 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 694 | self.waitUntilSettled() |
| 695 | |
| 696 | self.assertEqual(len(self.builds), 4) |
| 697 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 698 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 699 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 700 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 701 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 702 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 703 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 704 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 706 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | # After A failed and B and C restarted, B should be back in |
| 708 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 709 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 710 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 711 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 712 | self.launch_server.hold_jobs_in_build = False |
| 713 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 714 | self.waitUntilSettled() |
| 715 | |
| 716 | self.assertEqual(len(self.builds), 0) |
| 717 | self.assertEqual(len(self.history), 21) |
| 718 | self.assertEqual(A.data['status'], 'NEW') |
| 719 | self.assertEqual(B.data['status'], 'NEW') |
| 720 | self.assertEqual(C.data['status'], 'MERGED') |
| 721 | self.assertEqual(A.reported, 2) |
| 722 | self.assertEqual(B.reported, 2) |
| 723 | self.assertEqual(C.reported, 2) |
| 724 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 725 | def test_patch_order(self): |
| 726 | "Test that dependent patches are tested in the right order" |
| 727 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 728 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 729 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 730 | A.addApproval('code-review', 2) |
| 731 | B.addApproval('code-review', 2) |
| 732 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 733 | |
| 734 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 735 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 736 | M2.setMerged() |
| 737 | M1.setMerged() |
| 738 | |
| 739 | # C -> B -> A -> M1 -> M2 |
| 740 | # M2 is here to make sure it is never queried. If it is, it |
| 741 | # means zuul is walking down the entire history of merged |
| 742 | # changes. |
| 743 | |
| 744 | C.setDependsOn(B, 1) |
| 745 | B.setDependsOn(A, 1) |
| 746 | A.setDependsOn(M1, 1) |
| 747 | M1.setDependsOn(M2, 1) |
| 748 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 749 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 750 | |
| 751 | self.waitUntilSettled() |
| 752 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 753 | self.assertEqual(A.data['status'], 'NEW') |
| 754 | self.assertEqual(B.data['status'], 'NEW') |
| 755 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 756 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 757 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 758 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 759 | |
| 760 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 761 | self.assertEqual(M2.queried, 0) |
| 762 | self.assertEqual(A.data['status'], 'MERGED') |
| 763 | self.assertEqual(B.data['status'], 'MERGED') |
| 764 | self.assertEqual(C.data['status'], 'MERGED') |
| 765 | self.assertEqual(A.reported, 2) |
| 766 | self.assertEqual(B.reported, 2) |
| 767 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 768 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 769 | def test_needed_changes_enqueue(self): |
| 770 | "Test that a needed change is enqueued ahead" |
| 771 | # A Given a git tree like this, if we enqueue |
| 772 | # / \ change C, we should walk up and down the tree |
| 773 | # B G and enqueue changes in the order ABCDEFG. |
| 774 | # /|\ This is also the order that you would get if |
| 775 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 776 | # / the ordering is stable across re-enqueue events. |
| 777 | # D |
| 778 | |
| 779 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 780 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 781 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 782 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 783 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 784 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 785 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 786 | B.setDependsOn(A, 1) |
| 787 | C.setDependsOn(B, 1) |
| 788 | D.setDependsOn(C, 1) |
| 789 | E.setDependsOn(B, 1) |
| 790 | F.setDependsOn(B, 1) |
| 791 | G.setDependsOn(A, 1) |
| 792 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 793 | A.addApproval('code-review', 2) |
| 794 | B.addApproval('code-review', 2) |
| 795 | C.addApproval('code-review', 2) |
| 796 | D.addApproval('code-review', 2) |
| 797 | E.addApproval('code-review', 2) |
| 798 | F.addApproval('code-review', 2) |
| 799 | G.addApproval('code-review', 2) |
| 800 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 801 | |
| 802 | self.waitUntilSettled() |
| 803 | |
| 804 | self.assertEqual(A.data['status'], 'NEW') |
| 805 | self.assertEqual(B.data['status'], 'NEW') |
| 806 | self.assertEqual(C.data['status'], 'NEW') |
| 807 | self.assertEqual(D.data['status'], 'NEW') |
| 808 | self.assertEqual(E.data['status'], 'NEW') |
| 809 | self.assertEqual(F.data['status'], 'NEW') |
| 810 | self.assertEqual(G.data['status'], 'NEW') |
| 811 | |
| 812 | # We're about to add approvals to changes without adding the |
| 813 | # triggering events to Zuul, so that we can be sure that it is |
| 814 | # enqueing the changes based on dependencies, not because of |
| 815 | # triggering events. Since it will have the changes cached |
| 816 | # already (without approvals), we need to clear the cache |
| 817 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 818 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 819 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 820 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 821 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 822 | A.addApproval('approved', 1) |
| 823 | B.addApproval('approved', 1) |
| 824 | D.addApproval('approved', 1) |
| 825 | E.addApproval('approved', 1) |
| 826 | F.addApproval('approved', 1) |
| 827 | G.addApproval('approved', 1) |
| 828 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 829 | |
| 830 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 831 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 832 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 833 | self.launch_server.hold_jobs_in_build = False |
| 834 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 835 | self.waitUntilSettled() |
| 836 | |
| 837 | self.assertEqual(A.data['status'], 'MERGED') |
| 838 | self.assertEqual(B.data['status'], 'MERGED') |
| 839 | self.assertEqual(C.data['status'], 'MERGED') |
| 840 | self.assertEqual(D.data['status'], 'MERGED') |
| 841 | self.assertEqual(E.data['status'], 'MERGED') |
| 842 | self.assertEqual(F.data['status'], 'MERGED') |
| 843 | self.assertEqual(G.data['status'], 'MERGED') |
| 844 | self.assertEqual(A.reported, 2) |
| 845 | self.assertEqual(B.reported, 2) |
| 846 | self.assertEqual(C.reported, 2) |
| 847 | self.assertEqual(D.reported, 2) |
| 848 | self.assertEqual(E.reported, 2) |
| 849 | self.assertEqual(F.reported, 2) |
| 850 | self.assertEqual(G.reported, 2) |
| 851 | self.assertEqual(self.history[6].changes, |
| 852 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 853 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 854 | def test_source_cache(self): |
| 855 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 856 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 857 | |
| 858 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 859 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 860 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 861 | A.addApproval('code-review', 2) |
| 862 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 863 | |
| 864 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 865 | M1.setMerged() |
| 866 | |
| 867 | B.setDependsOn(A, 1) |
| 868 | A.setDependsOn(M1, 1) |
| 869 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 870 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 871 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 872 | |
| 873 | self.waitUntilSettled() |
| 874 | |
| 875 | for build in self.builds: |
| 876 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 877 | build.release() |
| 878 | self.waitUntilSettled() |
| 879 | for build in self.builds: |
| 880 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 881 | build.release() |
| 882 | self.waitUntilSettled() |
| 883 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 884 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 885 | self.waitUntilSettled() |
| 886 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 887 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 888 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 889 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 890 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 891 | self.launch_server.hold_jobs_in_build = False |
| 892 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 893 | self.waitUntilSettled() |
| 894 | |
| 895 | self.assertEqual(A.data['status'], 'MERGED') |
| 896 | self.assertEqual(B.data['status'], 'MERGED') |
| 897 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 898 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 899 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 900 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 901 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 902 | # TODO: move to test_gerrit (this is a unit test!) |
| 903 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 904 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 905 | source = tenant.layout.pipelines['gate'].source |
| 906 | |
| 907 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 908 | # it easier for users to create events for testing. |
| 909 | event = zuul.model.TriggerEvent() |
| 910 | event.trigger_name = 'gerrit' |
| 911 | event.change_number = '1' |
| 912 | event.patch_number = '2' |
| 913 | |
| 914 | a = source.getChange(event) |
| 915 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 916 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 917 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 918 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 919 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 920 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 921 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 922 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 923 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 924 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 925 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 926 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 927 | def test_build_configuration_conflict(self): |
| 928 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 929 | |
| 930 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 931 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 932 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 933 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 934 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 935 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 936 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 937 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 938 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 939 | A.addApproval('code-review', 2) |
| 940 | B.addApproval('code-review', 2) |
| 941 | C.addApproval('code-review', 2) |
| 942 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 943 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 944 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 945 | self.waitUntilSettled() |
| 946 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 947 | self.assertEqual(A.reported, 1) |
| 948 | self.assertEqual(B.reported, 1) |
| 949 | self.assertEqual(C.reported, 1) |
| 950 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 951 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 952 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 953 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 954 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 955 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 957 | |
| 958 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 959 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 960 | self.gearman_server.hold_jobs_in_queue = False |
| 961 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 962 | self.waitUntilSettled() |
| 963 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 964 | self.assertEqual(A.data['status'], 'MERGED') |
| 965 | self.assertEqual(B.data['status'], 'NEW') |
| 966 | self.assertEqual(C.data['status'], 'MERGED') |
| 967 | self.assertEqual(A.reported, 2) |
| 968 | self.assertEqual(B.reported, 2) |
| 969 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 970 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 971 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 972 | def test_post(self): |
| 973 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 974 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 975 | e = { |
| 976 | "type": "ref-updated", |
| 977 | "submitter": { |
| 978 | "name": "User Name", |
| 979 | }, |
| 980 | "refUpdate": { |
| 981 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 982 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 983 | "refName": "master", |
| 984 | "project": "org/project", |
| 985 | } |
| 986 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 987 | self.fake_gerrit.addEvent(e) |
| 988 | self.waitUntilSettled() |
| 989 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 990 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 991 | self.assertEqual(len(self.history), 1) |
| 992 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 993 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 994 | def test_post_ignore_deletes(self): |
| 995 | "Test that deleting refs does not trigger post jobs" |
| 996 | |
| 997 | e = { |
| 998 | "type": "ref-updated", |
| 999 | "submitter": { |
| 1000 | "name": "User Name", |
| 1001 | }, |
| 1002 | "refUpdate": { |
| 1003 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1004 | "newRev": "0000000000000000000000000000000000000000", |
| 1005 | "refName": "master", |
| 1006 | "project": "org/project", |
| 1007 | } |
| 1008 | } |
| 1009 | self.fake_gerrit.addEvent(e) |
| 1010 | self.waitUntilSettled() |
| 1011 | |
| 1012 | job_names = [x.name for x in self.history] |
| 1013 | self.assertEqual(len(self.history), 0) |
| 1014 | self.assertNotIn('project-post', job_names) |
| 1015 | |
| 1016 | def test_post_ignore_deletes_negative(self): |
| 1017 | "Test that deleting refs does trigger post jobs" |
| 1018 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1019 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1020 | self.sched.reconfigure(self.config) |
| 1021 | |
| 1022 | e = { |
| 1023 | "type": "ref-updated", |
| 1024 | "submitter": { |
| 1025 | "name": "User Name", |
| 1026 | }, |
| 1027 | "refUpdate": { |
| 1028 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1029 | "newRev": "0000000000000000000000000000000000000000", |
| 1030 | "refName": "master", |
| 1031 | "project": "org/project", |
| 1032 | } |
| 1033 | } |
| 1034 | self.fake_gerrit.addEvent(e) |
| 1035 | self.waitUntilSettled() |
| 1036 | |
| 1037 | job_names = [x.name for x in self.history] |
| 1038 | self.assertEqual(len(self.history), 1) |
| 1039 | self.assertIn('project-post', job_names) |
| 1040 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1041 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1042 | def test_build_configuration_branch(self): |
| 1043 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1044 | |
| 1045 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1046 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1047 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1048 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1049 | A.addApproval('code-review', 2) |
| 1050 | B.addApproval('code-review', 2) |
| 1051 | C.addApproval('code-review', 2) |
| 1052 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1053 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1054 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1055 | self.waitUntilSettled() |
| 1056 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1057 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1058 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1059 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1060 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1061 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1062 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1063 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1064 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1065 | self.gearman_server.hold_jobs_in_queue = False |
| 1066 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1067 | self.waitUntilSettled() |
| 1068 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1069 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1070 | repo = git.Repo(path) |
| 1071 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1072 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1073 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1074 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1075 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1076 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1077 | def test_build_configuration_branch_interaction(self): |
| 1078 | "Test that switching between branches works" |
| 1079 | self.test_build_configuration() |
| 1080 | self.test_build_configuration_branch() |
| 1081 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1082 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1083 | repo = git.Repo(path) |
| 1084 | repo.heads.master.commit = repo.commit('init') |
| 1085 | self.test_build_configuration() |
| 1086 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1087 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1088 | def test_build_configuration_multi_branch(self): |
| 1089 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1090 | |
| 1091 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1092 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1093 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1094 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1095 | A.addApproval('code-review', 2) |
| 1096 | B.addApproval('code-review', 2) |
| 1097 | C.addApproval('code-review', 2) |
| 1098 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1099 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1100 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1101 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1102 | queue = self.gearman_server.getQueue() |
| 1103 | job_A = None |
| 1104 | for job in queue: |
| 1105 | if 'project-merge' in job.name: |
| 1106 | job_A = job |
| 1107 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1108 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1109 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1110 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1111 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1112 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1113 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1114 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1115 | job_B = None |
| 1116 | for job in queue: |
| 1117 | if 'project-merge' in job.name: |
| 1118 | job_B = job |
| 1119 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1120 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1121 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1122 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1123 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1124 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1125 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1126 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1127 | for job in queue: |
| 1128 | if 'project-merge' in job.name: |
| 1129 | job_C = job |
| 1130 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1131 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1132 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1133 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1134 | self.gearman_server.hold_jobs_in_queue = False |
| 1135 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1136 | self.waitUntilSettled() |
| 1137 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1138 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1139 | repo = git.Repo(path) |
| 1140 | |
| 1141 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1142 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1143 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1144 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1145 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1146 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1147 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1148 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 1149 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1150 | |
| 1151 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1152 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1153 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1154 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1155 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1156 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1157 | self.assertEqual(repo_shas[0], commit_B) |
| 1158 | |
| 1159 | repo_messages = [c.message.strip() |
| 1160 | for c in repo.iter_commits(ref_A)] |
| 1161 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1162 | repo_messages.reverse() |
| 1163 | correct_messages = ['initial commit', 'A-1'] |
| 1164 | self.assertEqual(repo_messages, correct_messages) |
| 1165 | self.assertEqual(repo_shas[0], commit_A) |
| 1166 | |
| 1167 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1168 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1169 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1170 | def test_dependent_changes_dequeue(self): |
| 1171 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1172 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1173 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1174 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1175 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1176 | A.addApproval('code-review', 2) |
| 1177 | B.addApproval('code-review', 2) |
| 1178 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1179 | |
| 1180 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1181 | M1.setMerged() |
| 1182 | |
| 1183 | # C -> B -> A -> M1 |
| 1184 | |
| 1185 | C.setDependsOn(B, 1) |
| 1186 | B.setDependsOn(A, 1) |
| 1187 | A.setDependsOn(M1, 1) |
| 1188 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1189 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1190 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1191 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1192 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1193 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1194 | |
| 1195 | self.waitUntilSettled() |
| 1196 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1197 | self.assertEqual(A.data['status'], 'NEW') |
| 1198 | self.assertEqual(A.reported, 2) |
| 1199 | self.assertEqual(B.data['status'], 'NEW') |
| 1200 | self.assertEqual(B.reported, 2) |
| 1201 | self.assertEqual(C.data['status'], 'NEW') |
| 1202 | self.assertEqual(C.reported, 2) |
| 1203 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1204 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1205 | def test_failing_dependent_changes(self): |
| 1206 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1207 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1208 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1209 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1210 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1211 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1212 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1213 | A.addApproval('code-review', 2) |
| 1214 | B.addApproval('code-review', 2) |
| 1215 | C.addApproval('code-review', 2) |
| 1216 | D.addApproval('code-review', 2) |
| 1217 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1218 | |
| 1219 | # E, D -> C -> B, A |
| 1220 | |
| 1221 | D.setDependsOn(C, 1) |
| 1222 | C.setDependsOn(B, 1) |
| 1223 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1224 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1225 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1226 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1227 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1228 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1229 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1230 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1231 | |
| 1232 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1233 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1234 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1235 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1236 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1237 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1238 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1239 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1240 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1241 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1242 | self.waitUntilSettled() |
| 1243 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1244 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1245 | for build in self.builds: |
| 1246 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1247 | build.release() |
| 1248 | self.waitUntilSettled() |
| 1249 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1250 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1251 | self.waitUntilSettled() |
| 1252 | |
| 1253 | self.assertEqual(A.data['status'], 'MERGED') |
| 1254 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1255 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1256 | self.assertEqual(B.data['status'], 'NEW') |
| 1257 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1258 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1259 | self.assertEqual(C.data['status'], 'NEW') |
| 1260 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1261 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1262 | self.assertEqual(D.data['status'], 'NEW') |
| 1263 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1264 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1265 | self.assertEqual(E.data['status'], 'MERGED') |
| 1266 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1267 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1268 | self.assertEqual(len(self.history), 18) |
| 1269 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1270 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1271 | "Test that if a change at the head fails it is dequeued only once" |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1272 | # If it's dequeued more than once, we should see extra |
| 1273 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1274 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1275 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1276 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1277 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1278 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1279 | A.addApproval('code-review', 2) |
| 1280 | B.addApproval('code-review', 2) |
| 1281 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1282 | |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1283 | self.launch_server.failJob('project-test1', A) |
| 1284 | self.launch_server.failJob('project-test2', A) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1285 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1286 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1287 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1288 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1289 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1290 | |
| 1291 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1292 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1293 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1294 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1295 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1296 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1297 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1298 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1299 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1300 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1301 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1302 | self.waitUntilSettled() |
| 1303 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1304 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1305 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1306 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1307 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1308 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1309 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1310 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1311 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1312 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1313 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1314 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1315 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1316 | self.waitUntilSettled() |
| 1317 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1318 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1319 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1320 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1321 | self.launch_server.hold_jobs_in_build = False |
| 1322 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1323 | self.waitUntilSettled() |
| 1324 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1325 | self.assertEqual(len(self.builds), 0) |
| 1326 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1327 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1328 | self.assertEqual(A.data['status'], 'NEW') |
| 1329 | self.assertEqual(B.data['status'], 'MERGED') |
| 1330 | self.assertEqual(C.data['status'], 'MERGED') |
| 1331 | self.assertEqual(A.reported, 2) |
| 1332 | self.assertEqual(B.reported, 2) |
| 1333 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1334 | |
| 1335 | def test_nonvoting_job(self): |
| 1336 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1337 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1338 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1339 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1340 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1341 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1342 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1343 | |
| 1344 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1345 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1346 | self.assertEqual(A.data['status'], 'MERGED') |
| 1347 | self.assertEqual(A.reported, 2) |
| 1348 | self.assertEqual( |
| 1349 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1350 | 'SUCCESS') |
| 1351 | self.assertEqual( |
| 1352 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1353 | 'SUCCESS') |
| 1354 | self.assertEqual( |
| 1355 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1356 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1357 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1358 | for build in self.builds: |
| 1359 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1360 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1361 | def test_check_queue_success(self): |
| 1362 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1363 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1364 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1365 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1366 | |
| 1367 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1368 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1369 | self.assertEqual(A.data['status'], 'NEW') |
| 1370 | self.assertEqual(A.reported, 1) |
| 1371 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1372 | 'SUCCESS') |
| 1373 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1374 | 'SUCCESS') |
| 1375 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1376 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1377 | |
| 1378 | def test_check_queue_failure(self): |
| 1379 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1380 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1381 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1382 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1383 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1384 | |
| 1385 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1386 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1387 | self.assertEqual(A.data['status'], 'NEW') |
| 1388 | self.assertEqual(A.reported, 1) |
| 1389 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1390 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1391 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1392 | 'SUCCESS') |
| 1393 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1394 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1395 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1396 | @skip("Disabled for early v3 development") |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1397 | def test_dependent_behind_dequeue(self): |
| 1398 | "test that dependent changes behind dequeued changes work" |
| 1399 | # This complicated test is a reproduction of a real life bug |
| 1400 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1401 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1402 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1403 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1404 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1405 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1406 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1407 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1408 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1409 | D.setDependsOn(C, 1) |
| 1410 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1411 | A.addApproval('code-review', 2) |
| 1412 | B.addApproval('code-review', 2) |
| 1413 | C.addApproval('code-review', 2) |
| 1414 | D.addApproval('code-review', 2) |
| 1415 | E.addApproval('code-review', 2) |
| 1416 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1417 | |
| 1418 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | |
| 1420 | # Change object re-use in the gerrit trigger is hidden if |
| 1421 | # changes are added in quick succession; waiting makes it more |
| 1422 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1423 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1424 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1425 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1426 | self.waitUntilSettled() |
| 1427 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1428 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1429 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1430 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1431 | self.waitUntilSettled() |
| 1432 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1433 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1434 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1435 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1436 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1437 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1438 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1439 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1440 | self.waitUntilSettled() |
| 1441 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1442 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1443 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1444 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1445 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1446 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1447 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1448 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1449 | self.waitUntilSettled() |
| 1450 | |
| 1451 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1452 | |
| 1453 | # Grab pointers to the jobs we want to release before |
| 1454 | # releasing any, because list indexes may change as |
| 1455 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1456 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1457 | a.release() |
| 1458 | b.release() |
| 1459 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1460 | self.waitUntilSettled() |
| 1461 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1462 | self.launch_server.hold_jobs_in_build = False |
| 1463 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1464 | self.waitUntilSettled() |
| 1465 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1466 | self.assertEqual(A.data['status'], 'NEW') |
| 1467 | self.assertEqual(B.data['status'], 'MERGED') |
| 1468 | self.assertEqual(C.data['status'], 'MERGED') |
| 1469 | self.assertEqual(D.data['status'], 'MERGED') |
| 1470 | self.assertEqual(E.data['status'], 'MERGED') |
| 1471 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1472 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1473 | self.assertEqual(A.reported, 2) |
| 1474 | self.assertEqual(B.reported, 2) |
| 1475 | self.assertEqual(C.reported, 2) |
| 1476 | self.assertEqual(D.reported, 2) |
| 1477 | self.assertEqual(E.reported, 2) |
| 1478 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1479 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1480 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1481 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1482 | |
| 1483 | def test_merger_repack(self): |
| 1484 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1485 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1486 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1487 | A.addApproval('code-review', 2) |
| 1488 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1489 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1490 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1491 | 'SUCCESS') |
| 1492 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1493 | 'SUCCESS') |
| 1494 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1495 | 'SUCCESS') |
| 1496 | self.assertEqual(A.data['status'], 'MERGED') |
| 1497 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1498 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1499 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1500 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1501 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1502 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1503 | |
| 1504 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1505 | A.addApproval('code-review', 2) |
| 1506 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1507 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1508 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1509 | 'SUCCESS') |
| 1510 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1511 | 'SUCCESS') |
| 1512 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1513 | 'SUCCESS') |
| 1514 | self.assertEqual(A.data['status'], 'MERGED') |
| 1515 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1516 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1517 | def test_merger_repack_large_change(self): |
| 1518 | "Test that the merger works with large changes after a repack" |
| 1519 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1520 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1521 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1522 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1523 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1524 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1525 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1526 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1527 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1528 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1529 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1530 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1531 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1532 | A.addApproval('code-review', 2) |
| 1533 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1534 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1535 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1536 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1537 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1538 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1539 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1540 | 'SUCCESS') |
| 1541 | self.assertEqual(A.data['status'], 'MERGED') |
| 1542 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1543 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1544 | def test_new_patchset_dequeues_old(self): |
| 1545 | "Test that a new patchset causes the old to be dequeued" |
| 1546 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1547 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1548 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1549 | M.setMerged() |
| 1550 | |
| 1551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1552 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1553 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1554 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1555 | A.addApproval('code-review', 2) |
| 1556 | B.addApproval('code-review', 2) |
| 1557 | C.addApproval('code-review', 2) |
| 1558 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1559 | |
| 1560 | C.setDependsOn(B, 1) |
| 1561 | B.setDependsOn(A, 1) |
| 1562 | A.setDependsOn(M, 1) |
| 1563 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1564 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1565 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1566 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1567 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1568 | self.waitUntilSettled() |
| 1569 | |
| 1570 | B.addPatchset() |
| 1571 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1572 | self.waitUntilSettled() |
| 1573 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1574 | self.launch_server.hold_jobs_in_build = False |
| 1575 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1576 | self.waitUntilSettled() |
| 1577 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1578 | self.assertEqual(A.data['status'], 'MERGED') |
| 1579 | self.assertEqual(A.reported, 2) |
| 1580 | self.assertEqual(B.data['status'], 'NEW') |
| 1581 | self.assertEqual(B.reported, 2) |
| 1582 | self.assertEqual(C.data['status'], 'NEW') |
| 1583 | self.assertEqual(C.reported, 2) |
| 1584 | self.assertEqual(D.data['status'], 'MERGED') |
| 1585 | self.assertEqual(D.reported, 2) |
| 1586 | self.assertEqual(len(self.history), 9) # 3 each for A, B, D. |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1587 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1588 | def test_new_patchset_check(self): |
| 1589 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1590 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1591 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1592 | |
| 1593 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1594 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1595 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1596 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1597 | |
| 1598 | # Add two git-dependent changes |
| 1599 | B.setDependsOn(A, 1) |
| 1600 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1601 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1602 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1603 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1604 | |
| 1605 | # A live item, and a non-live/live pair |
| 1606 | items = check_pipeline.getAllItems() |
| 1607 | self.assertEqual(len(items), 3) |
| 1608 | |
| 1609 | self.assertEqual(items[0].change.number, '1') |
| 1610 | self.assertEqual(items[0].change.patchset, '1') |
| 1611 | self.assertFalse(items[0].live) |
| 1612 | |
| 1613 | self.assertEqual(items[1].change.number, '2') |
| 1614 | self.assertEqual(items[1].change.patchset, '1') |
| 1615 | self.assertTrue(items[1].live) |
| 1616 | |
| 1617 | self.assertEqual(items[2].change.number, '1') |
| 1618 | self.assertEqual(items[2].change.patchset, '1') |
| 1619 | self.assertTrue(items[2].live) |
| 1620 | |
| 1621 | # Add a new patchset to A |
| 1622 | A.addPatchset() |
| 1623 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1624 | self.waitUntilSettled() |
| 1625 | |
| 1626 | # The live copy of A,1 should be gone, but the non-live and B |
| 1627 | # should continue, and we should have a new A,2 |
| 1628 | items = check_pipeline.getAllItems() |
| 1629 | self.assertEqual(len(items), 3) |
| 1630 | |
| 1631 | self.assertEqual(items[0].change.number, '1') |
| 1632 | self.assertEqual(items[0].change.patchset, '1') |
| 1633 | self.assertFalse(items[0].live) |
| 1634 | |
| 1635 | self.assertEqual(items[1].change.number, '2') |
| 1636 | self.assertEqual(items[1].change.patchset, '1') |
| 1637 | self.assertTrue(items[1].live) |
| 1638 | |
| 1639 | self.assertEqual(items[2].change.number, '1') |
| 1640 | self.assertEqual(items[2].change.patchset, '2') |
| 1641 | self.assertTrue(items[2].live) |
| 1642 | |
| 1643 | # Add a new patchset to B |
| 1644 | B.addPatchset() |
| 1645 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1646 | self.waitUntilSettled() |
| 1647 | |
| 1648 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1649 | # but we should have a new B,2 (still based on A,1) |
| 1650 | items = check_pipeline.getAllItems() |
| 1651 | self.assertEqual(len(items), 3) |
| 1652 | |
| 1653 | self.assertEqual(items[0].change.number, '1') |
| 1654 | self.assertEqual(items[0].change.patchset, '2') |
| 1655 | self.assertTrue(items[0].live) |
| 1656 | |
| 1657 | self.assertEqual(items[1].change.number, '1') |
| 1658 | self.assertEqual(items[1].change.patchset, '1') |
| 1659 | self.assertFalse(items[1].live) |
| 1660 | |
| 1661 | self.assertEqual(items[2].change.number, '2') |
| 1662 | self.assertEqual(items[2].change.patchset, '2') |
| 1663 | self.assertTrue(items[2].live) |
| 1664 | |
| 1665 | self.builds[0].release() |
| 1666 | self.waitUntilSettled() |
| 1667 | self.builds[0].release() |
| 1668 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1669 | self.launch_server.hold_jobs_in_build = False |
| 1670 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1671 | self.waitUntilSettled() |
| 1672 | |
| 1673 | self.assertEqual(A.reported, 1) |
| 1674 | self.assertEqual(B.reported, 1) |
| 1675 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1676 | self.assertEqual(self.history[0].changes, '1,1') |
| 1677 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1678 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1679 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1680 | self.assertEqual(self.history[2].changes, '1,2') |
| 1681 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1682 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1683 | |
| 1684 | def test_abandoned_gate(self): |
| 1685 | "Test that an abandoned change is dequeued from gate" |
| 1686 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1687 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1688 | |
| 1689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1690 | A.addApproval('code-review', 2) |
| 1691 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1692 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1693 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1694 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1695 | |
| 1696 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1697 | self.waitUntilSettled() |
| 1698 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1699 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1700 | self.waitUntilSettled() |
| 1701 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1702 | self.assertBuilds([]) |
| 1703 | self.assertHistory([ |
| 1704 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1705 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1706 | self.assertEqual(A.reported, 1, |
| 1707 | "Abandoned gate change should report only start") |
| 1708 | |
| 1709 | def test_abandoned_check(self): |
| 1710 | "Test that an abandoned change is dequeued from check" |
| 1711 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1712 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1713 | |
| 1714 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1715 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1716 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1717 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1718 | |
| 1719 | # Add two git-dependent changes |
| 1720 | B.setDependsOn(A, 1) |
| 1721 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1722 | self.waitUntilSettled() |
| 1723 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1724 | self.waitUntilSettled() |
| 1725 | # A live item, and a non-live/live pair |
| 1726 | items = check_pipeline.getAllItems() |
| 1727 | self.assertEqual(len(items), 3) |
| 1728 | |
| 1729 | self.assertEqual(items[0].change.number, '1') |
| 1730 | self.assertFalse(items[0].live) |
| 1731 | |
| 1732 | self.assertEqual(items[1].change.number, '2') |
| 1733 | self.assertTrue(items[1].live) |
| 1734 | |
| 1735 | self.assertEqual(items[2].change.number, '1') |
| 1736 | self.assertTrue(items[2].live) |
| 1737 | |
| 1738 | # Abandon A |
| 1739 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1740 | self.waitUntilSettled() |
| 1741 | |
| 1742 | # The live copy of A should be gone, but the non-live and B |
| 1743 | # should continue |
| 1744 | items = check_pipeline.getAllItems() |
| 1745 | self.assertEqual(len(items), 2) |
| 1746 | |
| 1747 | self.assertEqual(items[0].change.number, '1') |
| 1748 | self.assertFalse(items[0].live) |
| 1749 | |
| 1750 | self.assertEqual(items[1].change.number, '2') |
| 1751 | self.assertTrue(items[1].live) |
| 1752 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1753 | self.launch_server.hold_jobs_in_build = False |
| 1754 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1755 | self.waitUntilSettled() |
| 1756 | |
| 1757 | self.assertEqual(len(self.history), 4) |
| 1758 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1759 | 'Build should have been aborted') |
| 1760 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1761 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1762 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1763 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1764 | def test_abandoned_not_timer(self): |
| 1765 | "Test that an abandoned change does not cancel timer jobs" |
| 1766 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1767 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1768 | |
| 1769 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1770 | self.updateConfigLayout( |
| 1771 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1772 | self.sched.reconfigure(self.config) |
| 1773 | self.registerJobs() |
| 1774 | # The pipeline triggers every second, so we should have seen |
| 1775 | # several by now. |
| 1776 | time.sleep(5) |
| 1777 | self.waitUntilSettled() |
| 1778 | # Stop queuing timer triggered jobs so that the assertions |
| 1779 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1780 | self.updateConfigLayout( |
| 1781 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1782 | self.sched.reconfigure(self.config) |
| 1783 | self.registerJobs() |
| 1784 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1785 | |
| 1786 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1787 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1788 | self.waitUntilSettled() |
| 1789 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1790 | |
| 1791 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1792 | self.waitUntilSettled() |
| 1793 | |
| 1794 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1795 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1796 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1797 | self.waitUntilSettled() |
| 1798 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1799 | def test_zuul_url_return(self): |
| 1800 | "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf" |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1801 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1802 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1803 | |
| 1804 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1805 | A.addApproval('code-review', 2) |
| 1806 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1807 | self.waitUntilSettled() |
| 1808 | |
| 1809 | self.assertEqual(len(self.builds), 1) |
| 1810 | for build in self.builds: |
| 1811 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1812 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1813 | self.launch_server.hold_jobs_in_build = False |
| 1814 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1815 | self.waitUntilSettled() |
| 1816 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1817 | def test_new_patchset_dequeues_old_on_head(self): |
| 1818 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1819 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1820 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1821 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1822 | M.setMerged() |
| 1823 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1824 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1825 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1826 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1827 | A.addApproval('code-review', 2) |
| 1828 | B.addApproval('code-review', 2) |
| 1829 | C.addApproval('code-review', 2) |
| 1830 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1831 | |
| 1832 | C.setDependsOn(B, 1) |
| 1833 | B.setDependsOn(A, 1) |
| 1834 | A.setDependsOn(M, 1) |
| 1835 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1836 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1837 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1838 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1839 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1840 | self.waitUntilSettled() |
| 1841 | |
| 1842 | A.addPatchset() |
| 1843 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1844 | self.waitUntilSettled() |
| 1845 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1846 | self.launch_server.hold_jobs_in_build = False |
| 1847 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1848 | self.waitUntilSettled() |
| 1849 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1850 | self.assertEqual(A.data['status'], 'NEW') |
| 1851 | self.assertEqual(A.reported, 2) |
| 1852 | self.assertEqual(B.data['status'], 'NEW') |
| 1853 | self.assertEqual(B.reported, 2) |
| 1854 | self.assertEqual(C.data['status'], 'NEW') |
| 1855 | self.assertEqual(C.reported, 2) |
| 1856 | self.assertEqual(D.data['status'], 'MERGED') |
| 1857 | self.assertEqual(D.reported, 2) |
| 1858 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1859 | |
| 1860 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1861 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1862 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1863 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1864 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1865 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1866 | A.addApproval('code-review', 2) |
| 1867 | B.addApproval('code-review', 2) |
| 1868 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1869 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1870 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1871 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1872 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1873 | self.waitUntilSettled() |
| 1874 | |
| 1875 | B.addPatchset() |
| 1876 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1877 | self.waitUntilSettled() |
| 1878 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1879 | self.launch_server.hold_jobs_in_build = False |
| 1880 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1881 | self.waitUntilSettled() |
| 1882 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1883 | self.assertEqual(A.data['status'], 'MERGED') |
| 1884 | self.assertEqual(A.reported, 2) |
| 1885 | self.assertEqual(B.data['status'], 'NEW') |
| 1886 | self.assertEqual(B.reported, 2) |
| 1887 | self.assertEqual(C.data['status'], 'MERGED') |
| 1888 | self.assertEqual(C.reported, 2) |
| 1889 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1890 | |
| 1891 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1892 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1893 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1894 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1895 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1896 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1897 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1898 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1899 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1900 | self.waitUntilSettled() |
| 1901 | |
| 1902 | B.addPatchset() |
| 1903 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1904 | self.waitUntilSettled() |
| 1905 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1906 | self.launch_server.hold_jobs_in_build = False |
| 1907 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1908 | self.waitUntilSettled() |
| 1909 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1910 | self.assertEqual(A.data['status'], 'NEW') |
| 1911 | self.assertEqual(A.reported, 1) |
| 1912 | self.assertEqual(B.data['status'], 'NEW') |
| 1913 | self.assertEqual(B.reported, 1) |
| 1914 | self.assertEqual(C.data['status'], 'NEW') |
| 1915 | self.assertEqual(C.reported, 1) |
| 1916 | self.assertEqual(len(self.history), 10) |
| 1917 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1918 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1919 | def test_noop_job(self): |
| 1920 | "Test that the internal noop job works" |
| 1921 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1922 | A.addApproval('code-review', 2) |
| 1923 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1924 | self.waitUntilSettled() |
| 1925 | |
| 1926 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1927 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1928 | self.assertEqual(len(self.history), 0) |
| 1929 | self.assertEqual(A.data['status'], 'MERGED') |
| 1930 | self.assertEqual(A.reported, 2) |
| 1931 | |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1932 | def test_no_job_project(self): |
| 1933 | "Test that reports with no jobs don't get sent" |
| 1934 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1935 | 'master', 'A') |
| 1936 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1937 | self.waitUntilSettled() |
| 1938 | |
| 1939 | # Change wasn't reported to |
| 1940 | self.assertEqual(A.reported, False) |
| 1941 | |
| 1942 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1943 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1944 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1945 | items = check_pipeline.getAllItems() |
| 1946 | self.assertEqual(len(items), 0) |
| 1947 | |
| 1948 | self.assertEqual(len(self.history), 0) |
| 1949 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1950 | def test_zuul_refs(self): |
| 1951 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1952 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1953 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1954 | M1.setMerged() |
| 1955 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1956 | M2.setMerged() |
| 1957 | |
| 1958 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1959 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1960 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1961 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1962 | A.addApproval('code-review', 2) |
| 1963 | B.addApproval('code-review', 2) |
| 1964 | C.addApproval('code-review', 2) |
| 1965 | D.addApproval('code-review', 2) |
| 1966 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1967 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1968 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1969 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1970 | |
| 1971 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1972 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1973 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1974 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1975 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1976 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1977 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1978 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1979 | self.waitUntilSettled() |
| 1980 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1981 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1982 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1983 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1984 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1985 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1986 | a_build = x |
| 1987 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1988 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1989 | b_build = x |
| 1990 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1991 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1992 | c_build = x |
| 1993 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1994 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1995 | d_build = x |
| 1996 | if a_build and b_build and c_build and d_build: |
| 1997 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1998 | |
| 1999 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2000 | self.assertIsNotNone(a_zref) |
| 2001 | self.assertIsNotNone(b_zref) |
| 2002 | self.assertIsNotNone(c_zref) |
| 2003 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2004 | |
| 2005 | # And they should all be different |
| 2006 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2007 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2008 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2009 | # should have a, not b, and should not be in project2 |
| 2010 | self.assertTrue(a_build.hasChanges(A)) |
| 2011 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2012 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2013 | # should have a and b, and should not be in project2 |
| 2014 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2015 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2016 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2017 | # should have a and b in 1, c in 2 |
| 2018 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2019 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2020 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2021 | # should have a and b in 1, c and d in 2 |
| 2022 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2023 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2024 | self.launch_server.hold_jobs_in_build = False |
| 2025 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2026 | self.waitUntilSettled() |
| 2027 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2028 | self.assertEqual(A.data['status'], 'MERGED') |
| 2029 | self.assertEqual(A.reported, 2) |
| 2030 | self.assertEqual(B.data['status'], 'MERGED') |
| 2031 | self.assertEqual(B.reported, 2) |
| 2032 | self.assertEqual(C.data['status'], 'MERGED') |
| 2033 | self.assertEqual(C.reported, 2) |
| 2034 | self.assertEqual(D.data['status'], 'MERGED') |
| 2035 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2036 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2037 | def test_rerun_on_error(self): |
| 2038 | "Test that if a worker fails to run a job, it is run again" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2039 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2040 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2041 | A.addApproval('code-review', 2) |
| 2042 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2043 | self.waitUntilSettled() |
| 2044 | |
| 2045 | self.builds[0].run_error = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2046 | self.launch_server.hold_jobs_in_build = False |
| 2047 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2048 | self.waitUntilSettled() |
| 2049 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2050 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2051 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2052 | def test_statsd(self): |
| 2053 | "Test each of the statsd methods used in the scheduler" |
| 2054 | import extras |
| 2055 | statsd = extras.try_import('statsd.statsd') |
| 2056 | statsd.incr('test-incr') |
| 2057 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2058 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2059 | self.assertReportedStat('test-incr', '1|c') |
| 2060 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2061 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2062 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2063 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2064 | def test_stuck_job_cleanup(self): |
| 2065 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2066 | # This job won't be registered at startup because it is not in |
| 2067 | # the standard layout, but we need it to already be registerd |
| 2068 | # for when we reconfigure, as that is when Zuul will attempt |
| 2069 | # to run the new job. |
| 2070 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2071 | self.gearman_server.hold_jobs_in_queue = True |
| 2072 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2073 | A.addApproval('code-review', 2) |
| 2074 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2075 | self.waitUntilSettled() |
| 2076 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2077 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2078 | self.updateConfigLayout( |
| 2079 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2080 | self.sched.reconfigure(self.config) |
| 2081 | self.waitUntilSettled() |
| 2082 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2083 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2084 | self.waitUntilSettled() |
| 2085 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2086 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2087 | |
| 2088 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2089 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2090 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2091 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2092 | def test_file_head(self): |
| 2093 | # This is a regression test for an observed bug. A change |
| 2094 | # with a file named "HEAD" in the root directory of the repo |
| 2095 | # was processed by a merger. It then was unable to reset the |
| 2096 | # repo because of: |
| 2097 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2098 | # with exit code 128 |
| 2099 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2100 | # and filename |
| 2101 | # Use '--' to separate filenames from revisions' |
| 2102 | |
| 2103 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2104 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2105 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2106 | |
| 2107 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2108 | self.waitUntilSettled() |
| 2109 | |
| 2110 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2111 | self.waitUntilSettled() |
| 2112 | |
| 2113 | self.assertIn('Build succeeded', A.messages[0]) |
| 2114 | self.assertIn('Build succeeded', B.messages[0]) |
| 2115 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2116 | @skip("Disabled for early v3 development") |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2117 | def test_file_jobs(self): |
| 2118 | "Test that file jobs run only when appropriate" |
| 2119 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2120 | A.addPatchset(['pip-requires']) |
| 2121 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2122 | A.addApproval('code-review', 2) |
| 2123 | B.addApproval('code-review', 2) |
| 2124 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2125 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2126 | self.waitUntilSettled() |
| 2127 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2128 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2129 | if x.name == 'project-testfile'] |
| 2130 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2131 | self.assertEqual(len(testfile_jobs), 1) |
| 2132 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2133 | self.assertEqual(A.data['status'], 'MERGED') |
| 2134 | self.assertEqual(A.reported, 2) |
| 2135 | self.assertEqual(B.data['status'], 'MERGED') |
| 2136 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2137 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2138 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2139 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2140 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2141 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2142 | |
| 2143 | if should_skip: |
| 2144 | files = {'ignoreme': 'ignored\n'} |
| 2145 | else: |
| 2146 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2147 | |
| 2148 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2149 | 'master', |
| 2150 | 'test irrelevant-files', |
| 2151 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2152 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2153 | self.waitUntilSettled() |
| 2154 | |
| 2155 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2156 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2157 | |
| 2158 | if should_skip: |
| 2159 | self.assertEqual([], tested_change_ids) |
| 2160 | else: |
| 2161 | self.assertIn(change.data['number'], tested_change_ids) |
| 2162 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2163 | def test_irrelevant_files_match_skips_job(self): |
| 2164 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2165 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2166 | def test_irrelevant_files_no_match_runs_job(self): |
| 2167 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2168 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2169 | def test_inherited_jobs_keep_matchers(self): |
| 2170 | self.updateConfigLayout('layout-inheritance') |
| 2171 | self.sched.reconfigure(self.config) |
| 2172 | |
| 2173 | files = {'ignoreme': 'ignored\n'} |
| 2174 | |
| 2175 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2176 | 'master', |
| 2177 | 'test irrelevant-files', |
| 2178 | files=files) |
| 2179 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2180 | self.waitUntilSettled() |
| 2181 | |
| 2182 | run_jobs = set([build.name for build in self.history]) |
| 2183 | |
| 2184 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2185 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2186 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2187 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2188 | def test_test_config(self): |
| 2189 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2190 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2191 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2192 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2193 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2194 | def test_queue_names(self): |
| 2195 | "Test shared change queue names" |
| 2196 | project1 = self.sched.layout.projects['org/project1'] |
| 2197 | project2 = self.sched.layout.projects['org/project2'] |
| 2198 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2199 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2200 | self.assertEqual(q1.name, 'integration') |
| 2201 | self.assertEqual(q2.name, 'integration') |
| 2202 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2203 | self.updateConfigLayout( |
| 2204 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2205 | with testtools.ExpectedException( |
| 2206 | Exception, "More than one name assigned to change queue"): |
| 2207 | self.sched.reconfigure(self.config) |
| 2208 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2209 | def test_queue_precedence(self): |
| 2210 | "Test that queue precedence works" |
| 2211 | |
| 2212 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2213 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2214 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2215 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2216 | A.addApproval('code-review', 2) |
| 2217 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2218 | |
| 2219 | self.waitUntilSettled() |
| 2220 | self.gearman_server.hold_jobs_in_queue = False |
| 2221 | self.gearman_server.release() |
| 2222 | self.waitUntilSettled() |
| 2223 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2224 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2225 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2226 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2227 | self.waitUntilSettled() |
| 2228 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2229 | self.log.debug(self.history) |
| 2230 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2231 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2232 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2233 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2234 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2235 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2236 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2237 | @skip("Disabled for early v3 development") |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2238 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2239 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2240 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2241 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2242 | A.addApproval('code-review', 2) |
| 2243 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2244 | self.waitUntilSettled() |
| 2245 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2246 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2247 | self.waitUntilSettled() |
| 2248 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2249 | port = self.webapp.server.socket.getsockname()[1] |
| 2250 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2251 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2252 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2253 | headers = f.info() |
| 2254 | self.assertIn('Content-Length', headers) |
| 2255 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2256 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2257 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2258 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2259 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2260 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2261 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2262 | data = f.read() |
| 2263 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2264 | self.launch_server.hold_jobs_in_build = False |
| 2265 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2266 | self.waitUntilSettled() |
| 2267 | |
| 2268 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2269 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2270 | for p in data['pipelines']: |
| 2271 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2272 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2273 | self.assertEqual(q['window'], 20) |
| 2274 | else: |
| 2275 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2276 | for head in q['heads']: |
| 2277 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2278 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2279 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2280 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2281 | status_jobs.append(job) |
| 2282 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2283 | self.assertEqual('https://server/job/project-merge/0/', |
| 2284 | status_jobs[0]['url']) |
| 2285 | self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0', |
| 2286 | status_jobs[0]['report_url']) |
| 2287 | |
| 2288 | self.assertEqual('project-test1', status_jobs[1]['name']) |
| 2289 | self.assertEqual('https://server/job/project-test1/1/', |
| 2290 | status_jobs[1]['url']) |
| 2291 | self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1', |
| 2292 | status_jobs[1]['report_url']) |
| 2293 | |
| 2294 | self.assertEqual('project-test2', status_jobs[2]['name']) |
| 2295 | self.assertEqual('https://server/job/project-test2/2/', |
| 2296 | status_jobs[2]['url']) |
| 2297 | self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2', |
| 2298 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2299 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2300 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2301 | def test_merging_queues(self): |
| 2302 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2303 | self.updateConfigLayout( |
| 2304 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2305 | self.sched.reconfigure(self.config) |
| 2306 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2307 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2308 | @skip("Disabled for early v3 development") |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2309 | def test_mutex(self): |
| 2310 | "Test job mutexes" |
| 2311 | self.config.set('zuul', 'layout_config', |
| 2312 | 'tests/fixtures/layout-mutex.yaml') |
| 2313 | self.sched.reconfigure(self.config) |
| 2314 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2315 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2316 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2317 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2318 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2319 | |
| 2320 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2321 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2322 | self.waitUntilSettled() |
| 2323 | self.assertEqual(len(self.builds), 3) |
| 2324 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2325 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2326 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2327 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2328 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2329 | self.waitUntilSettled() |
| 2330 | |
| 2331 | self.assertEqual(len(self.builds), 3) |
| 2332 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2333 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2334 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2335 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2336 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2337 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2338 | self.waitUntilSettled() |
| 2339 | |
| 2340 | self.assertEqual(len(self.builds), 3) |
| 2341 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2342 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2343 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2344 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2345 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2346 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2347 | self.waitUntilSettled() |
| 2348 | |
| 2349 | self.assertEqual(len(self.builds), 3) |
| 2350 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2351 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2352 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2353 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2354 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2355 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2356 | self.waitUntilSettled() |
| 2357 | |
| 2358 | self.assertEqual(len(self.builds), 2) |
| 2359 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2360 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2361 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2362 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2363 | self.launch_server.hold_jobs_in_build = False |
| 2364 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2365 | |
| 2366 | self.waitUntilSettled() |
| 2367 | self.assertEqual(len(self.builds), 0) |
| 2368 | |
| 2369 | self.assertEqual(A.reported, 1) |
| 2370 | self.assertEqual(B.reported, 1) |
| 2371 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2372 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2373 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2374 | def test_node_label(self): |
| 2375 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2376 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2377 | |
| 2378 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2379 | A.addApproval('code-review', 2) |
| 2380 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2381 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2382 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2383 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2384 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2385 | 'debian') |
| 2386 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2387 | |
| 2388 | def test_live_reconfiguration(self): |
| 2389 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2390 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2391 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2392 | A.addApproval('code-review', 2) |
| 2393 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2394 | self.waitUntilSettled() |
| 2395 | |
| 2396 | self.sched.reconfigure(self.config) |
| 2397 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2398 | self.launch_server.hold_jobs_in_build = False |
| 2399 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2400 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2401 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2402 | 'SUCCESS') |
| 2403 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2404 | 'SUCCESS') |
| 2405 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2406 | 'SUCCESS') |
| 2407 | self.assertEqual(A.data['status'], 'MERGED') |
| 2408 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2409 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2410 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2411 | def test_live_reconfiguration_merge_conflict(self): |
| 2412 | # A real-world bug: a change in a gate queue has a merge |
| 2413 | # conflict and a job is added to its project while it's |
| 2414 | # sitting in the queue. The job gets added to the change and |
| 2415 | # enqueued and the change gets stuck. |
| 2416 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2417 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2418 | |
| 2419 | # This change is fine. It's here to stop the queue long |
| 2420 | # enough for the next change to be subject to the |
| 2421 | # reconfiguration, as well as to provide a conflict for the |
| 2422 | # next change. This change will succeed and merge. |
| 2423 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2424 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2425 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2426 | |
| 2427 | # This change will be in merge conflict. During the |
| 2428 | # reconfiguration, we will add a job. We want to make sure |
| 2429 | # that doesn't cause it to get stuck. |
| 2430 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2431 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2432 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2433 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2434 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2435 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2436 | |
| 2437 | self.waitUntilSettled() |
| 2438 | |
| 2439 | # No jobs have run yet |
| 2440 | self.assertEqual(A.data['status'], 'NEW') |
| 2441 | self.assertEqual(A.reported, 1) |
| 2442 | self.assertEqual(B.data['status'], 'NEW') |
| 2443 | self.assertEqual(B.reported, 1) |
| 2444 | self.assertEqual(len(self.history), 0) |
| 2445 | |
| 2446 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2447 | self.updateConfigLayout( |
| 2448 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2449 | self.sched.reconfigure(self.config) |
| 2450 | self.waitUntilSettled() |
| 2451 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2452 | self.launch_server.hold_jobs_in_build = False |
| 2453 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2454 | self.waitUntilSettled() |
| 2455 | |
| 2456 | self.assertEqual(A.data['status'], 'MERGED') |
| 2457 | self.assertEqual(A.reported, 2) |
| 2458 | self.assertEqual(B.data['status'], 'NEW') |
| 2459 | self.assertEqual(B.reported, 2) |
| 2460 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2461 | 'SUCCESS') |
| 2462 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2463 | 'SUCCESS') |
| 2464 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2465 | 'SUCCESS') |
| 2466 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2467 | 'SUCCESS') |
| 2468 | self.assertEqual(len(self.history), 4) |
| 2469 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2470 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2471 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2472 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2473 | # that tests a job added to a job tree with a failed root does |
| 2474 | # not run. |
| 2475 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2476 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2477 | |
| 2478 | # This change is fine. It's here to stop the queue long |
| 2479 | # enough for the next change to be subject to the |
| 2480 | # reconfiguration. This change will succeed and merge. |
| 2481 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2482 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2483 | A.addApproval('code-review', 2) |
| 2484 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2485 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2486 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2487 | self.waitUntilSettled() |
| 2488 | |
| 2489 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2490 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2491 | B.addApproval('code-review', 2) |
| 2492 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2493 | self.waitUntilSettled() |
| 2494 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2495 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2496 | self.waitUntilSettled() |
| 2497 | |
| 2498 | # Both -merge jobs have run, but no others. |
| 2499 | self.assertEqual(A.data['status'], 'NEW') |
| 2500 | self.assertEqual(A.reported, 1) |
| 2501 | self.assertEqual(B.data['status'], 'NEW') |
| 2502 | self.assertEqual(B.reported, 1) |
| 2503 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2504 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2505 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2506 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2507 | self.assertEqual(len(self.history), 2) |
| 2508 | |
| 2509 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2510 | self.updateConfigLayout( |
| 2511 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2512 | self.sched.reconfigure(self.config) |
| 2513 | self.waitUntilSettled() |
| 2514 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2515 | self.launch_server.hold_jobs_in_build = False |
| 2516 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2517 | self.waitUntilSettled() |
| 2518 | |
| 2519 | self.assertEqual(A.data['status'], 'MERGED') |
| 2520 | self.assertEqual(A.reported, 2) |
| 2521 | self.assertEqual(B.data['status'], 'NEW') |
| 2522 | self.assertEqual(B.reported, 2) |
| 2523 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2524 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2525 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2526 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2527 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2528 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2529 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2530 | self.assertEqual(len(self.history), 5) |
| 2531 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2532 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2533 | def test_live_reconfiguration_failed_job(self): |
| 2534 | # Test that a change with a removed failing job does not |
| 2535 | # disrupt reconfiguration. If a change has a failed job and |
| 2536 | # that job is removed during a reconfiguration, we observed a |
| 2537 | # bug where the code to re-set build statuses would run on |
| 2538 | # that build and raise an exception because the job no longer |
| 2539 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2540 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2541 | |
| 2542 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2543 | |
| 2544 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2545 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2546 | |
| 2547 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2548 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2549 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2550 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2551 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2552 | self.waitUntilSettled() |
| 2553 | |
| 2554 | self.assertEqual(A.data['status'], 'NEW') |
| 2555 | self.assertEqual(A.reported, 0) |
| 2556 | |
| 2557 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2558 | 'SUCCESS') |
| 2559 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2560 | 'FAILURE') |
| 2561 | self.assertEqual(len(self.history), 2) |
| 2562 | |
| 2563 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2564 | self.updateConfigLayout( |
| 2565 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2566 | self.sched.reconfigure(self.config) |
| 2567 | self.waitUntilSettled() |
| 2568 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2569 | self.launch_server.hold_jobs_in_build = False |
| 2570 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2571 | self.waitUntilSettled() |
| 2572 | |
| 2573 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2574 | 'SUCCESS') |
| 2575 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2576 | 'SUCCESS') |
| 2577 | self.assertEqual(len(self.history), 4) |
| 2578 | |
| 2579 | self.assertEqual(A.data['status'], 'NEW') |
| 2580 | self.assertEqual(A.reported, 1) |
| 2581 | self.assertIn('Build succeeded', A.messages[0]) |
| 2582 | # Ensure the removed job was not included in the report. |
| 2583 | self.assertNotIn('project-test1', A.messages[0]) |
| 2584 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2585 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2586 | def test_live_reconfiguration_shared_queue(self): |
| 2587 | # Test that a change with a failing job which was removed from |
| 2588 | # this project but otherwise still exists in the system does |
| 2589 | # not disrupt reconfiguration. |
| 2590 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2591 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2592 | |
| 2593 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2594 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2595 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2596 | |
| 2597 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2598 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2599 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2600 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2601 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2602 | self.waitUntilSettled() |
| 2603 | |
| 2604 | self.assertEqual(A.data['status'], 'NEW') |
| 2605 | self.assertEqual(A.reported, 0) |
| 2606 | |
| 2607 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2608 | 'SUCCESS') |
| 2609 | self.assertEqual(self.getJobFromHistory( |
| 2610 | 'project1-project2-integration').result, 'FAILURE') |
| 2611 | self.assertEqual(len(self.history), 2) |
| 2612 | |
| 2613 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2614 | self.updateConfigLayout( |
| 2615 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2616 | self.sched.reconfigure(self.config) |
| 2617 | self.waitUntilSettled() |
| 2618 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2619 | self.launch_server.hold_jobs_in_build = False |
| 2620 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2621 | self.waitUntilSettled() |
| 2622 | |
| 2623 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2624 | 'SUCCESS') |
| 2625 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2626 | 'SUCCESS') |
| 2627 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2628 | 'SUCCESS') |
| 2629 | self.assertEqual(self.getJobFromHistory( |
| 2630 | 'project1-project2-integration').result, 'FAILURE') |
| 2631 | self.assertEqual(len(self.history), 4) |
| 2632 | |
| 2633 | self.assertEqual(A.data['status'], 'NEW') |
| 2634 | self.assertEqual(A.reported, 1) |
| 2635 | self.assertIn('Build succeeded', A.messages[0]) |
| 2636 | # Ensure the removed job was not included in the report. |
| 2637 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2638 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2639 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2640 | def test_double_live_reconfiguration_shared_queue(self): |
| 2641 | # This was a real-world regression. A change is added to |
| 2642 | # gate; a reconfigure happens, a second change which depends |
| 2643 | # on the first is added, and a second reconfiguration happens. |
| 2644 | # Ensure that both changes merge. |
| 2645 | |
| 2646 | # A failure may indicate incorrect caching or cleaning up of |
| 2647 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2648 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2649 | |
| 2650 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2651 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2652 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2653 | A.addApproval('code-review', 2) |
| 2654 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2655 | |
| 2656 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2657 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2658 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2659 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2660 | self.waitUntilSettled() |
| 2661 | |
| 2662 | # Reconfigure (with only one change in the pipeline). |
| 2663 | self.sched.reconfigure(self.config) |
| 2664 | self.waitUntilSettled() |
| 2665 | |
| 2666 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2667 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2668 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2669 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2670 | self.waitUntilSettled() |
| 2671 | |
| 2672 | # Reconfigure (with both in the pipeline). |
| 2673 | self.sched.reconfigure(self.config) |
| 2674 | self.waitUntilSettled() |
| 2675 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2676 | self.launch_server.hold_jobs_in_build = False |
| 2677 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2678 | self.waitUntilSettled() |
| 2679 | |
| 2680 | self.assertEqual(len(self.history), 8) |
| 2681 | |
| 2682 | self.assertEqual(A.data['status'], 'MERGED') |
| 2683 | self.assertEqual(A.reported, 2) |
| 2684 | self.assertEqual(B.data['status'], 'MERGED') |
| 2685 | self.assertEqual(B.reported, 2) |
| 2686 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2687 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2688 | def test_live_reconfiguration_del_project(self): |
| 2689 | # Test project deletion from layout |
| 2690 | # while changes are enqueued |
| 2691 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2692 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2693 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2694 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2695 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2696 | |
| 2697 | # A Depends-On: B |
| 2698 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2699 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2700 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2701 | |
| 2702 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2703 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2704 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2705 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2706 | self.waitUntilSettled() |
| 2707 | self.assertEqual(len(self.builds), 5) |
| 2708 | |
| 2709 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2710 | self.updateConfigLayout( |
| 2711 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2712 | self.sched.reconfigure(self.config) |
| 2713 | self.waitUntilSettled() |
| 2714 | |
| 2715 | # Builds for C aborted, builds for A succeed, |
| 2716 | # and have change B applied ahead |
| 2717 | job_c = self.getJobFromHistory('project1-test1') |
| 2718 | self.assertEqual(job_c.changes, '3,1') |
| 2719 | self.assertEqual(job_c.result, 'ABORTED') |
| 2720 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2721 | self.launch_server.hold_jobs_in_build = False |
| 2722 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2723 | self.waitUntilSettled() |
| 2724 | |
| 2725 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2726 | '2,1 1,1') |
| 2727 | |
| 2728 | self.assertEqual(A.data['status'], 'NEW') |
| 2729 | self.assertEqual(B.data['status'], 'NEW') |
| 2730 | self.assertEqual(C.data['status'], 'NEW') |
| 2731 | self.assertEqual(A.reported, 1) |
| 2732 | self.assertEqual(B.reported, 0) |
| 2733 | self.assertEqual(C.reported, 0) |
| 2734 | |
| 2735 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2736 | self.assertIn('Build succeeded', A.messages[0]) |
| 2737 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2738 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2739 | def test_live_reconfiguration_functions(self): |
| 2740 | "Test live reconfiguration with a custom function" |
| 2741 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2742 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2743 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2744 | A.addApproval('code-review', 2) |
| 2745 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2746 | self.waitUntilSettled() |
| 2747 | |
| 2748 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2749 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2750 | 'debian') |
| 2751 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2752 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2753 | self.updateConfigLayout( |
| 2754 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2755 | self.sched.reconfigure(self.config) |
| 2756 | self.worker.build_history = [] |
| 2757 | |
| 2758 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2759 | B.addApproval('code-review', 2) |
| 2760 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2761 | self.waitUntilSettled() |
| 2762 | |
| 2763 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2764 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2765 | 'wheezy') |
| 2766 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2767 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2768 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2769 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2770 | self.updateConfigLayout( |
| 2771 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2772 | self.sched.reconfigure(self.config) |
| 2773 | |
| 2774 | self.init_repo("org/new-project") |
| 2775 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2776 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2777 | A.addApproval('code-review', 2) |
| 2778 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2779 | self.waitUntilSettled() |
| 2780 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2781 | 'SUCCESS') |
| 2782 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2783 | 'SUCCESS') |
| 2784 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2785 | 'SUCCESS') |
| 2786 | self.assertEqual(A.data['status'], 'MERGED') |
| 2787 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2788 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2789 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2790 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2791 | self.sched.reconfigure(self.config) |
| 2792 | |
| 2793 | self.init_repo("org/delete-project") |
| 2794 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2795 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2796 | A.addApproval('code-review', 2) |
| 2797 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2798 | self.waitUntilSettled() |
| 2799 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2800 | 'SUCCESS') |
| 2801 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2802 | 'SUCCESS') |
| 2803 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2804 | 'SUCCESS') |
| 2805 | self.assertEqual(A.data['status'], 'MERGED') |
| 2806 | self.assertEqual(A.reported, 2) |
| 2807 | |
| 2808 | # Delete org/new-project zuul repo. Should be recloned. |
| 2809 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2810 | |
| 2811 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2812 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2813 | B.addApproval('code-review', 2) |
| 2814 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2815 | self.waitUntilSettled() |
| 2816 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2817 | 'SUCCESS') |
| 2818 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2819 | 'SUCCESS') |
| 2820 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2821 | 'SUCCESS') |
| 2822 | self.assertEqual(B.data['status'], 'MERGED') |
| 2823 | self.assertEqual(B.reported, 2) |
| 2824 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2825 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2826 | def test_tags(self): |
| 2827 | "Test job tags" |
| 2828 | self.config.set('zuul', 'layout_config', |
| 2829 | 'tests/fixtures/layout-tags.yaml') |
| 2830 | self.sched.reconfigure(self.config) |
| 2831 | |
| 2832 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2833 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2834 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2835 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2836 | self.waitUntilSettled() |
| 2837 | |
| 2838 | results = {'project1-merge': 'extratag merge project1', |
| 2839 | 'project2-merge': 'merge'} |
| 2840 | |
| 2841 | for build in self.history: |
| 2842 | self.assertEqual(results.get(build.name, ''), |
| 2843 | build.parameters.get('BUILD_TAGS')) |
| 2844 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2845 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2846 | def test_timer(self): |
| 2847 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2848 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2849 | self.updateConfigLayout( |
| 2850 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2851 | self.sched.reconfigure(self.config) |
| 2852 | self.registerJobs() |
| 2853 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2854 | # The pipeline triggers every second, so we should have seen |
| 2855 | # several by now. |
| 2856 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2857 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2858 | |
| 2859 | self.assertEqual(len(self.builds), 2) |
| 2860 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2861 | port = self.webapp.server.socket.getsockname()[1] |
| 2862 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2863 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2864 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2865 | data = f.read() |
| 2866 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2867 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2868 | # Stop queuing timer triggered jobs so that the assertions |
| 2869 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2870 | self.updateConfigLayout( |
| 2871 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2872 | self.sched.reconfigure(self.config) |
| 2873 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2874 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2875 | self.waitUntilSettled() |
| 2876 | |
| 2877 | self.assertEqual(self.getJobFromHistory( |
| 2878 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2879 | self.assertEqual(self.getJobFromHistory( |
| 2880 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2881 | |
| 2882 | data = json.loads(data) |
| 2883 | status_jobs = set() |
| 2884 | for p in data['pipelines']: |
| 2885 | for q in p['change_queues']: |
| 2886 | for head in q['heads']: |
| 2887 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2888 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2889 | for job in change['jobs']: |
| 2890 | status_jobs.add(job['name']) |
| 2891 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2892 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2893 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2894 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2895 | def test_idle(self): |
| 2896 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2897 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2898 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2899 | for x in range(1, 3): |
| 2900 | # Test that timer triggers periodic jobs even across |
| 2901 | # layout config reloads. |
| 2902 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2903 | self.updateConfigLayout( |
| 2904 | 'tests/fixtures/layout-idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2905 | self.sched.reconfigure(self.config) |
| 2906 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2907 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2908 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2909 | # The pipeline triggers every second, so we should have seen |
| 2910 | # several by now. |
| 2911 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2912 | |
| 2913 | # Stop queuing timer triggered jobs so that the assertions |
| 2914 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2915 | self.updateConfigLayout( |
| 2916 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2917 | self.sched.reconfigure(self.config) |
| 2918 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2919 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2920 | |
| 2921 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2922 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2923 | self.waitUntilSettled() |
| 2924 | self.assertEqual(len(self.builds), 0) |
| 2925 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2926 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2927 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2928 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2929 | self.sched.reconfigure(self.config) |
| 2930 | |
| 2931 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2932 | self.waitUntilSettled() |
| 2933 | |
| 2934 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2935 | self.waitUntilSettled() |
| 2936 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2937 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2938 | |
| 2939 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2940 | # work on the knowledge of what the first message should be as |
| 2941 | # it is only configured to go to SMTP. |
| 2942 | |
| 2943 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2944 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2945 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2946 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2947 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2948 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2949 | |
| 2950 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2951 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2952 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2953 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2954 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2955 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2956 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2957 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2958 | def test_timer_smtp(self): |
| 2959 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2960 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2961 | self.updateConfigLayout( |
| 2962 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2963 | self.sched.reconfigure(self.config) |
| 2964 | self.registerJobs() |
| 2965 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2966 | # The pipeline triggers every second, so we should have seen |
| 2967 | # several by now. |
| 2968 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2969 | self.waitUntilSettled() |
| 2970 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2971 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2972 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2973 | self.waitUntilSettled() |
| 2974 | self.assertEqual(len(self.history), 2) |
| 2975 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2976 | self.assertEqual(self.getJobFromHistory( |
| 2977 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2978 | self.assertEqual(self.getJobFromHistory( |
| 2979 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2980 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2981 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2982 | |
| 2983 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2984 | # work on the knowledge of what the first message should be as |
| 2985 | # it is only configured to go to SMTP. |
| 2986 | |
| 2987 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2988 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2989 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2990 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2991 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2992 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2993 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2994 | # Stop queuing timer triggered jobs and let any that may have |
| 2995 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2996 | self.updateConfigLayout( |
| 2997 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2998 | self.sched.reconfigure(self.config) |
| 2999 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3000 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3001 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3002 | self.waitUntilSettled() |
| 3003 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3004 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3005 | "Test that the RPC client can enqueue a change" |
| 3006 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3007 | A.addApproval('code-review', 2) |
| 3008 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3009 | |
| 3010 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3011 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3012 | r = client.enqueue(tenant='tenant-one', |
| 3013 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3014 | project='org/project', |
| 3015 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3016 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3017 | self.waitUntilSettled() |
| 3018 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3019 | 'SUCCESS') |
| 3020 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3021 | 'SUCCESS') |
| 3022 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3023 | 'SUCCESS') |
| 3024 | self.assertEqual(A.data['status'], 'MERGED') |
| 3025 | self.assertEqual(A.reported, 2) |
| 3026 | self.assertEqual(r, True) |
| 3027 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3028 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3029 | def test_client_enqueue_ref(self): |
| 3030 | "Test that the RPC client can enqueue a ref" |
| 3031 | |
| 3032 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3033 | self.gearman_server.port) |
| 3034 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3035 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3036 | pipeline='post', |
| 3037 | project='org/project', |
| 3038 | trigger='gerrit', |
| 3039 | ref='master', |
| 3040 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3041 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3042 | self.waitUntilSettled() |
| 3043 | job_names = [x.name for x in self.history] |
| 3044 | self.assertEqual(len(self.history), 1) |
| 3045 | self.assertIn('project-post', job_names) |
| 3046 | self.assertEqual(r, True) |
| 3047 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3048 | def test_client_enqueue_negative(self): |
| 3049 | "Test that the RPC client returns errors" |
| 3050 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3051 | self.gearman_server.port) |
| 3052 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3053 | "Invalid tenant"): |
| 3054 | r = client.enqueue(tenant='tenant-foo', |
| 3055 | pipeline='gate', |
| 3056 | project='org/project', |
| 3057 | trigger='gerrit', |
| 3058 | change='1,1') |
| 3059 | client.shutdown() |
| 3060 | self.assertEqual(r, False) |
| 3061 | |
| 3062 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3063 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3064 | r = client.enqueue(tenant='tenant-one', |
| 3065 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3066 | project='project-does-not-exist', |
| 3067 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3068 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3069 | client.shutdown() |
| 3070 | self.assertEqual(r, False) |
| 3071 | |
| 3072 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3073 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3074 | r = client.enqueue(tenant='tenant-one', |
| 3075 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3076 | project='org/project', |
| 3077 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3078 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3079 | client.shutdown() |
| 3080 | self.assertEqual(r, False) |
| 3081 | |
| 3082 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3083 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3084 | r = client.enqueue(tenant='tenant-one', |
| 3085 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3086 | project='org/project', |
| 3087 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3088 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3089 | client.shutdown() |
| 3090 | self.assertEqual(r, False) |
| 3091 | |
| 3092 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3093 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3094 | r = client.enqueue(tenant='tenant-one', |
| 3095 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3096 | project='org/project', |
| 3097 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3098 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3099 | client.shutdown() |
| 3100 | self.assertEqual(r, False) |
| 3101 | |
| 3102 | self.waitUntilSettled() |
| 3103 | self.assertEqual(len(self.history), 0) |
| 3104 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3105 | |
| 3106 | def test_client_promote(self): |
| 3107 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3108 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3110 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3111 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3112 | A.addApproval('code-review', 2) |
| 3113 | B.addApproval('code-review', 2) |
| 3114 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3115 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3116 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3117 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3118 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3119 | |
| 3120 | self.waitUntilSettled() |
| 3121 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3122 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3123 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3124 | enqueue_times = {} |
| 3125 | for item in items: |
| 3126 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3127 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3128 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3129 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3130 | r = client.promote(tenant='tenant-one', |
| 3131 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3132 | change_ids=['2,1', '3,1']) |
| 3133 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3134 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3135 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3136 | for item in items: |
| 3137 | self.assertEqual( |
| 3138 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3139 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3140 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3141 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3142 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3143 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3144 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3145 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3146 | self.waitUntilSettled() |
| 3147 | |
| 3148 | self.assertEqual(len(self.builds), 6) |
| 3149 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3150 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3151 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3152 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3153 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3154 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3155 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3156 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3157 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3158 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3159 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3160 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3161 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3162 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3163 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3164 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3165 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3166 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3167 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3168 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3169 | self.waitUntilSettled() |
| 3170 | |
| 3171 | self.assertEqual(A.data['status'], 'MERGED') |
| 3172 | self.assertEqual(A.reported, 2) |
| 3173 | self.assertEqual(B.data['status'], 'MERGED') |
| 3174 | self.assertEqual(B.reported, 2) |
| 3175 | self.assertEqual(C.data['status'], 'MERGED') |
| 3176 | self.assertEqual(C.reported, 2) |
| 3177 | |
| 3178 | client.shutdown() |
| 3179 | self.assertEqual(r, True) |
| 3180 | |
| 3181 | def test_client_promote_dependent(self): |
| 3182 | "Test that the RPC client can promote a dependent change" |
| 3183 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3184 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3185 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3187 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3188 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3189 | |
| 3190 | C.setDependsOn(B, 1) |
| 3191 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3192 | A.addApproval('code-review', 2) |
| 3193 | B.addApproval('code-review', 2) |
| 3194 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3195 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3196 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3197 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3198 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3199 | |
| 3200 | self.waitUntilSettled() |
| 3201 | |
| 3202 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3203 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3204 | r = client.promote(tenant='tenant-one', |
| 3205 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3206 | change_ids=['3,1']) |
| 3207 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3208 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3209 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3211 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3212 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3213 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3214 | self.waitUntilSettled() |
| 3215 | |
| 3216 | self.assertEqual(len(self.builds), 6) |
| 3217 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3218 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3219 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3220 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3221 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3222 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3223 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3224 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3225 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3226 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3227 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3228 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3229 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3230 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3231 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3232 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3233 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3234 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3235 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3236 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3237 | self.waitUntilSettled() |
| 3238 | |
| 3239 | self.assertEqual(A.data['status'], 'MERGED') |
| 3240 | self.assertEqual(A.reported, 2) |
| 3241 | self.assertEqual(B.data['status'], 'MERGED') |
| 3242 | self.assertEqual(B.reported, 2) |
| 3243 | self.assertEqual(C.data['status'], 'MERGED') |
| 3244 | self.assertEqual(C.reported, 2) |
| 3245 | |
| 3246 | client.shutdown() |
| 3247 | self.assertEqual(r, True) |
| 3248 | |
| 3249 | def test_client_promote_negative(self): |
| 3250 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3251 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3253 | A.addApproval('code-review', 2) |
| 3254 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3255 | self.waitUntilSettled() |
| 3256 | |
| 3257 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3258 | self.gearman_server.port) |
| 3259 | |
| 3260 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3261 | r = client.promote(tenant='tenant-one', |
| 3262 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3263 | change_ids=['2,1', '3,1']) |
| 3264 | client.shutdown() |
| 3265 | self.assertEqual(r, False) |
| 3266 | |
| 3267 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3268 | r = client.promote(tenant='tenant-one', |
| 3269 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3270 | change_ids=['4,1']) |
| 3271 | client.shutdown() |
| 3272 | self.assertEqual(r, False) |
| 3273 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3274 | self.launch_server.hold_jobs_in_build = False |
| 3275 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3276 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3277 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3278 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3279 | def test_queue_rate_limiting(self): |
| 3280 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3281 | self.updateConfigLayout( |
| 3282 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3283 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3284 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3285 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3286 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3287 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3288 | |
| 3289 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3290 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3291 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3292 | A.addApproval('code-review', 2) |
| 3293 | B.addApproval('code-review', 2) |
| 3294 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3295 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3296 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3297 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3298 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3299 | self.waitUntilSettled() |
| 3300 | |
| 3301 | # Only A and B will have their merge jobs queued because |
| 3302 | # window is 2. |
| 3303 | self.assertEqual(len(self.builds), 2) |
| 3304 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3305 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3306 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3307 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3308 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3309 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3310 | self.waitUntilSettled() |
| 3311 | |
| 3312 | # Only A and B will have their test jobs queued because |
| 3313 | # window is 2. |
| 3314 | self.assertEqual(len(self.builds), 4) |
| 3315 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3316 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3317 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3318 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3319 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3320 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3321 | self.waitUntilSettled() |
| 3322 | |
| 3323 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3324 | # A failed so window is reduced by 1 to 1. |
| 3325 | self.assertEqual(queue.window, 1) |
| 3326 | self.assertEqual(queue.window_floor, 1) |
| 3327 | self.assertEqual(A.data['status'], 'NEW') |
| 3328 | |
| 3329 | # Gate is reset and only B's merge job is queued because |
| 3330 | # window shrunk to 1. |
| 3331 | self.assertEqual(len(self.builds), 1) |
| 3332 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3333 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3334 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3335 | self.waitUntilSettled() |
| 3336 | |
| 3337 | # Only B's test jobs are queued because window is still 1. |
| 3338 | self.assertEqual(len(self.builds), 2) |
| 3339 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3340 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3341 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3342 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3343 | self.waitUntilSettled() |
| 3344 | |
| 3345 | # B was successfully merged so window is increased to 2. |
| 3346 | self.assertEqual(queue.window, 2) |
| 3347 | self.assertEqual(queue.window_floor, 1) |
| 3348 | self.assertEqual(B.data['status'], 'MERGED') |
| 3349 | |
| 3350 | # Only C is left and its merge job is queued. |
| 3351 | self.assertEqual(len(self.builds), 1) |
| 3352 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3353 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3354 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3355 | self.waitUntilSettled() |
| 3356 | |
| 3357 | # After successful merge job the test jobs for C are queued. |
| 3358 | self.assertEqual(len(self.builds), 2) |
| 3359 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3360 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3361 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3362 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3363 | self.waitUntilSettled() |
| 3364 | |
| 3365 | # C successfully merged so window is bumped to 3. |
| 3366 | self.assertEqual(queue.window, 3) |
| 3367 | self.assertEqual(queue.window_floor, 1) |
| 3368 | self.assertEqual(C.data['status'], 'MERGED') |
| 3369 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3370 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3371 | def test_queue_rate_limiting_dependent(self): |
| 3372 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3373 | self.updateConfigLayout( |
| 3374 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3375 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3376 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3377 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3378 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3379 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3380 | |
| 3381 | B.setDependsOn(A, 1) |
| 3382 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3383 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3384 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3385 | A.addApproval('code-review', 2) |
| 3386 | B.addApproval('code-review', 2) |
| 3387 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3388 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3389 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3390 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3391 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3392 | self.waitUntilSettled() |
| 3393 | |
| 3394 | # Only A and B will have their merge jobs queued because |
| 3395 | # window is 2. |
| 3396 | self.assertEqual(len(self.builds), 2) |
| 3397 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3398 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3399 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3400 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3401 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3402 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3403 | self.waitUntilSettled() |
| 3404 | |
| 3405 | # Only A and B will have their test jobs queued because |
| 3406 | # window is 2. |
| 3407 | self.assertEqual(len(self.builds), 4) |
| 3408 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3409 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3410 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3411 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3412 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3413 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3414 | self.waitUntilSettled() |
| 3415 | |
| 3416 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3417 | # A failed so window is reduced by 1 to 1. |
| 3418 | self.assertEqual(queue.window, 1) |
| 3419 | self.assertEqual(queue.window_floor, 1) |
| 3420 | self.assertEqual(A.data['status'], 'NEW') |
| 3421 | self.assertEqual(B.data['status'], 'NEW') |
| 3422 | |
| 3423 | # Gate is reset and only C's merge job is queued because |
| 3424 | # window shrunk to 1 and A and B were dequeued. |
| 3425 | self.assertEqual(len(self.builds), 1) |
| 3426 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3427 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3428 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3429 | self.waitUntilSettled() |
| 3430 | |
| 3431 | # Only C's test jobs are queued because window is still 1. |
| 3432 | self.assertEqual(len(self.builds), 2) |
| 3433 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3434 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3435 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3436 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3437 | self.waitUntilSettled() |
| 3438 | |
| 3439 | # C was successfully merged so window is increased to 2. |
| 3440 | self.assertEqual(queue.window, 2) |
| 3441 | self.assertEqual(queue.window_floor, 1) |
| 3442 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3443 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3444 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3445 | def test_worker_update_metadata(self): |
| 3446 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3447 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3448 | |
| 3449 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3450 | A.addApproval('code-review', 2) |
| 3451 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3452 | self.waitUntilSettled() |
| 3453 | |
| 3454 | self.assertEqual(len(self.launcher.builds), 1) |
| 3455 | |
| 3456 | self.log.debug('Current builds:') |
| 3457 | self.log.debug(self.launcher.builds) |
| 3458 | |
| 3459 | start = time.time() |
| 3460 | while True: |
| 3461 | if time.time() - start > 10: |
| 3462 | raise Exception("Timeout waiting for gearman server to report " |
| 3463 | + "back to the client") |
| 3464 | build = self.launcher.builds.values()[0] |
| 3465 | if build.worker.name == "My Worker": |
| 3466 | break |
| 3467 | else: |
| 3468 | time.sleep(0) |
| 3469 | |
| 3470 | self.log.debug(build) |
| 3471 | self.assertEqual("My Worker", build.worker.name) |
| 3472 | self.assertEqual("localhost", build.worker.hostname) |
| 3473 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3474 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3475 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3476 | self.assertEqual("v1.1", build.worker.version) |
| 3477 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3478 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3479 | self.launch_server.hold_jobs_in_build = False |
| 3480 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3481 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3482 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3483 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3484 | def test_footer_message(self): |
| 3485 | "Test a pipeline's footer message is correctly added to the report." |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3486 | self.updateConfigLayout( |
| 3487 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3488 | self.sched.reconfigure(self.config) |
| 3489 | self.registerJobs() |
| 3490 | |
| 3491 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3492 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3493 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3494 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3495 | self.waitUntilSettled() |
| 3496 | |
| 3497 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3498 | B.addApproval('code-review', 2) |
| 3499 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3500 | self.waitUntilSettled() |
| 3501 | |
| 3502 | self.assertEqual(2, len(self.smtp_messages)) |
| 3503 | |
| 3504 | failure_body = """\ |
| 3505 | Build failed. For information on how to proceed, see \ |
| 3506 | http://wiki.example.org/Test_Failures |
| 3507 | |
| 3508 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3509 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3510 | |
| 3511 | For CI problems and help debugging, contact ci@example.org""" |
| 3512 | |
| 3513 | success_body = """\ |
| 3514 | Build succeeded. |
| 3515 | |
| 3516 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3517 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3518 | |
| 3519 | For CI problems and help debugging, contact ci@example.org""" |
| 3520 | |
| 3521 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3522 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3523 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3524 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3525 | def test_merge_failure_reporters(self): |
| 3526 | """Check that the config is set up correctly""" |
| 3527 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3528 | self.updateConfigLayout( |
| 3529 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3530 | self.sched.reconfigure(self.config) |
| 3531 | self.registerJobs() |
| 3532 | |
| 3533 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3534 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3535 | "dependencies was unable to be automatically merged with the " |
| 3536 | "current state of its repository. Please rebase the change and " |
| 3537 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3538 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3539 | self.assertEqual( |
| 3540 | "The merge failed! For more information...", |
| 3541 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3542 | |
| 3543 | self.assertEqual( |
| 3544 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3545 | self.assertEqual( |
| 3546 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3547 | |
| 3548 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3549 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3550 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3551 | |
| 3552 | self.assertTrue( |
| 3553 | ( |
| 3554 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3555 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3556 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3557 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3558 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3559 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3560 | ) or ( |
| 3561 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3562 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3563 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3564 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3565 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3566 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3567 | ) |
| 3568 | ) |
| 3569 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3570 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3571 | def test_merge_failure_reports(self): |
| 3572 | """Check that when a change fails to merge the correct message is sent |
| 3573 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3574 | self.updateConfigLayout( |
| 3575 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3576 | self.sched.reconfigure(self.config) |
| 3577 | self.registerJobs() |
| 3578 | |
| 3579 | # Check a test failure isn't reported to SMTP |
| 3580 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3581 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3582 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3583 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3584 | self.waitUntilSettled() |
| 3585 | |
| 3586 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3587 | self.assertEqual(0, len(self.smtp_messages)) |
| 3588 | |
| 3589 | # Check a merge failure is reported to SMTP |
| 3590 | # B should be merged, but C will conflict with B |
| 3591 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3592 | B.addPatchset(['conflict']) |
| 3593 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3594 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3595 | B.addApproval('code-review', 2) |
| 3596 | C.addApproval('code-review', 2) |
| 3597 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3598 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3599 | self.waitUntilSettled() |
| 3600 | |
| 3601 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3602 | self.assertEqual(1, len(self.smtp_messages)) |
| 3603 | self.assertEqual('The merge failed! For more information...', |
| 3604 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3605 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3606 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3607 | def test_default_merge_failure_reports(self): |
| 3608 | """Check that the default merge failure reports are correct.""" |
| 3609 | |
| 3610 | # A should report success, B should report merge failure. |
| 3611 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3612 | A.addPatchset(['conflict']) |
| 3613 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3614 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3615 | A.addApproval('code-review', 2) |
| 3616 | B.addApproval('code-review', 2) |
| 3617 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3618 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3619 | self.waitUntilSettled() |
| 3620 | |
| 3621 | self.assertEqual(3, len(self.history)) # A jobs |
| 3622 | self.assertEqual(A.reported, 2) |
| 3623 | self.assertEqual(B.reported, 2) |
| 3624 | self.assertEqual(A.data['status'], 'MERGED') |
| 3625 | self.assertEqual(B.data['status'], 'NEW') |
| 3626 | self.assertIn('Build succeeded', A.messages[1]) |
| 3627 | self.assertIn('Merge Failed', B.messages[1]) |
| 3628 | self.assertIn('automatically merged', B.messages[1]) |
| 3629 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3630 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3631 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3632 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3633 | def test_swift_instructions(self): |
| 3634 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3635 | self.updateConfigLayout( |
| 3636 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3637 | self.sched.reconfigure(self.config) |
| 3638 | self.registerJobs() |
| 3639 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3640 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3641 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3642 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3643 | A.addApproval('code-review', 2) |
| 3644 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3645 | self.waitUntilSettled() |
| 3646 | |
| 3647 | self.assertEqual( |
| 3648 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3649 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3650 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3651 | self.assertEqual(5, |
| 3652 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3653 | split('\n'))) |
| 3654 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3655 | |
| 3656 | self.assertEqual( |
| 3657 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3658 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3659 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3660 | self.assertEqual(5, |
| 3661 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3662 | split('\n'))) |
| 3663 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3664 | |
| 3665 | self.assertEqual( |
| 3666 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3667 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3668 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3669 | self.assertEqual(5, |
| 3670 | len(self.builds[1]. |
| 3671 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3672 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3673 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3674 | self.launch_server.hold_jobs_in_build = False |
| 3675 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3676 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3677 | |
| 3678 | def test_client_get_running_jobs(self): |
| 3679 | "Test that the RPC client can get a list of running jobs" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3680 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3681 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3682 | A.addApproval('code-review', 2) |
| 3683 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3684 | self.waitUntilSettled() |
| 3685 | |
| 3686 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3687 | self.gearman_server.port) |
| 3688 | |
| 3689 | # Wait for gearman server to send the initial workData back to zuul |
| 3690 | start = time.time() |
| 3691 | while True: |
| 3692 | if time.time() - start > 10: |
| 3693 | raise Exception("Timeout waiting for gearman server to report " |
| 3694 | + "back to the client") |
Clint Byrum | 78a6977 | 2016-12-05 10:52:07 -0800 | [diff] [blame] | 3695 | build = self.launch_client.builds.values()[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3696 | if build.worker.name == "My Worker": |
| 3697 | break |
| 3698 | else: |
| 3699 | time.sleep(0) |
| 3700 | |
| 3701 | running_items = client.get_running_jobs() |
| 3702 | |
| 3703 | self.assertEqual(1, len(running_items)) |
| 3704 | running_item = running_items[0] |
| 3705 | self.assertEqual([], running_item['failing_reasons']) |
| 3706 | self.assertEqual([], running_item['items_behind']) |
| 3707 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3708 | self.assertEqual(None, running_item['item_ahead']) |
| 3709 | self.assertEqual('org/project', running_item['project']) |
| 3710 | self.assertEqual(None, running_item['remaining_time']) |
| 3711 | self.assertEqual(True, running_item['active']) |
| 3712 | self.assertEqual('1,1', running_item['id']) |
| 3713 | |
| 3714 | self.assertEqual(3, len(running_item['jobs'])) |
| 3715 | for job in running_item['jobs']: |
| 3716 | if job['name'] == 'project-merge': |
| 3717 | self.assertEqual('project-merge', job['name']) |
| 3718 | self.assertEqual('gate', job['pipeline']) |
| 3719 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3720 | self.assertEqual('https://server/job/project-merge/0/', |
| 3721 | job['url']) |
| 3722 | self.assertEqual(7, len(job['worker'])) |
| 3723 | self.assertEqual(False, job['canceled']) |
| 3724 | self.assertEqual(True, job['voting']) |
| 3725 | self.assertEqual(None, job['result']) |
| 3726 | self.assertEqual('gate', job['pipeline']) |
| 3727 | break |
| 3728 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3729 | self.launch_server.hold_jobs_in_build = False |
| 3730 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3731 | self.waitUntilSettled() |
| 3732 | |
| 3733 | running_items = client.get_running_jobs() |
| 3734 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3735 | |
| 3736 | def test_nonvoting_pipeline(self): |
| 3737 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3738 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3739 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3740 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3741 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3742 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3743 | |
| 3744 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3745 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3746 | self.assertEqual( |
| 3747 | self.getJobFromHistory('experimental-project-test').result, |
| 3748 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3749 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3750 | |
| 3751 | def test_crd_gate(self): |
| 3752 | "Test cross-repo dependencies" |
| 3753 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3754 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3755 | A.addApproval('code-review', 2) |
| 3756 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3757 | |
| 3758 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3759 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3760 | AM2.setMerged() |
| 3761 | AM1.setMerged() |
| 3762 | |
| 3763 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3764 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3765 | BM2.setMerged() |
| 3766 | BM1.setMerged() |
| 3767 | |
| 3768 | # A -> AM1 -> AM2 |
| 3769 | # B -> BM1 -> BM2 |
| 3770 | # A Depends-On: B |
| 3771 | # M2 is here to make sure it is never queried. If it is, it |
| 3772 | # means zuul is walking down the entire history of merged |
| 3773 | # changes. |
| 3774 | |
| 3775 | B.setDependsOn(BM1, 1) |
| 3776 | BM1.setDependsOn(BM2, 1) |
| 3777 | |
| 3778 | A.setDependsOn(AM1, 1) |
| 3779 | AM1.setDependsOn(AM2, 1) |
| 3780 | |
| 3781 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3782 | A.subject, B.data['id']) |
| 3783 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3784 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3785 | self.waitUntilSettled() |
| 3786 | |
| 3787 | self.assertEqual(A.data['status'], 'NEW') |
| 3788 | self.assertEqual(B.data['status'], 'NEW') |
| 3789 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3790 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3791 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3792 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3793 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3794 | B.addApproval('approved', 1) |
| 3795 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3796 | self.waitUntilSettled() |
| 3797 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3798 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3799 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3800 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3801 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3802 | self.launch_server.hold_jobs_in_build = False |
| 3803 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3804 | self.waitUntilSettled() |
| 3805 | |
| 3806 | self.assertEqual(AM2.queried, 0) |
| 3807 | self.assertEqual(BM2.queried, 0) |
| 3808 | self.assertEqual(A.data['status'], 'MERGED') |
| 3809 | self.assertEqual(B.data['status'], 'MERGED') |
| 3810 | self.assertEqual(A.reported, 2) |
| 3811 | self.assertEqual(B.reported, 2) |
| 3812 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3813 | changes = self.getJobFromHistory( |
| 3814 | 'project-merge', 'org/project1').changes |
| 3815 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3816 | |
| 3817 | def test_crd_branch(self): |
| 3818 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3819 | |
| 3820 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3821 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3822 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3823 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3824 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3825 | A.addApproval('code-review', 2) |
| 3826 | B.addApproval('code-review', 2) |
| 3827 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3828 | |
| 3829 | # A Depends-On: B+C |
| 3830 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3831 | A.subject, B.data['id']) |
| 3832 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3833 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3834 | B.addApproval('approved', 1) |
| 3835 | C.addApproval('approved', 1) |
| 3836 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3837 | self.waitUntilSettled() |
| 3838 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3839 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3840 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3841 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3842 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3843 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3844 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3845 | self.launch_server.hold_jobs_in_build = False |
| 3846 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3847 | self.waitUntilSettled() |
| 3848 | |
| 3849 | self.assertEqual(A.data['status'], 'MERGED') |
| 3850 | self.assertEqual(B.data['status'], 'MERGED') |
| 3851 | self.assertEqual(C.data['status'], 'MERGED') |
| 3852 | self.assertEqual(A.reported, 2) |
| 3853 | self.assertEqual(B.reported, 2) |
| 3854 | self.assertEqual(C.reported, 2) |
| 3855 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3856 | changes = self.getJobFromHistory( |
| 3857 | 'project-merge', 'org/project1').changes |
| 3858 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3859 | |
| 3860 | def test_crd_multiline(self): |
| 3861 | "Test multiple depends-on lines in commit" |
| 3862 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3863 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3864 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3865 | A.addApproval('code-review', 2) |
| 3866 | B.addApproval('code-review', 2) |
| 3867 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3868 | |
| 3869 | # A Depends-On: B+C |
| 3870 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3871 | A.subject, B.data['id'], C.data['id']) |
| 3872 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3873 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3874 | B.addApproval('approved', 1) |
| 3875 | C.addApproval('approved', 1) |
| 3876 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3877 | self.waitUntilSettled() |
| 3878 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3879 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3880 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3881 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3882 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3883 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3884 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3885 | self.launch_server.hold_jobs_in_build = False |
| 3886 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3887 | self.waitUntilSettled() |
| 3888 | |
| 3889 | self.assertEqual(A.data['status'], 'MERGED') |
| 3890 | self.assertEqual(B.data['status'], 'MERGED') |
| 3891 | self.assertEqual(C.data['status'], 'MERGED') |
| 3892 | self.assertEqual(A.reported, 2) |
| 3893 | self.assertEqual(B.reported, 2) |
| 3894 | self.assertEqual(C.reported, 2) |
| 3895 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3896 | changes = self.getJobFromHistory( |
| 3897 | 'project-merge', 'org/project1').changes |
| 3898 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3899 | |
| 3900 | def test_crd_unshared_gate(self): |
| 3901 | "Test cross-repo dependencies in unshared gate queues" |
| 3902 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3903 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3904 | A.addApproval('code-review', 2) |
| 3905 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3906 | |
| 3907 | # A Depends-On: B |
| 3908 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3909 | A.subject, B.data['id']) |
| 3910 | |
| 3911 | # A and B do not share a queue, make sure that A is unable to |
| 3912 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3913 | B.addApproval('approved', 1) |
| 3914 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3915 | self.waitUntilSettled() |
| 3916 | |
| 3917 | self.assertEqual(A.data['status'], 'NEW') |
| 3918 | self.assertEqual(B.data['status'], 'NEW') |
| 3919 | self.assertEqual(A.reported, 0) |
| 3920 | self.assertEqual(B.reported, 0) |
| 3921 | self.assertEqual(len(self.history), 0) |
| 3922 | |
| 3923 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3924 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3925 | self.waitUntilSettled() |
| 3926 | |
| 3927 | self.assertEqual(B.data['status'], 'MERGED') |
| 3928 | self.assertEqual(B.reported, 2) |
| 3929 | |
| 3930 | # Now that B is merged, A should be able to be enqueued and |
| 3931 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3932 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3933 | self.waitUntilSettled() |
| 3934 | |
| 3935 | self.assertEqual(A.data['status'], 'MERGED') |
| 3936 | self.assertEqual(A.reported, 2) |
| 3937 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3938 | def test_crd_gate_reverse(self): |
| 3939 | "Test reverse cross-repo dependencies" |
| 3940 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3941 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3942 | A.addApproval('code-review', 2) |
| 3943 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3944 | |
| 3945 | # A Depends-On: B |
| 3946 | |
| 3947 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3948 | A.subject, B.data['id']) |
| 3949 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3950 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3951 | self.waitUntilSettled() |
| 3952 | |
| 3953 | self.assertEqual(A.data['status'], 'NEW') |
| 3954 | self.assertEqual(B.data['status'], 'NEW') |
| 3955 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3956 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3957 | A.addApproval('approved', 1) |
| 3958 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3959 | self.waitUntilSettled() |
| 3960 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3961 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3962 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3963 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3964 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3965 | self.launch_server.hold_jobs_in_build = False |
| 3966 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3967 | self.waitUntilSettled() |
| 3968 | |
| 3969 | self.assertEqual(A.data['status'], 'MERGED') |
| 3970 | self.assertEqual(B.data['status'], 'MERGED') |
| 3971 | self.assertEqual(A.reported, 2) |
| 3972 | self.assertEqual(B.reported, 2) |
| 3973 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3974 | changes = self.getJobFromHistory( |
| 3975 | 'project-merge', 'org/project1').changes |
| 3976 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3977 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3978 | def test_crd_cycle(self): |
| 3979 | "Test cross-repo dependency cycles" |
| 3980 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3981 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3982 | A.addApproval('code-review', 2) |
| 3983 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3984 | |
| 3985 | # A -> B -> A (via commit-depends) |
| 3986 | |
| 3987 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3988 | A.subject, B.data['id']) |
| 3989 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3990 | B.subject, A.data['id']) |
| 3991 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3992 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3993 | self.waitUntilSettled() |
| 3994 | |
| 3995 | self.assertEqual(A.reported, 0) |
| 3996 | self.assertEqual(B.reported, 0) |
| 3997 | self.assertEqual(A.data['status'], 'NEW') |
| 3998 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3999 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4000 | def test_crd_gate_unknown(self): |
| 4001 | "Test unknown projects in dependent pipeline" |
| 4002 | self.init_repo("org/unknown") |
| 4003 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4004 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4005 | A.addApproval('code-review', 2) |
| 4006 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4007 | |
| 4008 | # A Depends-On: B |
| 4009 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4010 | A.subject, B.data['id']) |
| 4011 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4012 | B.addApproval('approved', 1) |
| 4013 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4014 | self.waitUntilSettled() |
| 4015 | |
| 4016 | # Unknown projects cannot share a queue with any other |
| 4017 | # since they don't have common jobs with any other (they have no jobs). |
| 4018 | # Changes which depend on unknown project changes |
| 4019 | # should not be processed in dependent pipeline |
| 4020 | self.assertEqual(A.data['status'], 'NEW') |
| 4021 | self.assertEqual(B.data['status'], 'NEW') |
| 4022 | self.assertEqual(A.reported, 0) |
| 4023 | self.assertEqual(B.reported, 0) |
| 4024 | self.assertEqual(len(self.history), 0) |
| 4025 | |
| 4026 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4027 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4028 | B.setMerged() |
| 4029 | self.waitUntilSettled() |
| 4030 | self.assertEqual(len(self.history), 0) |
| 4031 | |
| 4032 | # Now that B is merged, A should be able to be enqueued and |
| 4033 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4034 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4035 | self.waitUntilSettled() |
| 4036 | |
| 4037 | self.assertEqual(A.data['status'], 'MERGED') |
| 4038 | self.assertEqual(A.reported, 2) |
| 4039 | self.assertEqual(B.data['status'], 'MERGED') |
| 4040 | self.assertEqual(B.reported, 0) |
| 4041 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4042 | def test_crd_check(self): |
| 4043 | "Test cross-repo dependencies in independent pipelines" |
| 4044 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4045 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4046 | self.gearman_server.hold_jobs_in_queue = True |
| 4047 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4048 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4049 | |
| 4050 | # A Depends-On: B |
| 4051 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4052 | A.subject, B.data['id']) |
| 4053 | |
| 4054 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4055 | self.waitUntilSettled() |
| 4056 | |
| 4057 | queue = self.gearman_server.getQueue() |
| 4058 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4059 | self.gearman_server.hold_jobs_in_queue = False |
| 4060 | self.gearman_server.release() |
| 4061 | self.waitUntilSettled() |
| 4062 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4063 | self.launch_server.release('.*-merge') |
| 4064 | self.waitUntilSettled() |
| 4065 | |
| 4066 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4067 | repo = git.Repo(path) |
| 4068 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4069 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4070 | correct_messages = [ |
| 4071 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4072 | self.assertEqual(repo_messages, correct_messages) |
| 4073 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4074 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4075 | repo = git.Repo(path) |
| 4076 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4077 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4078 | correct_messages = [ |
| 4079 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4080 | self.assertEqual(repo_messages, correct_messages) |
| 4081 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4082 | self.launch_server.hold_jobs_in_build = False |
| 4083 | self.launch_server.release() |
| 4084 | self.waitUntilSettled() |
| 4085 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4086 | self.assertEqual(A.data['status'], 'NEW') |
| 4087 | self.assertEqual(B.data['status'], 'NEW') |
| 4088 | self.assertEqual(A.reported, 1) |
| 4089 | self.assertEqual(B.reported, 0) |
| 4090 | |
| 4091 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4092 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4093 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4094 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4095 | def test_crd_check_git_depends(self): |
| 4096 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4097 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4098 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4099 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4100 | |
| 4101 | # Add two git-dependent changes and make sure they both report |
| 4102 | # success. |
| 4103 | B.setDependsOn(A, 1) |
| 4104 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4105 | self.waitUntilSettled() |
| 4106 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4107 | self.waitUntilSettled() |
| 4108 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4109 | self.orderedRelease() |
| 4110 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4111 | self.waitUntilSettled() |
| 4112 | |
| 4113 | self.assertEqual(A.data['status'], 'NEW') |
| 4114 | self.assertEqual(B.data['status'], 'NEW') |
| 4115 | self.assertEqual(A.reported, 1) |
| 4116 | self.assertEqual(B.reported, 1) |
| 4117 | |
| 4118 | self.assertEqual(self.history[0].changes, '1,1') |
| 4119 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4120 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4121 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4122 | |
| 4123 | self.assertIn('Build succeeded', A.messages[0]) |
| 4124 | self.assertIn('Build succeeded', B.messages[0]) |
| 4125 | |
| 4126 | def test_crd_check_duplicate(self): |
| 4127 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4128 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4129 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4130 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4131 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4132 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4133 | |
| 4134 | # Add two git-dependent changes... |
| 4135 | B.setDependsOn(A, 1) |
| 4136 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4137 | self.waitUntilSettled() |
| 4138 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4139 | |
| 4140 | # ...make sure the live one is not duplicated... |
| 4141 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4142 | self.waitUntilSettled() |
| 4143 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4144 | |
| 4145 | # ...but the non-live one is able to be. |
| 4146 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4147 | self.waitUntilSettled() |
| 4148 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4149 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4150 | # Release jobs in order to avoid races with change A jobs |
| 4151 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4152 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4153 | self.launch_server.hold_jobs_in_build = False |
| 4154 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4155 | self.waitUntilSettled() |
| 4156 | |
| 4157 | self.assertEqual(A.data['status'], 'NEW') |
| 4158 | self.assertEqual(B.data['status'], 'NEW') |
| 4159 | self.assertEqual(A.reported, 1) |
| 4160 | self.assertEqual(B.reported, 1) |
| 4161 | |
| 4162 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4163 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4164 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4165 | |
| 4166 | self.assertIn('Build succeeded', A.messages[0]) |
| 4167 | self.assertIn('Build succeeded', B.messages[0]) |
| 4168 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4169 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4170 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4171 | |
| 4172 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4173 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4174 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4175 | |
| 4176 | # A Depends-On: B |
| 4177 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4178 | A.subject, B.data['id']) |
| 4179 | |
| 4180 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4181 | self.waitUntilSettled() |
| 4182 | |
| 4183 | self.sched.reconfigure(self.config) |
| 4184 | |
| 4185 | # Make sure the items still share a change queue, and the |
| 4186 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4187 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4188 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4189 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4190 | first_item = queue.queue[0] |
| 4191 | for item in queue.queue: |
| 4192 | self.assertEqual(item.queue, first_item.queue) |
| 4193 | self.assertFalse(first_item.live) |
| 4194 | self.assertTrue(queue.queue[1].live) |
| 4195 | |
| 4196 | self.gearman_server.hold_jobs_in_queue = False |
| 4197 | self.gearman_server.release() |
| 4198 | self.waitUntilSettled() |
| 4199 | |
| 4200 | self.assertEqual(A.data['status'], 'NEW') |
| 4201 | self.assertEqual(B.data['status'], 'NEW') |
| 4202 | self.assertEqual(A.reported, 1) |
| 4203 | self.assertEqual(B.reported, 0) |
| 4204 | |
| 4205 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4206 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4207 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4208 | def test_crd_check_reconfiguration(self): |
| 4209 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4210 | |
| 4211 | def test_crd_undefined_project(self): |
| 4212 | """Test that undefined projects in dependencies are handled for |
| 4213 | independent pipelines""" |
| 4214 | # It's a hack for fake gerrit, |
| 4215 | # as it implies repo creation upon the creation of any change |
| 4216 | self.init_repo("org/unknown") |
| 4217 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4218 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4219 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4220 | def test_crd_check_ignore_dependencies(self): |
| 4221 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4222 | self.updateConfigLayout( |
| 4223 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4224 | self.sched.reconfigure(self.config) |
| 4225 | self.registerJobs() |
| 4226 | |
| 4227 | self.gearman_server.hold_jobs_in_queue = True |
| 4228 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4229 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4230 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4231 | |
| 4232 | # A Depends-On: B |
| 4233 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4234 | A.subject, B.data['id']) |
| 4235 | # C git-depends on B |
| 4236 | C.setDependsOn(B, 1) |
| 4237 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4238 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4239 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4240 | self.waitUntilSettled() |
| 4241 | |
| 4242 | # Make sure none of the items share a change queue, and all |
| 4243 | # are live. |
| 4244 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4245 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4246 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4247 | for item in check_pipeline.getAllItems(): |
| 4248 | self.assertTrue(item.live) |
| 4249 | |
| 4250 | self.gearman_server.hold_jobs_in_queue = False |
| 4251 | self.gearman_server.release() |
| 4252 | self.waitUntilSettled() |
| 4253 | |
| 4254 | self.assertEqual(A.data['status'], 'NEW') |
| 4255 | self.assertEqual(B.data['status'], 'NEW') |
| 4256 | self.assertEqual(C.data['status'], 'NEW') |
| 4257 | self.assertEqual(A.reported, 1) |
| 4258 | self.assertEqual(B.reported, 1) |
| 4259 | self.assertEqual(C.reported, 1) |
| 4260 | |
| 4261 | # Each job should have tested exactly one change |
| 4262 | for job in self.history: |
| 4263 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4264 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4265 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4266 | def test_crd_check_transitive(self): |
| 4267 | "Test transitive cross-repo dependencies" |
| 4268 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4269 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4270 | # and C,2 (not C,1 which would indicate stale data in the |
| 4271 | # cache for B). |
| 4272 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4273 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4274 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4275 | |
| 4276 | # A Depends-On: B |
| 4277 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4278 | A.subject, B.data['id']) |
| 4279 | |
| 4280 | # B Depends-On: C |
| 4281 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4282 | B.subject, C.data['id']) |
| 4283 | |
| 4284 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4285 | self.waitUntilSettled() |
| 4286 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4287 | |
| 4288 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4289 | self.waitUntilSettled() |
| 4290 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4291 | |
| 4292 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4293 | self.waitUntilSettled() |
| 4294 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4295 | |
| 4296 | C.addPatchset() |
| 4297 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4298 | self.waitUntilSettled() |
| 4299 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4300 | |
| 4301 | A.addPatchset() |
| 4302 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4303 | self.waitUntilSettled() |
| 4304 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4305 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4306 | def test_crd_check_unknown(self): |
| 4307 | "Test unknown projects in independent pipeline" |
| 4308 | self.init_repo("org/unknown") |
| 4309 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4310 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4311 | # A Depends-On: B |
| 4312 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4313 | A.subject, B.data['id']) |
| 4314 | |
| 4315 | # Make sure zuul has seen an event on B. |
| 4316 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4317 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4318 | self.waitUntilSettled() |
| 4319 | |
| 4320 | self.assertEqual(A.data['status'], 'NEW') |
| 4321 | self.assertEqual(A.reported, 1) |
| 4322 | self.assertEqual(B.data['status'], 'NEW') |
| 4323 | self.assertEqual(B.reported, 0) |
| 4324 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4325 | def test_crd_cycle_join(self): |
| 4326 | "Test an updated change creates a cycle" |
| 4327 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4328 | |
| 4329 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4330 | self.waitUntilSettled() |
| 4331 | |
| 4332 | # Create B->A |
| 4333 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4334 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4335 | B.subject, A.data['id']) |
| 4336 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4337 | self.waitUntilSettled() |
| 4338 | |
| 4339 | # Update A to add A->B (a cycle). |
| 4340 | A.addPatchset() |
| 4341 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4342 | A.subject, B.data['id']) |
| 4343 | # Normally we would submit the patchset-created event for |
| 4344 | # processing here, however, we have no way of noting whether |
| 4345 | # the dependency cycle detection correctly raised an |
| 4346 | # exception, so instead, we reach into the source driver and |
| 4347 | # call the method that would ultimately be called by the event |
| 4348 | # processing. |
| 4349 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4350 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4351 | source = tenant.layout.pipelines['gate'].source |
| 4352 | |
| 4353 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4354 | # it easier for users to create events for testing. |
| 4355 | event = zuul.model.TriggerEvent() |
| 4356 | event.trigger_name = 'gerrit' |
| 4357 | event.change_number = '1' |
| 4358 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4359 | with testtools.ExpectedException( |
| 4360 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4361 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4362 | self.log.debug("Got expected dependency cycle exception") |
| 4363 | |
| 4364 | # Now if we update B to remove the depends-on, everything |
| 4365 | # should be okay. B; A->B |
| 4366 | |
| 4367 | B.addPatchset() |
| 4368 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4369 | |
| 4370 | source.getChange(event, True) |
| 4371 | event.change_number = '2' |
| 4372 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4373 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4374 | def test_disable_at(self): |
| 4375 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4376 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4377 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4378 | self.sched.reconfigure(self.config) |
| 4379 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4380 | tenant = self.sched.abide.tenants.get('openstack') |
| 4381 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4382 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4383 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4384 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4385 | |
| 4386 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4387 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4388 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4389 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4390 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4391 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4392 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4393 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4394 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4395 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4396 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4397 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4398 | self.launch_server.failJob('project-test1', A) |
| 4399 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4400 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4401 | self.launch_server.failJob('project-test1', D) |
| 4402 | self.launch_server.failJob('project-test1', E) |
| 4403 | self.launch_server.failJob('project-test1', F) |
| 4404 | self.launch_server.failJob('project-test1', G) |
| 4405 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4406 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4407 | self.launch_server.failJob('project-test1', J) |
| 4408 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4409 | |
| 4410 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4411 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4412 | self.waitUntilSettled() |
| 4413 | |
| 4414 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4415 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4416 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4417 | |
| 4418 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4419 | self.waitUntilSettled() |
| 4420 | |
| 4421 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4422 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4423 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4424 | |
| 4425 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4426 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4427 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4428 | self.waitUntilSettled() |
| 4429 | |
| 4430 | # We should be disabled now |
| 4431 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4432 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4433 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4434 | |
| 4435 | # We need to wait between each of these patches to make sure the |
| 4436 | # smtp messages come back in an expected order |
| 4437 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4438 | self.waitUntilSettled() |
| 4439 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4440 | self.waitUntilSettled() |
| 4441 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4442 | self.waitUntilSettled() |
| 4443 | |
| 4444 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4445 | # leaving a message on each change |
| 4446 | self.assertEqual(1, len(A.messages)) |
| 4447 | self.assertIn('Build failed.', A.messages[0]) |
| 4448 | self.assertEqual(1, len(B.messages)) |
| 4449 | self.assertIn('Build failed.', B.messages[0]) |
| 4450 | self.assertEqual(1, len(C.messages)) |
| 4451 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4452 | self.assertEqual(1, len(D.messages)) |
| 4453 | self.assertIn('Build failed.', D.messages[0]) |
| 4454 | self.assertEqual(1, len(E.messages)) |
| 4455 | self.assertIn('Build failed.', E.messages[0]) |
| 4456 | self.assertEqual(1, len(F.messages)) |
| 4457 | self.assertIn('Build failed.', F.messages[0]) |
| 4458 | |
| 4459 | # The last 3 (GHI) would have only reported via smtp. |
| 4460 | self.assertEqual(3, len(self.smtp_messages)) |
| 4461 | self.assertEqual(0, len(G.messages)) |
| 4462 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4463 | self.assertIn( |
| 4464 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4465 | self.assertEqual(0, len(H.messages)) |
| 4466 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4467 | self.assertIn( |
| 4468 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4469 | self.assertEqual(0, len(I.messages)) |
| 4470 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4471 | self.assertIn( |
| 4472 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4473 | |
| 4474 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4475 | # comes out of disabled |
| 4476 | self.sched.reconfigure(self.config) |
| 4477 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4478 | tenant = self.sched.abide.tenants.get('openstack') |
| 4479 | |
| 4480 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4481 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4482 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4483 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4484 | |
| 4485 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4486 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4487 | self.waitUntilSettled() |
| 4488 | |
| 4489 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4490 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4491 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4492 | |
| 4493 | # J and K went back to gerrit |
| 4494 | self.assertEqual(1, len(J.messages)) |
| 4495 | self.assertIn('Build failed.', J.messages[0]) |
| 4496 | self.assertEqual(1, len(K.messages)) |
| 4497 | self.assertIn('Build failed.', K.messages[0]) |
| 4498 | # No more messages reported via smtp |
| 4499 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4500 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4501 | def test_rerun_on_abort(self): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4502 | "Test that if a launch server fails to run a job, it is run again" |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4503 | |
| 4504 | self.config.set('zuul', 'layout_config', |
| 4505 | 'tests/fixtures/layout-abort-attempts.yaml') |
| 4506 | self.sched.reconfigure(self.config) |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4507 | self.launch_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4508 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4509 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4510 | self.waitUntilSettled() |
| 4511 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4512 | self.launch_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4513 | self.waitUntilSettled() |
| 4514 | |
| 4515 | self.assertEqual(len(self.builds), 2) |
| 4516 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4517 | self.launch_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4518 | self.waitUntilSettled() |
| 4519 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4520 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4521 | self.assertEqual(len(self.builds), 1, |
| 4522 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4523 | self.builds[0].requeue = True |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4524 | self.launch_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4525 | self.waitUntilSettled() |
| 4526 | |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4527 | self.launch_server.hold_jobs_in_build = False |
| 4528 | self.launch_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4529 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4530 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4531 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4532 | self.assertEqual(A.reported, 1) |
| 4533 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4534 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4535 | def test_zookeeper_disconnect(self): |
| 4536 | "Test that jobs are launched after a zookeeper disconnect" |
| 4537 | |
| 4538 | self.fake_nodepool.paused = True |
| 4539 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4540 | A.addApproval('code-review', 2) |
| 4541 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4542 | self.waitUntilSettled() |
| 4543 | |
| 4544 | self.zk.client.stop() |
| 4545 | self.zk.client.start() |
| 4546 | self.fake_nodepool.paused = False |
| 4547 | self.waitUntilSettled() |
| 4548 | |
| 4549 | self.assertEqual(A.data['status'], 'MERGED') |
| 4550 | self.assertEqual(A.reported, 2) |
| 4551 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4552 | |
| 4553 | class TestDuplicatePipeline(ZuulTestCase): |
| 4554 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4555 | |
| 4556 | def test_duplicate_pipelines(self): |
| 4557 | "Test that a change matching multiple pipelines works" |
| 4558 | |
| 4559 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4560 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4561 | self.waitUntilSettled() |
| 4562 | |
| 4563 | self.assertHistory([ |
| 4564 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4565 | pipeline='dup1'), |
| 4566 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4567 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4568 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4569 | |
| 4570 | self.assertEqual(len(A.messages), 2) |
| 4571 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4572 | if 'dup1' in A.messages[0]: |
| 4573 | self.assertIn('dup1', A.messages[0]) |
| 4574 | self.assertNotIn('dup2', A.messages[0]) |
| 4575 | self.assertIn('project-test1', A.messages[0]) |
| 4576 | self.assertIn('dup2', A.messages[1]) |
| 4577 | self.assertNotIn('dup1', A.messages[1]) |
| 4578 | self.assertIn('project-test1', A.messages[1]) |
| 4579 | else: |
| 4580 | self.assertIn('dup1', A.messages[1]) |
| 4581 | self.assertNotIn('dup2', A.messages[1]) |
| 4582 | self.assertIn('project-test1', A.messages[1]) |
| 4583 | self.assertIn('dup2', A.messages[0]) |
| 4584 | self.assertNotIn('dup1', A.messages[0]) |
| 4585 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4586 | |
| 4587 | |
| 4588 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4589 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4590 | |
| 4591 | def test_one_job_project(self): |
| 4592 | "Test that queueing works with one job" |
| 4593 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4594 | 'master', 'A') |
| 4595 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4596 | 'master', 'B') |
| 4597 | A.addApproval('code-review', 2) |
| 4598 | B.addApproval('code-review', 2) |
| 4599 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4600 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4601 | self.waitUntilSettled() |
| 4602 | |
| 4603 | self.assertEqual(A.data['status'], 'MERGED') |
| 4604 | self.assertEqual(A.reported, 2) |
| 4605 | self.assertEqual(B.data['status'], 'MERGED') |
| 4606 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4607 | |
| 4608 | |
| 4609 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4610 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4611 | |
| 4612 | def test_job_from_templates_launched(self): |
| 4613 | "Test whether a job generated via a template can be launched" |
| 4614 | |
| 4615 | A = self.fake_gerrit.addFakeChange( |
| 4616 | 'org/templated-project', 'master', 'A') |
| 4617 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4618 | self.waitUntilSettled() |
| 4619 | |
| 4620 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4621 | 'SUCCESS') |
| 4622 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4623 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4624 | |
| 4625 | def test_layered_templates(self): |
| 4626 | "Test whether a job generated via a template can be launched" |
| 4627 | |
| 4628 | A = self.fake_gerrit.addFakeChange( |
| 4629 | 'org/layered-project', 'master', 'A') |
| 4630 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4631 | self.waitUntilSettled() |
| 4632 | |
| 4633 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4634 | 'SUCCESS') |
| 4635 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4636 | 'SUCCESS') |
| 4637 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4638 | ).result, 'SUCCESS') |
| 4639 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4640 | ).result, 'SUCCESS') |
| 4641 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4642 | ).result, 'SUCCESS') |
| 4643 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4644 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4645 | |
| 4646 | |
| 4647 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4648 | tenant_config_file = 'config/success-url/main.yaml' |
| 4649 | |
| 4650 | def test_success_url(self): |
| 4651 | "Ensure bad build params are ignored" |
| 4652 | self.sched.reconfigure(self.config) |
| 4653 | self.init_repo('org/docs') |
| 4654 | |
| 4655 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4656 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4657 | self.waitUntilSettled() |
| 4658 | |
| 4659 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4660 | self.assertEqual(len(self.history), 2) |
| 4661 | |
| 4662 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4663 | for build in self.history: |
| 4664 | if build.name == 'docs-draft-test': |
| 4665 | uuid = build.uuid[:7] |
| 4666 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4667 | |
| 4668 | # Two msgs: 'Starting...' + results |
| 4669 | self.assertEqual(len(self.smtp_messages), 2) |
| 4670 | body = self.smtp_messages[1]['body'].splitlines() |
| 4671 | self.assertEqual('Build succeeded.', body[0]) |
| 4672 | |
| 4673 | self.assertIn( |
| 4674 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4675 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4676 | body[2]) |
| 4677 | |
| 4678 | # NOTE: This default URL is currently hard-coded in launcher/server.py |
| 4679 | self.assertIn( |
| 4680 | '- docs-draft-test2 https://server/job', |
| 4681 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4682 | |
| 4683 | |
| 4684 | class TestSchedulerMergeModes(ZuulTestCase): |
| 4685 | tenant_config_file = 'config/merge-modes/main.yaml' |
| 4686 | |
| 4687 | def _test_project_merge_mode(self, mode): |
| 4688 | self.launch_server.keep_jobdir = False |
| 4689 | project = 'org/project-%s' % mode |
| 4690 | self.launch_server.hold_jobs_in_build = True |
| 4691 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4692 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4693 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4694 | A.addApproval('code-review', 2) |
| 4695 | B.addApproval('code-review', 2) |
| 4696 | C.addApproval('code-review', 2) |
| 4697 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4698 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4699 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4700 | self.waitUntilSettled() |
| 4701 | |
| 4702 | build = self.builds[-1] |
| 4703 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4704 | |
| 4705 | path = os.path.join(build.jobdir.git_root, project) |
| 4706 | repo = git.Repo(path) |
| 4707 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4708 | repo_messages.reverse() |
| 4709 | |
| 4710 | self.launch_server.hold_jobs_in_build = False |
| 4711 | self.launch_server.release() |
| 4712 | self.waitUntilSettled() |
| 4713 | |
| 4714 | return repo_messages |
| 4715 | |
| 4716 | def _test_merge(self, mode): |
| 4717 | us_path = os.path.join( |
| 4718 | self.upstream_root, 'org/project-%s' % mode) |
| 4719 | expected_messages = [ |
| 4720 | 'initial commit', |
| 4721 | 'add content from fixture', |
| 4722 | # the intermediate commits order is nondeterministic |
| 4723 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4724 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4725 | ] |
| 4726 | result = self._test_project_merge_mode(mode) |
| 4727 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4728 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4729 | |
| 4730 | def test_project_merge_mode_merge(self): |
| 4731 | self._test_merge('merge') |
| 4732 | |
| 4733 | def test_project_merge_mode_merge_resolve(self): |
| 4734 | self._test_merge('merge-resolve') |
| 4735 | |
| 4736 | def test_project_merge_mode_cherrypick(self): |
| 4737 | expected_messages = [ |
| 4738 | 'initial commit', |
| 4739 | 'add content from fixture', |
| 4740 | 'A-1', |
| 4741 | 'B-1', |
| 4742 | 'C-1'] |
| 4743 | result = self._test_project_merge_mode('cherry-pick') |
| 4744 | self.assertEqual(result, expected_messages) |