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 | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 23 | import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import urllib2 |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 25 | import yaml |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 29 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 30 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 32 | import zuul.rpcclient |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 33 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 34 | import zuul.reporter.smtp |
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 ( |
| 37 | BaseTestCase, |
| 38 | ZuulTestCase, |
| 39 | repack_repo, |
| 40 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 41 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 42 | logging.basicConfig(level=logging.DEBUG, |
| 43 | format='%(asctime)s %(name)-32s ' |
| 44 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 45 | |
| 46 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 47 | class TestSchedulerConfigParsing(BaseTestCase): |
| 48 | |
| 49 | def test_parse_skip_if(self): |
| 50 | job_yaml = """ |
| 51 | jobs: |
| 52 | - name: job_name |
| 53 | skip-if: |
| 54 | - project: ^project_name$ |
| 55 | branch: ^stable/icehouse$ |
| 56 | all-files-match-any: |
| 57 | - ^filename$ |
| 58 | - project: ^project2_name$ |
| 59 | all-files-match-any: |
| 60 | - ^filename2$ |
| 61 | """.strip() |
| 62 | data = yaml.load(job_yaml) |
| 63 | config_job = data.get('jobs')[0] |
| 64 | sched = zuul.scheduler.Scheduler() |
| 65 | cm = zuul.change_matcher |
| 66 | expected = cm.MatchAny([ |
| 67 | cm.MatchAll([ |
| 68 | cm.ProjectMatcher('^project_name$'), |
| 69 | cm.BranchMatcher('^stable/icehouse$'), |
| 70 | cm.MatchAllFiles([cm.FileMatcher('^filename$')]), |
| 71 | ]), |
| 72 | cm.MatchAll([ |
| 73 | cm.ProjectMatcher('^project2_name$'), |
| 74 | cm.MatchAllFiles([cm.FileMatcher('^filename2$')]), |
| 75 | ]), |
| 76 | ]) |
| 77 | matcher = sched._parseSkipIf(config_job) |
| 78 | self.assertEqual(expected, matcher) |
| 79 | |
| 80 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 81 | class TestScheduler(ZuulTestCase): |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 82 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 83 | def test_jobs_launched(self): |
| 84 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 85 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 86 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 87 | A.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 88 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 89 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 90 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 91 | 'SUCCESS') |
| 92 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 93 | 'SUCCESS') |
| 94 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 95 | 'SUCCESS') |
| 96 | self.assertEqual(A.data['status'], 'MERGED') |
| 97 | self.assertEqual(A.reported, 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 98 | |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 99 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 100 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 101 | value='1|g') |
| 102 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 103 | kind='ms') |
| 104 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 105 | value='1|c') |
| 106 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 107 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 108 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 109 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 110 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 111 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 112 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 113 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 114 | def test_initial_pipeline_gauges(self): |
| 115 | "Test that each pipeline reported its length on start" |
| 116 | pipeline_names = self.sched.layout.pipelines.keys() |
| 117 | self.assertNotEqual(len(pipeline_names), 0) |
| 118 | for name in pipeline_names: |
| 119 | self.assertReportedStat('zuul.pipeline.%s.current_changes' % name, |
| 120 | value='0|g') |
| 121 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 122 | def test_duplicate_pipelines(self): |
| 123 | "Test that a change matching multiple pipelines works" |
James E. Blair | 1b4d972 | 2013-05-21 10:32:04 -0700 | [diff] [blame] | 124 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 125 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 126 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 127 | self.waitUntilSettled() |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 128 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 129 | self.assertEqual(len(self.history), 2) |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 130 | self.history[0].name == 'project-test1' |
| 131 | self.history[1].name == 'project-test1' |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 132 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 133 | self.assertEqual(len(A.messages), 2) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 134 | if 'dup1/project-test1' in A.messages[0]: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 135 | self.assertIn('dup1/project-test1', A.messages[0]) |
| 136 | self.assertNotIn('dup2/project-test1', A.messages[0]) |
| 137 | self.assertNotIn('dup1/project-test1', A.messages[1]) |
| 138 | self.assertIn('dup2/project-test1', A.messages[1]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 139 | else: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 140 | self.assertIn('dup1/project-test1', A.messages[1]) |
| 141 | self.assertNotIn('dup2/project-test1', A.messages[1]) |
| 142 | self.assertNotIn('dup1/project-test1', A.messages[0]) |
| 143 | self.assertIn('dup2/project-test1', A.messages[0]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 144 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 145 | def test_parallel_changes(self): |
| 146 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 147 | |
| 148 | self.worker.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 149 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 150 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 151 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 152 | A.addApproval('CRVW', 2) |
| 153 | B.addApproval('CRVW', 2) |
| 154 | C.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | |
| 156 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 157 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 158 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 159 | |
| 160 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(len(self.builds), 1) |
| 162 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 163 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 165 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 166 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 167 | self.assertEqual(len(self.builds), 3) |
| 168 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 169 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 170 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 171 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 172 | self.assertEqual(self.builds[2].name, 'project-merge') |
| 173 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 175 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(len(self.builds), 5) |
| 178 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 179 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 180 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 181 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 182 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 183 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 184 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 185 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 186 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 187 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 188 | self.assertEqual(self.builds[4].name, 'project-merge') |
| 189 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 190 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 191 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 192 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 193 | self.assertEqual(len(self.builds), 6) |
| 194 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 195 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 196 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 197 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 198 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 199 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 200 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 201 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 202 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 203 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 204 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 205 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
| 206 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 207 | self.assertTrue(self.job_has_changes(self.builds[5], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 208 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 209 | self.worker.hold_jobs_in_build = False |
| 210 | self.worker.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 211 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 212 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 213 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 214 | self.assertEqual(len(self.history), 9) |
| 215 | self.assertEqual(A.data['status'], 'MERGED') |
| 216 | self.assertEqual(B.data['status'], 'MERGED') |
| 217 | self.assertEqual(C.data['status'], 'MERGED') |
| 218 | self.assertEqual(A.reported, 2) |
| 219 | self.assertEqual(B.reported, 2) |
| 220 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 221 | |
| 222 | def test_failed_changes(self): |
| 223 | "Test that a change behind a failed change is retested" |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 224 | self.worker.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 225 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 227 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 228 | A.addApproval('CRVW', 2) |
| 229 | B.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 230 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 231 | self.worker.addFailTest('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 232 | |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 233 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 234 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 235 | self.waitUntilSettled() |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 236 | |
| 237 | self.worker.release('.*-merge') |
| 238 | self.waitUntilSettled() |
| 239 | |
| 240 | self.worker.hold_jobs_in_build = False |
| 241 | self.worker.release() |
| 242 | |
| 243 | self.waitUntilSettled() |
| 244 | # It's certain that the merge job for change 2 will run, but |
| 245 | # the test1 and test2 jobs may or may not run. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 246 | self.assertTrue(len(self.history) > 6) |
| 247 | self.assertEqual(A.data['status'], 'NEW') |
| 248 | self.assertEqual(B.data['status'], 'MERGED') |
| 249 | self.assertEqual(A.reported, 2) |
| 250 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 251 | |
| 252 | def test_independent_queues(self): |
| 253 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 254 | |
| 255 | self.worker.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 256 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 257 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 258 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 259 | A.addApproval('CRVW', 2) |
| 260 | B.addApproval('CRVW', 2) |
| 261 | C.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 262 | |
| 263 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 264 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 265 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 266 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 267 | self.waitUntilSettled() |
| 268 | |
| 269 | # There should be one merge job at the head of each queue running |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 270 | self.assertEqual(len(self.builds), 2) |
| 271 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 272 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 273 | self.assertEqual(self.builds[1].name, 'project1-merge') |
| 274 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 275 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 276 | # Release the current merge builds |
| 277 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 278 | self.waitUntilSettled() |
| 279 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 280 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 281 | self.waitUntilSettled() |
| 282 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 283 | # All the test builds should be running: |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 284 | # project1 (3) + project2 (3) + project (2) = 8 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 285 | self.assertEqual(len(self.builds), 8) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 286 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 287 | self.worker.release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 288 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 289 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 290 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 291 | self.assertEqual(len(self.history), 11) |
| 292 | self.assertEqual(A.data['status'], 'MERGED') |
| 293 | self.assertEqual(B.data['status'], 'MERGED') |
| 294 | self.assertEqual(C.data['status'], 'MERGED') |
| 295 | self.assertEqual(A.reported, 2) |
| 296 | self.assertEqual(B.reported, 2) |
| 297 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 298 | |
| 299 | def test_failed_change_at_head(self): |
| 300 | "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] | 301 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 302 | self.worker.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 303 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 304 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 305 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 306 | A.addApproval('CRVW', 2) |
| 307 | B.addApproval('CRVW', 2) |
| 308 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 309 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 310 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 311 | |
| 312 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 313 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 314 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 315 | |
| 316 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 317 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 318 | self.assertEqual(len(self.builds), 1) |
| 319 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 320 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 321 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 322 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 323 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 324 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 325 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 326 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 327 | self.waitUntilSettled() |
| 328 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 329 | self.assertEqual(len(self.builds), 6) |
| 330 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 331 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 332 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 333 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 334 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 335 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 336 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 337 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | self.waitUntilSettled() |
| 339 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 340 | # project-test2, project-merge for B |
| 341 | self.assertEqual(len(self.builds), 2) |
| 342 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 344 | self.worker.hold_jobs_in_build = False |
| 345 | self.worker.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 346 | self.waitUntilSettled() |
| 347 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 348 | self.assertEqual(len(self.builds), 0) |
| 349 | self.assertEqual(len(self.history), 15) |
| 350 | self.assertEqual(A.data['status'], 'NEW') |
| 351 | self.assertEqual(B.data['status'], 'MERGED') |
| 352 | self.assertEqual(C.data['status'], 'MERGED') |
| 353 | self.assertEqual(A.reported, 2) |
| 354 | self.assertEqual(B.reported, 2) |
| 355 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 356 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 357 | def test_failed_change_in_middle(self): |
| 358 | "Test a failed change in the middle of the queue" |
| 359 | |
| 360 | self.worker.hold_jobs_in_build = True |
| 361 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 362 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 363 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 364 | A.addApproval('CRVW', 2) |
| 365 | B.addApproval('CRVW', 2) |
| 366 | C.addApproval('CRVW', 2) |
| 367 | |
| 368 | self.worker.addFailTest('project-test1', B) |
| 369 | |
| 370 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 371 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 372 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 373 | |
| 374 | self.waitUntilSettled() |
| 375 | |
| 376 | self.worker.release('.*-merge') |
| 377 | self.waitUntilSettled() |
| 378 | self.worker.release('.*-merge') |
| 379 | self.waitUntilSettled() |
| 380 | self.worker.release('.*-merge') |
| 381 | self.waitUntilSettled() |
| 382 | |
| 383 | self.assertEqual(len(self.builds), 6) |
| 384 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 385 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 386 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 387 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 388 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 389 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 390 | |
| 391 | self.release(self.builds[2]) |
| 392 | self.waitUntilSettled() |
| 393 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 394 | # project-test1 and project-test2 for A |
| 395 | # project-test2 for B |
| 396 | # project-merge for C (without B) |
| 397 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 398 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 399 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 400 | self.worker.release('.*-merge') |
| 401 | self.waitUntilSettled() |
| 402 | |
| 403 | # project-test1 and project-test2 for A |
| 404 | # project-test2 for B |
| 405 | # project-test1 and project-test2 for C |
| 406 | self.assertEqual(len(self.builds), 5) |
| 407 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 408 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 409 | builds = items[0].current_build_set.getBuilds() |
| 410 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 411 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 412 | builds = items[1].current_build_set.getBuilds() |
| 413 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 414 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 415 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 416 | builds = items[2].current_build_set.getBuilds() |
| 417 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 418 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 419 | |
| 420 | self.worker.hold_jobs_in_build = False |
| 421 | self.worker.release() |
| 422 | self.waitUntilSettled() |
| 423 | |
| 424 | self.assertEqual(len(self.builds), 0) |
| 425 | self.assertEqual(len(self.history), 12) |
| 426 | self.assertEqual(A.data['status'], 'MERGED') |
| 427 | self.assertEqual(B.data['status'], 'NEW') |
| 428 | self.assertEqual(C.data['status'], 'MERGED') |
| 429 | self.assertEqual(A.reported, 2) |
| 430 | self.assertEqual(B.reported, 2) |
| 431 | self.assertEqual(C.reported, 2) |
| 432 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 433 | def test_failed_change_at_head_with_queue(self): |
| 434 | "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] | 435 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 436 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 437 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 438 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 439 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 440 | A.addApproval('CRVW', 2) |
| 441 | B.addApproval('CRVW', 2) |
| 442 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 443 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 444 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 445 | |
| 446 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 447 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 448 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 449 | |
| 450 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 451 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 452 | self.assertEqual(len(self.builds), 0) |
| 453 | self.assertEqual(len(queue), 1) |
| 454 | self.assertEqual(queue[0].name, 'build:project-merge') |
| 455 | self.assertTrue(self.job_has_changes(queue[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 456 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 457 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 458 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 459 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 460 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 461 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 462 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 463 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 464 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 465 | self.assertEqual(len(self.builds), 0) |
| 466 | self.assertEqual(len(queue), 6) |
| 467 | self.assertEqual(queue[0].name, 'build:project-test1') |
| 468 | self.assertEqual(queue[1].name, 'build:project-test2') |
| 469 | self.assertEqual(queue[2].name, 'build:project-test1') |
| 470 | self.assertEqual(queue[3].name, 'build:project-test2') |
| 471 | self.assertEqual(queue[4].name, 'build:project-test1') |
| 472 | self.assertEqual(queue[5].name, 'build:project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 473 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 474 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 475 | self.waitUntilSettled() |
| 476 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 477 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 478 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 479 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 480 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 481 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 482 | self.gearman_server.hold_jobs_in_queue = False |
| 483 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 484 | self.waitUntilSettled() |
| 485 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 486 | self.assertEqual(len(self.builds), 0) |
| 487 | self.assertEqual(len(self.history), 11) |
| 488 | self.assertEqual(A.data['status'], 'NEW') |
| 489 | self.assertEqual(B.data['status'], 'MERGED') |
| 490 | self.assertEqual(C.data['status'], 'MERGED') |
| 491 | self.assertEqual(A.reported, 2) |
| 492 | self.assertEqual(B.reported, 2) |
| 493 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 494 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 495 | def test_two_failed_changes_at_head(self): |
| 496 | "Test that changes are reparented correctly if 2 fail at head" |
| 497 | |
| 498 | self.worker.hold_jobs_in_build = True |
| 499 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 500 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 501 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 502 | A.addApproval('CRVW', 2) |
| 503 | B.addApproval('CRVW', 2) |
| 504 | C.addApproval('CRVW', 2) |
| 505 | |
| 506 | self.worker.addFailTest('project-test1', A) |
| 507 | self.worker.addFailTest('project-test1', B) |
| 508 | |
| 509 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 510 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 511 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 512 | self.waitUntilSettled() |
| 513 | |
| 514 | self.worker.release('.*-merge') |
| 515 | self.waitUntilSettled() |
| 516 | self.worker.release('.*-merge') |
| 517 | self.waitUntilSettled() |
| 518 | self.worker.release('.*-merge') |
| 519 | self.waitUntilSettled() |
| 520 | |
| 521 | self.assertEqual(len(self.builds), 6) |
| 522 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 523 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 524 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 525 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 526 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 527 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 528 | |
| 529 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 530 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 531 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 532 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 533 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 534 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 535 | |
| 536 | # Fail change B first |
| 537 | self.release(self.builds[2]) |
| 538 | self.waitUntilSettled() |
| 539 | |
| 540 | # restart of C after B failure |
| 541 | self.worker.release('.*-merge') |
| 542 | self.waitUntilSettled() |
| 543 | |
| 544 | self.assertEqual(len(self.builds), 5) |
| 545 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 546 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 547 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 548 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 549 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 550 | |
| 551 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 552 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 553 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 554 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 555 | self.assertFalse(self.job_has_changes(self.builds[4], B)) |
| 556 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 557 | |
| 558 | # Finish running all passing jobs for change A |
| 559 | self.release(self.builds[1]) |
| 560 | self.waitUntilSettled() |
| 561 | # Fail and report change A |
| 562 | self.release(self.builds[0]) |
| 563 | self.waitUntilSettled() |
| 564 | |
| 565 | # restart of B,C after A failure |
| 566 | self.worker.release('.*-merge') |
| 567 | self.waitUntilSettled() |
| 568 | self.worker.release('.*-merge') |
| 569 | self.waitUntilSettled() |
| 570 | |
| 571 | self.assertEqual(len(self.builds), 4) |
| 572 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 573 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 574 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 575 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 576 | |
| 577 | self.assertFalse(self.job_has_changes(self.builds[1], A)) |
| 578 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
| 579 | self.assertFalse(self.job_has_changes(self.builds[1], C)) |
| 580 | |
| 581 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 582 | # After A failed and B and C restarted, B should be back in |
| 583 | # C's tests because it has not failed yet. |
| 584 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 585 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 586 | |
| 587 | self.worker.hold_jobs_in_build = False |
| 588 | self.worker.release() |
| 589 | self.waitUntilSettled() |
| 590 | |
| 591 | self.assertEqual(len(self.builds), 0) |
| 592 | self.assertEqual(len(self.history), 21) |
| 593 | self.assertEqual(A.data['status'], 'NEW') |
| 594 | self.assertEqual(B.data['status'], 'NEW') |
| 595 | self.assertEqual(C.data['status'], 'MERGED') |
| 596 | self.assertEqual(A.reported, 2) |
| 597 | self.assertEqual(B.reported, 2) |
| 598 | self.assertEqual(C.reported, 2) |
| 599 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 600 | def test_patch_order(self): |
| 601 | "Test that dependent patches are tested in the right order" |
| 602 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 603 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 604 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 605 | A.addApproval('CRVW', 2) |
| 606 | B.addApproval('CRVW', 2) |
| 607 | C.addApproval('CRVW', 2) |
| 608 | |
| 609 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 610 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 611 | M2.setMerged() |
| 612 | M1.setMerged() |
| 613 | |
| 614 | # C -> B -> A -> M1 -> M2 |
| 615 | # M2 is here to make sure it is never queried. If it is, it |
| 616 | # means zuul is walking down the entire history of merged |
| 617 | # changes. |
| 618 | |
| 619 | C.setDependsOn(B, 1) |
| 620 | B.setDependsOn(A, 1) |
| 621 | A.setDependsOn(M1, 1) |
| 622 | M1.setDependsOn(M2, 1) |
| 623 | |
| 624 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 625 | |
| 626 | self.waitUntilSettled() |
| 627 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 628 | self.assertEqual(A.data['status'], 'NEW') |
| 629 | self.assertEqual(B.data['status'], 'NEW') |
| 630 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 631 | |
| 632 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 633 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 634 | |
| 635 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 636 | self.assertEqual(M2.queried, 0) |
| 637 | self.assertEqual(A.data['status'], 'MERGED') |
| 638 | self.assertEqual(B.data['status'], 'MERGED') |
| 639 | self.assertEqual(C.data['status'], 'MERGED') |
| 640 | self.assertEqual(A.reported, 2) |
| 641 | self.assertEqual(B.reported, 2) |
| 642 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 643 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 644 | def test_needed_changes_enqueue(self): |
| 645 | "Test that a needed change is enqueued ahead" |
| 646 | # A Given a git tree like this, if we enqueue |
| 647 | # / \ change C, we should walk up and down the tree |
| 648 | # B G and enqueue changes in the order ABCDEFG. |
| 649 | # /|\ This is also the order that you would get if |
| 650 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 651 | # / the ordering is stable across re-enqueue events. |
| 652 | # D |
| 653 | |
| 654 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 655 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 656 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 657 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 658 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 659 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 660 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 661 | B.setDependsOn(A, 1) |
| 662 | C.setDependsOn(B, 1) |
| 663 | D.setDependsOn(C, 1) |
| 664 | E.setDependsOn(B, 1) |
| 665 | F.setDependsOn(B, 1) |
| 666 | G.setDependsOn(A, 1) |
| 667 | |
| 668 | A.addApproval('CRVW', 2) |
| 669 | B.addApproval('CRVW', 2) |
| 670 | C.addApproval('CRVW', 2) |
| 671 | D.addApproval('CRVW', 2) |
| 672 | E.addApproval('CRVW', 2) |
| 673 | F.addApproval('CRVW', 2) |
| 674 | G.addApproval('CRVW', 2) |
| 675 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 676 | |
| 677 | self.waitUntilSettled() |
| 678 | |
| 679 | self.assertEqual(A.data['status'], 'NEW') |
| 680 | self.assertEqual(B.data['status'], 'NEW') |
| 681 | self.assertEqual(C.data['status'], 'NEW') |
| 682 | self.assertEqual(D.data['status'], 'NEW') |
| 683 | self.assertEqual(E.data['status'], 'NEW') |
| 684 | self.assertEqual(F.data['status'], 'NEW') |
| 685 | self.assertEqual(G.data['status'], 'NEW') |
| 686 | |
| 687 | # We're about to add approvals to changes without adding the |
| 688 | # triggering events to Zuul, so that we can be sure that it is |
| 689 | # enqueing the changes based on dependencies, not because of |
| 690 | # triggering events. Since it will have the changes cached |
| 691 | # already (without approvals), we need to clear the cache |
| 692 | # first. |
| 693 | source = self.sched.layout.pipelines['gate'].source |
| 694 | source.maintainCache([]) |
| 695 | |
| 696 | self.worker.hold_jobs_in_build = True |
| 697 | A.addApproval('APRV', 1) |
| 698 | B.addApproval('APRV', 1) |
| 699 | D.addApproval('APRV', 1) |
| 700 | E.addApproval('APRV', 1) |
| 701 | F.addApproval('APRV', 1) |
| 702 | G.addApproval('APRV', 1) |
| 703 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 704 | |
| 705 | for x in range(8): |
| 706 | self.worker.release('.*-merge') |
| 707 | self.waitUntilSettled() |
| 708 | self.worker.hold_jobs_in_build = False |
| 709 | self.worker.release() |
| 710 | self.waitUntilSettled() |
| 711 | |
| 712 | self.assertEqual(A.data['status'], 'MERGED') |
| 713 | self.assertEqual(B.data['status'], 'MERGED') |
| 714 | self.assertEqual(C.data['status'], 'MERGED') |
| 715 | self.assertEqual(D.data['status'], 'MERGED') |
| 716 | self.assertEqual(E.data['status'], 'MERGED') |
| 717 | self.assertEqual(F.data['status'], 'MERGED') |
| 718 | self.assertEqual(G.data['status'], 'MERGED') |
| 719 | self.assertEqual(A.reported, 2) |
| 720 | self.assertEqual(B.reported, 2) |
| 721 | self.assertEqual(C.reported, 2) |
| 722 | self.assertEqual(D.reported, 2) |
| 723 | self.assertEqual(E.reported, 2) |
| 724 | self.assertEqual(F.reported, 2) |
| 725 | self.assertEqual(G.reported, 2) |
| 726 | self.assertEqual(self.history[6].changes, |
| 727 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 728 | |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 729 | def test_trigger_cache(self): |
| 730 | "Test that the trigger cache operates correctly" |
| 731 | self.worker.hold_jobs_in_build = True |
| 732 | |
| 733 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 734 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 735 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
| 736 | A.addApproval('CRVW', 2) |
| 737 | B.addApproval('CRVW', 2) |
| 738 | |
| 739 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 740 | M1.setMerged() |
| 741 | |
| 742 | B.setDependsOn(A, 1) |
| 743 | A.setDependsOn(M1, 1) |
| 744 | |
| 745 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 746 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 747 | |
| 748 | self.waitUntilSettled() |
| 749 | |
| 750 | for build in self.builds: |
| 751 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 752 | build.release() |
| 753 | self.waitUntilSettled() |
| 754 | for build in self.builds: |
| 755 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 756 | build.release() |
| 757 | self.waitUntilSettled() |
| 758 | |
| 759 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 760 | self.waitUntilSettled() |
| 761 | |
Antoine Musso | f0506fa | 2014-06-03 15:03:38 +0200 | [diff] [blame] | 762 | self.log.debug("len %s" % self.gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 763 | # there should still be changes in the cache |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 764 | self.assertNotEqual(len(self.gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 765 | |
| 766 | self.worker.hold_jobs_in_build = False |
| 767 | self.worker.release() |
| 768 | self.waitUntilSettled() |
| 769 | |
| 770 | self.assertEqual(A.data['status'], 'MERGED') |
| 771 | self.assertEqual(B.data['status'], 'MERGED') |
| 772 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 773 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 774 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 775 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 776 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 777 | # TODO: move to test_gerrit (this is a unit test!) |
| 778 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 779 | source = self.sched.layout.pipelines['gate'].source |
| 780 | a = source._getChange(1, 2) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 781 | mgr = self.sched.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 782 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 783 | |
| 784 | A.addApproval('CRVW', 2) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 785 | a = source._getChange(1, 2, refresh=True) |
| 786 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 787 | |
| 788 | A.addApproval('APRV', 1) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 789 | a = source._getChange(1, 2, refresh=True) |
| 790 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
| 791 | source.maintainCache([]) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 792 | |
| 793 | def test_build_configuration(self): |
| 794 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 795 | |
| 796 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 797 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 798 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 799 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 800 | A.addApproval('CRVW', 2) |
| 801 | B.addApproval('CRVW', 2) |
| 802 | C.addApproval('CRVW', 2) |
| 803 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 804 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 805 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 806 | self.waitUntilSettled() |
| 807 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 808 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 809 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 810 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 811 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 812 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 813 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 814 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 815 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 816 | self.gearman_server.hold_jobs_in_queue = False |
| 817 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 818 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 819 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 820 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 821 | repo = git.Repo(path) |
| 822 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 823 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 824 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 825 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 826 | |
| 827 | def test_build_configuration_conflict(self): |
| 828 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 829 | |
| 830 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 831 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 832 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 833 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 834 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 835 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 836 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 837 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 838 | 'master', 'C') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 839 | A.addApproval('CRVW', 2) |
| 840 | B.addApproval('CRVW', 2) |
| 841 | C.addApproval('CRVW', 2) |
| 842 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 843 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 844 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 845 | self.waitUntilSettled() |
| 846 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 847 | self.assertEqual(A.reported, 1) |
| 848 | self.assertEqual(B.reported, 1) |
| 849 | self.assertEqual(C.reported, 1) |
| 850 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 851 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 852 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 853 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 854 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 855 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 856 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 857 | |
| 858 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 859 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 860 | self.gearman_server.hold_jobs_in_queue = False |
| 861 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 862 | self.waitUntilSettled() |
| 863 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 864 | self.assertEqual(A.data['status'], 'MERGED') |
| 865 | self.assertEqual(B.data['status'], 'NEW') |
| 866 | self.assertEqual(C.data['status'], 'MERGED') |
| 867 | self.assertEqual(A.reported, 2) |
| 868 | self.assertEqual(B.reported, 2) |
| 869 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 870 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 871 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 872 | def test_post(self): |
| 873 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 874 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 875 | e = { |
| 876 | "type": "ref-updated", |
| 877 | "submitter": { |
| 878 | "name": "User Name", |
| 879 | }, |
| 880 | "refUpdate": { |
| 881 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 882 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 883 | "refName": "master", |
| 884 | "project": "org/project", |
| 885 | } |
| 886 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 887 | self.fake_gerrit.addEvent(e) |
| 888 | self.waitUntilSettled() |
| 889 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 890 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 891 | self.assertEqual(len(self.history), 1) |
| 892 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 893 | |
| 894 | def test_build_configuration_branch(self): |
| 895 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 896 | |
| 897 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 898 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 899 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 900 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
| 901 | A.addApproval('CRVW', 2) |
| 902 | B.addApproval('CRVW', 2) |
| 903 | C.addApproval('CRVW', 2) |
| 904 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 905 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 906 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 907 | self.waitUntilSettled() |
| 908 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 909 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 910 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 911 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 912 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 913 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 914 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 915 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 916 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 917 | self.gearman_server.hold_jobs_in_queue = False |
| 918 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 919 | self.waitUntilSettled() |
| 920 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 921 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 922 | repo = git.Repo(path) |
| 923 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 924 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 925 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 926 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 927 | |
| 928 | def test_build_configuration_branch_interaction(self): |
| 929 | "Test that switching between branches works" |
| 930 | self.test_build_configuration() |
| 931 | self.test_build_configuration_branch() |
| 932 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 933 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 934 | repo = git.Repo(path) |
| 935 | repo.heads.master.commit = repo.commit('init') |
| 936 | self.test_build_configuration() |
| 937 | |
| 938 | def test_build_configuration_multi_branch(self): |
| 939 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 940 | |
| 941 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 942 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 943 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 944 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 945 | A.addApproval('CRVW', 2) |
| 946 | B.addApproval('CRVW', 2) |
| 947 | C.addApproval('CRVW', 2) |
| 948 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 949 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 950 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 951 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 952 | queue = self.gearman_server.getQueue() |
| 953 | job_A = None |
| 954 | for job in queue: |
| 955 | if 'project-merge' in job.name: |
| 956 | job_A = job |
| 957 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 958 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 959 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 960 | 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] | 961 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 962 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 963 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 964 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 965 | job_B = None |
| 966 | for job in queue: |
| 967 | if 'project-merge' in job.name: |
| 968 | job_B = job |
| 969 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 970 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 971 | 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] | 972 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 973 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 974 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 975 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 976 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 977 | for job in queue: |
| 978 | if 'project-merge' in job.name: |
| 979 | job_C = job |
| 980 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 981 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 982 | 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] | 983 | 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] | 984 | self.gearman_server.hold_jobs_in_queue = False |
| 985 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 986 | self.waitUntilSettled() |
| 987 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 988 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 989 | repo = git.Repo(path) |
| 990 | |
| 991 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 992 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 993 | 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] | 994 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 995 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 996 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 997 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 998 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 999 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1000 | |
| 1001 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1002 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1003 | 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] | 1004 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1005 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1006 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1007 | self.assertEqual(repo_shas[0], commit_B) |
| 1008 | |
| 1009 | repo_messages = [c.message.strip() |
| 1010 | for c in repo.iter_commits(ref_A)] |
| 1011 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1012 | repo_messages.reverse() |
| 1013 | correct_messages = ['initial commit', 'A-1'] |
| 1014 | self.assertEqual(repo_messages, correct_messages) |
| 1015 | self.assertEqual(repo_shas[0], commit_A) |
| 1016 | |
| 1017 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1018 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1019 | |
| 1020 | def test_one_job_project(self): |
| 1021 | "Test that queueing works with one job" |
| 1022 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1023 | 'master', 'A') |
| 1024 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1025 | 'master', 'B') |
| 1026 | A.addApproval('CRVW', 2) |
| 1027 | B.addApproval('CRVW', 2) |
| 1028 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1029 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1030 | self.waitUntilSettled() |
| 1031 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1032 | self.assertEqual(A.data['status'], 'MERGED') |
| 1033 | self.assertEqual(A.reported, 2) |
| 1034 | self.assertEqual(B.data['status'], 'MERGED') |
| 1035 | self.assertEqual(B.reported, 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1036 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1037 | def test_job_from_templates_launched(self): |
| 1038 | "Test whether a job generated via a template can be launched" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1039 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1040 | A = self.fake_gerrit.addFakeChange( |
| 1041 | 'org/templated-project', 'master', 'A') |
| 1042 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1043 | self.waitUntilSettled() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1044 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1045 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1046 | 'SUCCESS') |
| 1047 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1048 | 'SUCCESS') |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1049 | |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1050 | def test_layered_templates(self): |
| 1051 | "Test whether a job generated via a template can be launched" |
| 1052 | |
| 1053 | A = self.fake_gerrit.addFakeChange( |
| 1054 | 'org/layered-project', 'master', 'A') |
| 1055 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1056 | self.waitUntilSettled() |
| 1057 | |
| 1058 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1059 | 'SUCCESS') |
| 1060 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1061 | 'SUCCESS') |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 1062 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 1063 | ).result, 'SUCCESS') |
| 1064 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 1065 | ).result, 'SUCCESS') |
James E. Blair | 12a92b1 | 2014-03-26 11:54:53 -0700 | [diff] [blame] | 1066 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 1067 | ).result, 'SUCCESS') |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1068 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 1069 | 'SUCCESS') |
| 1070 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1071 | def test_dependent_changes_dequeue(self): |
| 1072 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1073 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1074 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1075 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1076 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1077 | A.addApproval('CRVW', 2) |
| 1078 | B.addApproval('CRVW', 2) |
| 1079 | C.addApproval('CRVW', 2) |
| 1080 | |
| 1081 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1082 | M1.setMerged() |
| 1083 | |
| 1084 | # C -> B -> A -> M1 |
| 1085 | |
| 1086 | C.setDependsOn(B, 1) |
| 1087 | B.setDependsOn(A, 1) |
| 1088 | A.setDependsOn(M1, 1) |
| 1089 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1090 | self.worker.addFailTest('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1091 | |
| 1092 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1093 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1094 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1095 | |
| 1096 | self.waitUntilSettled() |
| 1097 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1098 | self.assertEqual(A.data['status'], 'NEW') |
| 1099 | self.assertEqual(A.reported, 2) |
| 1100 | self.assertEqual(B.data['status'], 'NEW') |
| 1101 | self.assertEqual(B.reported, 2) |
| 1102 | self.assertEqual(C.data['status'], 'NEW') |
| 1103 | self.assertEqual(C.reported, 2) |
| 1104 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1105 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1106 | def test_failing_dependent_changes(self): |
| 1107 | "Test that failing dependent patches are taken out of stream" |
| 1108 | self.worker.hold_jobs_in_build = True |
| 1109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1110 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1111 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1112 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1113 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 1114 | A.addApproval('CRVW', 2) |
| 1115 | B.addApproval('CRVW', 2) |
| 1116 | C.addApproval('CRVW', 2) |
| 1117 | D.addApproval('CRVW', 2) |
| 1118 | E.addApproval('CRVW', 2) |
| 1119 | |
| 1120 | # E, D -> C -> B, A |
| 1121 | |
| 1122 | D.setDependsOn(C, 1) |
| 1123 | C.setDependsOn(B, 1) |
| 1124 | |
| 1125 | self.worker.addFailTest('project-test1', B) |
| 1126 | |
| 1127 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1128 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 1129 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1130 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1131 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 1132 | |
| 1133 | self.waitUntilSettled() |
| 1134 | self.worker.release('.*-merge') |
| 1135 | self.waitUntilSettled() |
| 1136 | self.worker.release('.*-merge') |
| 1137 | self.waitUntilSettled() |
| 1138 | self.worker.release('.*-merge') |
| 1139 | self.waitUntilSettled() |
| 1140 | self.worker.release('.*-merge') |
| 1141 | self.waitUntilSettled() |
| 1142 | self.worker.release('.*-merge') |
| 1143 | self.waitUntilSettled() |
| 1144 | |
| 1145 | self.worker.hold_jobs_in_build = False |
| 1146 | for build in self.builds: |
| 1147 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1148 | build.release() |
| 1149 | self.waitUntilSettled() |
| 1150 | |
| 1151 | self.worker.release() |
| 1152 | self.waitUntilSettled() |
| 1153 | |
| 1154 | self.assertEqual(A.data['status'], 'MERGED') |
| 1155 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1156 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1157 | self.assertEqual(B.data['status'], 'NEW') |
| 1158 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1159 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1160 | self.assertEqual(C.data['status'], 'NEW') |
| 1161 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1162 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1163 | self.assertEqual(D.data['status'], 'NEW') |
| 1164 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1165 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1166 | self.assertEqual(E.data['status'], 'MERGED') |
| 1167 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1168 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1169 | self.assertEqual(len(self.history), 18) |
| 1170 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1171 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1172 | "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] | 1173 | # If it's dequeued more than once, we should see extra |
| 1174 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1175 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1176 | self.worker.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1177 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1178 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1179 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 1180 | A.addApproval('CRVW', 2) |
| 1181 | B.addApproval('CRVW', 2) |
| 1182 | C.addApproval('CRVW', 2) |
| 1183 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1184 | self.worker.addFailTest('project1-test1', A) |
| 1185 | self.worker.addFailTest('project1-test2', A) |
| 1186 | self.worker.addFailTest('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1187 | |
| 1188 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1189 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1190 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1191 | |
| 1192 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1193 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1194 | self.assertEqual(len(self.builds), 1) |
| 1195 | self.assertEqual(self.builds[0].name, 'project1-merge') |
| 1196 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1197 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1198 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1199 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1200 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1201 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1202 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1203 | self.waitUntilSettled() |
| 1204 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1205 | self.assertEqual(len(self.builds), 9) |
| 1206 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 1207 | self.assertEqual(self.builds[1].name, 'project1-test2') |
| 1208 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
| 1209 | self.assertEqual(self.builds[3].name, 'project1-test1') |
| 1210 | self.assertEqual(self.builds[4].name, 'project1-test2') |
| 1211 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
| 1212 | self.assertEqual(self.builds[6].name, 'project1-test1') |
| 1213 | self.assertEqual(self.builds[7].name, 'project1-test2') |
| 1214 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1215 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1216 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1217 | self.waitUntilSettled() |
| 1218 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1219 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1220 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1221 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1222 | self.worker.hold_jobs_in_build = False |
| 1223 | self.worker.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1224 | self.waitUntilSettled() |
| 1225 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1226 | self.assertEqual(len(self.builds), 0) |
| 1227 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1228 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1229 | self.assertEqual(A.data['status'], 'NEW') |
| 1230 | self.assertEqual(B.data['status'], 'MERGED') |
| 1231 | self.assertEqual(C.data['status'], 'MERGED') |
| 1232 | self.assertEqual(A.reported, 2) |
| 1233 | self.assertEqual(B.reported, 2) |
| 1234 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1235 | |
| 1236 | def test_nonvoting_job(self): |
| 1237 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1238 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1239 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1240 | 'master', 'A') |
| 1241 | A.addApproval('CRVW', 2) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1242 | self.worker.addFailTest('nonvoting-project-test2', A) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1243 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1244 | |
| 1245 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1246 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1247 | self.assertEqual(A.data['status'], 'MERGED') |
| 1248 | self.assertEqual(A.reported, 2) |
| 1249 | self.assertEqual( |
| 1250 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1251 | 'SUCCESS') |
| 1252 | self.assertEqual( |
| 1253 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1254 | 'SUCCESS') |
| 1255 | self.assertEqual( |
| 1256 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1257 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1258 | |
| 1259 | def test_check_queue_success(self): |
| 1260 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1261 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1262 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1263 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1264 | |
| 1265 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1266 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1267 | self.assertEqual(A.data['status'], 'NEW') |
| 1268 | self.assertEqual(A.reported, 1) |
| 1269 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1270 | 'SUCCESS') |
| 1271 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1272 | 'SUCCESS') |
| 1273 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1274 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1275 | |
| 1276 | def test_check_queue_failure(self): |
| 1277 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1278 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1280 | self.worker.addFailTest('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1281 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1282 | |
| 1283 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1284 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1285 | self.assertEqual(A.data['status'], 'NEW') |
| 1286 | self.assertEqual(A.reported, 1) |
| 1287 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1288 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1289 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1290 | 'SUCCESS') |
| 1291 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1292 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1293 | |
| 1294 | def test_dependent_behind_dequeue(self): |
| 1295 | "test that dependent changes behind dequeued changes work" |
| 1296 | # This complicated test is a reproduction of a real life bug |
| 1297 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1298 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1299 | self.worker.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1300 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1301 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1302 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1303 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1304 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1305 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1306 | D.setDependsOn(C, 1) |
| 1307 | E.setDependsOn(D, 1) |
| 1308 | A.addApproval('CRVW', 2) |
| 1309 | B.addApproval('CRVW', 2) |
| 1310 | C.addApproval('CRVW', 2) |
| 1311 | D.addApproval('CRVW', 2) |
| 1312 | E.addApproval('CRVW', 2) |
| 1313 | F.addApproval('CRVW', 2) |
| 1314 | |
| 1315 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1316 | |
| 1317 | # Change object re-use in the gerrit trigger is hidden if |
| 1318 | # changes are added in quick succession; waiting makes it more |
| 1319 | # like real life. |
| 1320 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1321 | self.waitUntilSettled() |
| 1322 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1323 | self.waitUntilSettled() |
| 1324 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1325 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1326 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1327 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1328 | self.waitUntilSettled() |
| 1329 | |
| 1330 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1331 | self.waitUntilSettled() |
| 1332 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 1333 | self.waitUntilSettled() |
| 1334 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 1335 | self.waitUntilSettled() |
| 1336 | self.fake_gerrit.addEvent(F.addApproval('APRV', 1)) |
| 1337 | self.waitUntilSettled() |
| 1338 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1339 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1340 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1341 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1342 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1343 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1344 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1345 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1346 | self.waitUntilSettled() |
| 1347 | |
| 1348 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1349 | |
| 1350 | # Grab pointers to the jobs we want to release before |
| 1351 | # releasing any, because list indexes may change as |
| 1352 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1353 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1354 | a.release() |
| 1355 | b.release() |
| 1356 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1357 | self.waitUntilSettled() |
| 1358 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1359 | self.worker.hold_jobs_in_build = False |
| 1360 | self.worker.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1361 | self.waitUntilSettled() |
| 1362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1363 | self.assertEqual(A.data['status'], 'NEW') |
| 1364 | self.assertEqual(B.data['status'], 'MERGED') |
| 1365 | self.assertEqual(C.data['status'], 'MERGED') |
| 1366 | self.assertEqual(D.data['status'], 'MERGED') |
| 1367 | self.assertEqual(E.data['status'], 'MERGED') |
| 1368 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1369 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1370 | self.assertEqual(A.reported, 2) |
| 1371 | self.assertEqual(B.reported, 2) |
| 1372 | self.assertEqual(C.reported, 2) |
| 1373 | self.assertEqual(D.reported, 2) |
| 1374 | self.assertEqual(E.reported, 2) |
| 1375 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1376 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1377 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1378 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1379 | |
| 1380 | def test_merger_repack(self): |
| 1381 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1382 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1383 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1384 | A.addApproval('CRVW', 2) |
| 1385 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1386 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1387 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1388 | 'SUCCESS') |
| 1389 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1390 | 'SUCCESS') |
| 1391 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1392 | 'SUCCESS') |
| 1393 | self.assertEqual(A.data['status'], 'MERGED') |
| 1394 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1395 | self.assertEmptyQueues() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 1396 | self.worker.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1397 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1398 | path = os.path.join(self.git_root, "org/project") |
| 1399 | print repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1400 | |
| 1401 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1402 | A.addApproval('CRVW', 2) |
| 1403 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1404 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1405 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1406 | 'SUCCESS') |
| 1407 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1408 | 'SUCCESS') |
| 1409 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1410 | 'SUCCESS') |
| 1411 | self.assertEqual(A.data['status'], 'MERGED') |
| 1412 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1413 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1414 | def test_merger_repack_large_change(self): |
| 1415 | "Test that the merger works with large changes after a repack" |
| 1416 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1417 | # This test assumes the repo is already cloned; make sure it is |
| 1418 | url = self.sched.triggers['gerrit'].getGitUrl( |
| 1419 | self.sched.layout.projects['org/project1']) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1420 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1421 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1422 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1423 | path = os.path.join(self.upstream_root, "org/project1") |
| 1424 | print repack_repo(path) |
| 1425 | path = os.path.join(self.git_root, "org/project1") |
| 1426 | print repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1427 | |
| 1428 | A.addApproval('CRVW', 2) |
| 1429 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1430 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1431 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 1432 | 'SUCCESS') |
| 1433 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 1434 | 'SUCCESS') |
| 1435 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 1436 | 'SUCCESS') |
| 1437 | self.assertEqual(A.data['status'], 'MERGED') |
| 1438 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1439 | |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1440 | def test_nonexistent_job(self): |
| 1441 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1442 | # Set to the state immediately after a restart |
| 1443 | self.resetGearmanServer() |
| 1444 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1445 | |
| 1446 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1447 | A.addApproval('CRVW', 2) |
| 1448 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1449 | # There may be a thread about to report a lost change |
| 1450 | while A.reported < 2: |
| 1451 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1452 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1453 | self.assertFalse(job_names) |
| 1454 | self.assertEqual(A.data['status'], 'NEW') |
| 1455 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1456 | self.assertEmptyQueues() |
| 1457 | |
| 1458 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1459 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1460 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1461 | A.addApproval('CRVW', 2) |
| 1462 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1463 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1464 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1465 | 'SUCCESS') |
| 1466 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1467 | 'SUCCESS') |
| 1468 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1469 | 'SUCCESS') |
| 1470 | self.assertEqual(A.data['status'], 'MERGED') |
| 1471 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1472 | |
| 1473 | def test_single_nonexistent_post_job(self): |
| 1474 | "Test launching a single post job that doesn't exist" |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1475 | e = { |
| 1476 | "type": "ref-updated", |
| 1477 | "submitter": { |
| 1478 | "name": "User Name", |
| 1479 | }, |
| 1480 | "refUpdate": { |
| 1481 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1482 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1483 | "refName": "master", |
| 1484 | "project": "org/project", |
| 1485 | } |
| 1486 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1487 | # Set to the state immediately after a restart |
| 1488 | self.resetGearmanServer() |
| 1489 | self.launcher.negative_function_cache_ttl = 0 |
| 1490 | |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1491 | self.fake_gerrit.addEvent(e) |
| 1492 | self.waitUntilSettled() |
| 1493 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1494 | self.assertEqual(len(self.history), 0) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1495 | |
| 1496 | def test_new_patchset_dequeues_old(self): |
| 1497 | "Test that a new patchset causes the old to be dequeued" |
| 1498 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1499 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1500 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1501 | M.setMerged() |
| 1502 | |
| 1503 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1504 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1505 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1506 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1507 | A.addApproval('CRVW', 2) |
| 1508 | B.addApproval('CRVW', 2) |
| 1509 | C.addApproval('CRVW', 2) |
| 1510 | D.addApproval('CRVW', 2) |
| 1511 | |
| 1512 | C.setDependsOn(B, 1) |
| 1513 | B.setDependsOn(A, 1) |
| 1514 | A.setDependsOn(M, 1) |
| 1515 | |
| 1516 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1517 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1518 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1519 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 1520 | self.waitUntilSettled() |
| 1521 | |
| 1522 | B.addPatchset() |
| 1523 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1524 | self.waitUntilSettled() |
| 1525 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1526 | self.worker.hold_jobs_in_build = False |
| 1527 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1528 | self.waitUntilSettled() |
| 1529 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1530 | self.assertEqual(A.data['status'], 'MERGED') |
| 1531 | self.assertEqual(A.reported, 2) |
| 1532 | self.assertEqual(B.data['status'], 'NEW') |
| 1533 | self.assertEqual(B.reported, 2) |
| 1534 | self.assertEqual(C.data['status'], 'NEW') |
| 1535 | self.assertEqual(C.reported, 2) |
| 1536 | self.assertEqual(D.data['status'], 'MERGED') |
| 1537 | self.assertEqual(D.reported, 2) |
| 1538 | 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] | 1539 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1540 | def test_new_patchset_check(self): |
| 1541 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1542 | |
| 1543 | self.worker.hold_jobs_in_build = True |
| 1544 | |
| 1545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1546 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1547 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1548 | |
| 1549 | # Add two git-dependent changes |
| 1550 | B.setDependsOn(A, 1) |
| 1551 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1552 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1553 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1554 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1555 | |
| 1556 | # A live item, and a non-live/live pair |
| 1557 | items = check_pipeline.getAllItems() |
| 1558 | self.assertEqual(len(items), 3) |
| 1559 | |
| 1560 | self.assertEqual(items[0].change.number, '1') |
| 1561 | self.assertEqual(items[0].change.patchset, '1') |
| 1562 | self.assertFalse(items[0].live) |
| 1563 | |
| 1564 | self.assertEqual(items[1].change.number, '2') |
| 1565 | self.assertEqual(items[1].change.patchset, '1') |
| 1566 | self.assertTrue(items[1].live) |
| 1567 | |
| 1568 | self.assertEqual(items[2].change.number, '1') |
| 1569 | self.assertEqual(items[2].change.patchset, '1') |
| 1570 | self.assertTrue(items[2].live) |
| 1571 | |
| 1572 | # Add a new patchset to A |
| 1573 | A.addPatchset() |
| 1574 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1575 | self.waitUntilSettled() |
| 1576 | |
| 1577 | # The live copy of A,1 should be gone, but the non-live and B |
| 1578 | # should continue, and we should have a new A,2 |
| 1579 | items = check_pipeline.getAllItems() |
| 1580 | self.assertEqual(len(items), 3) |
| 1581 | |
| 1582 | self.assertEqual(items[0].change.number, '1') |
| 1583 | self.assertEqual(items[0].change.patchset, '1') |
| 1584 | self.assertFalse(items[0].live) |
| 1585 | |
| 1586 | self.assertEqual(items[1].change.number, '2') |
| 1587 | self.assertEqual(items[1].change.patchset, '1') |
| 1588 | self.assertTrue(items[1].live) |
| 1589 | |
| 1590 | self.assertEqual(items[2].change.number, '1') |
| 1591 | self.assertEqual(items[2].change.patchset, '2') |
| 1592 | self.assertTrue(items[2].live) |
| 1593 | |
| 1594 | # Add a new patchset to B |
| 1595 | B.addPatchset() |
| 1596 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1597 | self.waitUntilSettled() |
| 1598 | |
| 1599 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1600 | # but we should have a new B,2 (still based on A,1) |
| 1601 | items = check_pipeline.getAllItems() |
| 1602 | self.assertEqual(len(items), 3) |
| 1603 | |
| 1604 | self.assertEqual(items[0].change.number, '1') |
| 1605 | self.assertEqual(items[0].change.patchset, '2') |
| 1606 | self.assertTrue(items[0].live) |
| 1607 | |
| 1608 | self.assertEqual(items[1].change.number, '1') |
| 1609 | self.assertEqual(items[1].change.patchset, '1') |
| 1610 | self.assertFalse(items[1].live) |
| 1611 | |
| 1612 | self.assertEqual(items[2].change.number, '2') |
| 1613 | self.assertEqual(items[2].change.patchset, '2') |
| 1614 | self.assertTrue(items[2].live) |
| 1615 | |
| 1616 | self.builds[0].release() |
| 1617 | self.waitUntilSettled() |
| 1618 | self.builds[0].release() |
| 1619 | self.waitUntilSettled() |
| 1620 | self.worker.hold_jobs_in_build = False |
| 1621 | self.worker.release() |
| 1622 | self.waitUntilSettled() |
| 1623 | |
| 1624 | self.assertEqual(A.reported, 1) |
| 1625 | self.assertEqual(B.reported, 1) |
| 1626 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1627 | self.assertEqual(self.history[0].changes, '1,1') |
| 1628 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1629 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1630 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1631 | self.assertEqual(self.history[2].changes, '1,2') |
| 1632 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1633 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1634 | |
| 1635 | def test_abandoned_gate(self): |
| 1636 | "Test that an abandoned change is dequeued from gate" |
| 1637 | |
| 1638 | self.worker.hold_jobs_in_build = True |
| 1639 | |
| 1640 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1641 | A.addApproval('CRVW', 2) |
| 1642 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1643 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1644 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1645 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1646 | |
| 1647 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1648 | self.waitUntilSettled() |
| 1649 | |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1650 | self.worker.release('.*-merge') |
| 1651 | self.waitUntilSettled() |
| 1652 | |
| 1653 | self.assertEqual(len(self.builds), 0, "No job running") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1654 | self.assertEqual(len(self.history), 1, "Only one build in history") |
| 1655 | self.assertEqual(self.history[0].result, 'ABORTED', |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1656 | "Build should have been aborted") |
| 1657 | self.assertEqual(A.reported, 1, |
| 1658 | "Abandoned gate change should report only start") |
| 1659 | |
| 1660 | def test_abandoned_check(self): |
| 1661 | "Test that an abandoned change is dequeued from check" |
| 1662 | |
| 1663 | self.worker.hold_jobs_in_build = True |
| 1664 | |
| 1665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1666 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1667 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1668 | |
| 1669 | # Add two git-dependent changes |
| 1670 | B.setDependsOn(A, 1) |
| 1671 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1672 | self.waitUntilSettled() |
| 1673 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1674 | self.waitUntilSettled() |
| 1675 | # A live item, and a non-live/live pair |
| 1676 | items = check_pipeline.getAllItems() |
| 1677 | self.assertEqual(len(items), 3) |
| 1678 | |
| 1679 | self.assertEqual(items[0].change.number, '1') |
| 1680 | self.assertFalse(items[0].live) |
| 1681 | |
| 1682 | self.assertEqual(items[1].change.number, '2') |
| 1683 | self.assertTrue(items[1].live) |
| 1684 | |
| 1685 | self.assertEqual(items[2].change.number, '1') |
| 1686 | self.assertTrue(items[2].live) |
| 1687 | |
| 1688 | # Abandon A |
| 1689 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1690 | self.waitUntilSettled() |
| 1691 | |
| 1692 | # The live copy of A should be gone, but the non-live and B |
| 1693 | # should continue |
| 1694 | items = check_pipeline.getAllItems() |
| 1695 | self.assertEqual(len(items), 2) |
| 1696 | |
| 1697 | self.assertEqual(items[0].change.number, '1') |
| 1698 | self.assertFalse(items[0].live) |
| 1699 | |
| 1700 | self.assertEqual(items[1].change.number, '2') |
| 1701 | self.assertTrue(items[1].live) |
| 1702 | |
| 1703 | self.worker.hold_jobs_in_build = False |
| 1704 | self.worker.release() |
| 1705 | self.waitUntilSettled() |
| 1706 | |
| 1707 | self.assertEqual(len(self.history), 4) |
| 1708 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1709 | 'Build should have been aborted') |
| 1710 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1711 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1712 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1713 | def test_zuul_url_return(self): |
| 1714 | "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] | 1715 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1716 | self.worker.hold_jobs_in_build = True |
| 1717 | |
| 1718 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1719 | A.addApproval('CRVW', 2) |
| 1720 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1721 | self.waitUntilSettled() |
| 1722 | |
| 1723 | self.assertEqual(len(self.builds), 1) |
| 1724 | for build in self.builds: |
| 1725 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1726 | |
| 1727 | self.worker.hold_jobs_in_build = False |
| 1728 | self.worker.release() |
| 1729 | self.waitUntilSettled() |
| 1730 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1731 | def test_new_patchset_dequeues_old_on_head(self): |
| 1732 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1733 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1734 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1735 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1736 | M.setMerged() |
| 1737 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1738 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1739 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1740 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1741 | A.addApproval('CRVW', 2) |
| 1742 | B.addApproval('CRVW', 2) |
| 1743 | C.addApproval('CRVW', 2) |
| 1744 | D.addApproval('CRVW', 2) |
| 1745 | |
| 1746 | C.setDependsOn(B, 1) |
| 1747 | B.setDependsOn(A, 1) |
| 1748 | A.setDependsOn(M, 1) |
| 1749 | |
| 1750 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1751 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1752 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1753 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 1754 | self.waitUntilSettled() |
| 1755 | |
| 1756 | A.addPatchset() |
| 1757 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1758 | self.waitUntilSettled() |
| 1759 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1760 | self.worker.hold_jobs_in_build = False |
| 1761 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1762 | self.waitUntilSettled() |
| 1763 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1764 | self.assertEqual(A.data['status'], 'NEW') |
| 1765 | self.assertEqual(A.reported, 2) |
| 1766 | self.assertEqual(B.data['status'], 'NEW') |
| 1767 | self.assertEqual(B.reported, 2) |
| 1768 | self.assertEqual(C.data['status'], 'NEW') |
| 1769 | self.assertEqual(C.reported, 2) |
| 1770 | self.assertEqual(D.data['status'], 'MERGED') |
| 1771 | self.assertEqual(D.reported, 2) |
| 1772 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1773 | |
| 1774 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1775 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1776 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1777 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1778 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1779 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1780 | A.addApproval('CRVW', 2) |
| 1781 | B.addApproval('CRVW', 2) |
| 1782 | C.addApproval('CRVW', 2) |
| 1783 | |
| 1784 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1785 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1786 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1787 | self.waitUntilSettled() |
| 1788 | |
| 1789 | B.addPatchset() |
| 1790 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1791 | self.waitUntilSettled() |
| 1792 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1793 | self.worker.hold_jobs_in_build = False |
| 1794 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1795 | self.waitUntilSettled() |
| 1796 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1797 | self.assertEqual(A.data['status'], 'MERGED') |
| 1798 | self.assertEqual(A.reported, 2) |
| 1799 | self.assertEqual(B.data['status'], 'NEW') |
| 1800 | self.assertEqual(B.reported, 2) |
| 1801 | self.assertEqual(C.data['status'], 'MERGED') |
| 1802 | self.assertEqual(C.reported, 2) |
| 1803 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1804 | |
| 1805 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1806 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1807 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1808 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1809 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1810 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1811 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1812 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1813 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1814 | self.waitUntilSettled() |
| 1815 | |
| 1816 | B.addPatchset() |
| 1817 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1818 | self.waitUntilSettled() |
| 1819 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1820 | self.worker.hold_jobs_in_build = False |
| 1821 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1822 | self.waitUntilSettled() |
| 1823 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1824 | self.assertEqual(A.data['status'], 'NEW') |
| 1825 | self.assertEqual(A.reported, 1) |
| 1826 | self.assertEqual(B.data['status'], 'NEW') |
| 1827 | self.assertEqual(B.reported, 1) |
| 1828 | self.assertEqual(C.data['status'], 'NEW') |
| 1829 | self.assertEqual(C.reported, 1) |
| 1830 | self.assertEqual(len(self.history), 10) |
| 1831 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1832 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1833 | def test_noop_job(self): |
| 1834 | "Test that the internal noop job works" |
| 1835 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
| 1836 | A.addApproval('CRVW', 2) |
| 1837 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1838 | self.waitUntilSettled() |
| 1839 | |
| 1840 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1841 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1842 | self.assertEqual(len(self.history), 0) |
| 1843 | self.assertEqual(A.data['status'], 'MERGED') |
| 1844 | self.assertEqual(A.reported, 2) |
| 1845 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1846 | def test_zuul_refs(self): |
| 1847 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1848 | self.worker.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1849 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1850 | M1.setMerged() |
| 1851 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1852 | M2.setMerged() |
| 1853 | |
| 1854 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1855 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1856 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1857 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1858 | A.addApproval('CRVW', 2) |
| 1859 | B.addApproval('CRVW', 2) |
| 1860 | C.addApproval('CRVW', 2) |
| 1861 | D.addApproval('CRVW', 2) |
| 1862 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1863 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1864 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1865 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 1866 | |
| 1867 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1868 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1869 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1870 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1871 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1872 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1873 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1874 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1875 | self.waitUntilSettled() |
| 1876 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1877 | a_zref = b_zref = c_zref = d_zref = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1878 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1879 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1880 | a_zref = x.parameters['ZUUL_REF'] |
| 1881 | if x.parameters['ZUUL_CHANGE'] == '4': |
| 1882 | b_zref = x.parameters['ZUUL_REF'] |
| 1883 | if x.parameters['ZUUL_CHANGE'] == '5': |
| 1884 | c_zref = x.parameters['ZUUL_REF'] |
| 1885 | if x.parameters['ZUUL_CHANGE'] == '6': |
| 1886 | d_zref = x.parameters['ZUUL_REF'] |
| 1887 | |
| 1888 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1889 | self.assertIsNotNone(a_zref) |
| 1890 | self.assertIsNotNone(b_zref) |
| 1891 | self.assertIsNotNone(c_zref) |
| 1892 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1893 | |
| 1894 | # And they should all be different |
| 1895 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1896 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1897 | |
| 1898 | # a ref should have a, not b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1899 | self.assertTrue(self.ref_has_change(a_zref, A)) |
| 1900 | self.assertFalse(self.ref_has_change(a_zref, B)) |
| 1901 | self.assertFalse(self.ref_has_change(a_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1902 | |
| 1903 | # b ref should have a and b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1904 | self.assertTrue(self.ref_has_change(b_zref, A)) |
| 1905 | self.assertTrue(self.ref_has_change(b_zref, B)) |
| 1906 | self.assertFalse(self.ref_has_change(b_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1907 | |
| 1908 | # c ref should have a and b in 1, c in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1909 | self.assertTrue(self.ref_has_change(c_zref, A)) |
| 1910 | self.assertTrue(self.ref_has_change(c_zref, B)) |
| 1911 | self.assertTrue(self.ref_has_change(c_zref, C)) |
| 1912 | self.assertFalse(self.ref_has_change(c_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1913 | |
| 1914 | # d ref should have a and b in 1, c and d in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1915 | self.assertTrue(self.ref_has_change(d_zref, A)) |
| 1916 | self.assertTrue(self.ref_has_change(d_zref, B)) |
| 1917 | self.assertTrue(self.ref_has_change(d_zref, C)) |
| 1918 | self.assertTrue(self.ref_has_change(d_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1919 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1920 | self.worker.hold_jobs_in_build = False |
| 1921 | self.worker.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1922 | self.waitUntilSettled() |
| 1923 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1924 | self.assertEqual(A.data['status'], 'MERGED') |
| 1925 | self.assertEqual(A.reported, 2) |
| 1926 | self.assertEqual(B.data['status'], 'MERGED') |
| 1927 | self.assertEqual(B.reported, 2) |
| 1928 | self.assertEqual(C.data['status'], 'MERGED') |
| 1929 | self.assertEqual(C.reported, 2) |
| 1930 | self.assertEqual(D.data['status'], 'MERGED') |
| 1931 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1932 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 1933 | def test_rerun_on_error(self): |
| 1934 | "Test that if a worker fails to run a job, it is run again" |
| 1935 | self.worker.hold_jobs_in_build = True |
| 1936 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1937 | A.addApproval('CRVW', 2) |
| 1938 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1939 | self.waitUntilSettled() |
| 1940 | |
| 1941 | self.builds[0].run_error = True |
| 1942 | self.worker.hold_jobs_in_build = False |
| 1943 | self.worker.release() |
| 1944 | self.waitUntilSettled() |
| 1945 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 1946 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 1947 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1948 | def test_statsd(self): |
| 1949 | "Test each of the statsd methods used in the scheduler" |
| 1950 | import extras |
| 1951 | statsd = extras.try_import('statsd.statsd') |
| 1952 | statsd.incr('test-incr') |
| 1953 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1954 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1955 | self.assertReportedStat('test-incr', '1|c') |
| 1956 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 1957 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1958 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1959 | def test_stuck_job_cleanup(self): |
| 1960 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1961 | # This job won't be registered at startup because it is not in |
| 1962 | # the standard layout, but we need it to already be registerd |
| 1963 | # for when we reconfigure, as that is when Zuul will attempt |
| 1964 | # to run the new job. |
| 1965 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1966 | self.gearman_server.hold_jobs_in_queue = True |
| 1967 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1968 | A.addApproval('CRVW', 2) |
| 1969 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1970 | self.waitUntilSettled() |
| 1971 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 1972 | |
| 1973 | self.config.set('zuul', 'layout_config', |
| 1974 | 'tests/fixtures/layout-no-jobs.yaml') |
| 1975 | self.sched.reconfigure(self.config) |
| 1976 | self.waitUntilSettled() |
| 1977 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1978 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1979 | self.waitUntilSettled() |
| 1980 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1981 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1982 | |
| 1983 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1984 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 1985 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 1986 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1987 | def test_file_jobs(self): |
| 1988 | "Test that file jobs run only when appropriate" |
| 1989 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1990 | A.addPatchset(['pip-requires']) |
| 1991 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1992 | A.addApproval('CRVW', 2) |
| 1993 | B.addApproval('CRVW', 2) |
| 1994 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1995 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1996 | self.waitUntilSettled() |
| 1997 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1998 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 1999 | if x.name == 'project-testfile'] |
| 2000 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2001 | self.assertEqual(len(testfile_jobs), 1) |
| 2002 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2003 | self.assertEqual(A.data['status'], 'MERGED') |
| 2004 | self.assertEqual(A.reported, 2) |
| 2005 | self.assertEqual(B.data['status'], 'MERGED') |
| 2006 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2007 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2008 | def _test_skip_if_jobs(self, branch, should_skip): |
| 2009 | "Test that jobs with a skip-if filter run only when appropriate" |
| 2010 | self.config.set('zuul', 'layout_config', |
| 2011 | 'tests/fixtures/layout-skip-if.yaml') |
| 2012 | self.sched.reconfigure(self.config) |
| 2013 | self.registerJobs() |
| 2014 | |
| 2015 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2016 | branch, |
| 2017 | 'test skip-if') |
| 2018 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2019 | self.waitUntilSettled() |
| 2020 | |
| 2021 | tested_change_ids = [x.changes[0] for x in self.history |
| 2022 | if x.name == 'project-test-skip-if'] |
| 2023 | |
| 2024 | if should_skip: |
| 2025 | self.assertEqual([], tested_change_ids) |
| 2026 | else: |
| 2027 | self.assertIn(change.data['number'], tested_change_ids) |
| 2028 | |
| 2029 | def test_skip_if_match_skips_job(self): |
| 2030 | self._test_skip_if_jobs(branch='master', should_skip=True) |
| 2031 | |
| 2032 | def test_skip_if_no_match_runs_job(self): |
| 2033 | self._test_skip_if_jobs(branch='mp', should_skip=False) |
| 2034 | |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2035 | def test_test_config(self): |
| 2036 | "Test that we can test the config" |
| 2037 | sched = zuul.scheduler.Scheduler() |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 2038 | sched.registerTrigger(None, 'gerrit') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2039 | sched.registerTrigger(None, 'timer') |
James E. Blair | c494d54 | 2014-08-06 09:23:52 -0700 | [diff] [blame] | 2040 | sched.registerTrigger(None, 'zuul') |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 2041 | sched.testConfig(self.config.get('zuul', 'layout_config')) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2042 | |
| 2043 | def test_build_description(self): |
| 2044 | "Test that build descriptions update" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2045 | self.worker.registerFunction('set_description:' + |
| 2046 | self.worker.worker_id) |
| 2047 | |
| 2048 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2049 | A.addApproval('CRVW', 2) |
| 2050 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2051 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2052 | desc = self.history[0].description |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2053 | self.log.debug("Description: %s" % desc) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2054 | self.assertTrue(re.search("Branch.*master", desc)) |
| 2055 | self.assertTrue(re.search("Pipeline.*gate", desc)) |
| 2056 | self.assertTrue(re.search("project-merge.*SUCCESS", desc)) |
| 2057 | self.assertTrue(re.search("project-test1.*SUCCESS", desc)) |
| 2058 | self.assertTrue(re.search("project-test2.*SUCCESS", desc)) |
| 2059 | self.assertTrue(re.search("Reported result.*SUCCESS", desc)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2060 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2061 | def test_queue_names(self): |
| 2062 | "Test shared change queue names" |
| 2063 | project1 = self.sched.layout.projects['org/project1'] |
| 2064 | project2 = self.sched.layout.projects['org/project2'] |
| 2065 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2066 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2067 | self.assertEqual(q1.name, 'integration') |
| 2068 | self.assertEqual(q2.name, 'integration') |
| 2069 | |
| 2070 | self.config.set('zuul', 'layout_config', |
| 2071 | 'tests/fixtures/layout-bad-queue.yaml') |
| 2072 | with testtools.ExpectedException( |
| 2073 | Exception, "More than one name assigned to change queue"): |
| 2074 | self.sched.reconfigure(self.config) |
| 2075 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2076 | def test_queue_precedence(self): |
| 2077 | "Test that queue precedence works" |
| 2078 | |
| 2079 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2080 | self.worker.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2081 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2082 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2083 | A.addApproval('CRVW', 2) |
| 2084 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2085 | |
| 2086 | self.waitUntilSettled() |
| 2087 | self.gearman_server.hold_jobs_in_queue = False |
| 2088 | self.gearman_server.release() |
| 2089 | self.waitUntilSettled() |
| 2090 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2091 | # Run one build at a time to ensure non-race order: |
| 2092 | for x in range(6): |
| 2093 | self.release(self.builds[0]) |
| 2094 | self.waitUntilSettled() |
| 2095 | self.worker.hold_jobs_in_build = False |
| 2096 | self.waitUntilSettled() |
| 2097 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2098 | self.log.debug(self.history) |
| 2099 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2100 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2101 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2102 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2103 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2104 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2105 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2106 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2107 | "Test that we can retrieve JSON status info" |
| 2108 | self.worker.hold_jobs_in_build = True |
| 2109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2110 | A.addApproval('CRVW', 2) |
| 2111 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2112 | self.waitUntilSettled() |
| 2113 | |
| 2114 | port = self.webapp.server.socket.getsockname()[1] |
| 2115 | |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 2116 | req = urllib2.Request("http://localhost:%s/status.json" % port) |
Yuriy Taraday | a6d452f | 2014-04-16 12:36:20 +0400 | [diff] [blame] | 2117 | f = urllib2.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2118 | headers = f.info() |
| 2119 | self.assertIn('Content-Length', headers) |
| 2120 | self.assertIn('Content-Type', headers) |
| 2121 | self.assertEqual(headers['Content-Type'], |
| 2122 | 'application/json; charset=UTF-8') |
| 2123 | self.assertIn('Last-Modified', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2124 | data = f.read() |
| 2125 | |
| 2126 | self.worker.hold_jobs_in_build = False |
| 2127 | self.worker.release() |
| 2128 | self.waitUntilSettled() |
| 2129 | |
| 2130 | data = json.loads(data) |
| 2131 | status_jobs = set() |
| 2132 | for p in data['pipelines']: |
| 2133 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2134 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2135 | self.assertEqual(q['window'], 20) |
| 2136 | else: |
| 2137 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2138 | for head in q['heads']: |
| 2139 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2140 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2141 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2142 | for job in change['jobs']: |
| 2143 | status_jobs.add(job['name']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2144 | self.assertIn('project-merge', status_jobs) |
| 2145 | self.assertIn('project-test1', status_jobs) |
| 2146 | self.assertIn('project-test2', status_jobs) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2147 | |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2148 | def test_merging_queues(self): |
| 2149 | "Test that transitively-connected change queues are merged" |
| 2150 | self.config.set('zuul', 'layout_config', |
| 2151 | 'tests/fixtures/layout-merge-queues.yaml') |
| 2152 | self.sched.reconfigure(self.config) |
| 2153 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2154 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2155 | def test_node_label(self): |
| 2156 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2157 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2158 | |
| 2159 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 2160 | A.addApproval('CRVW', 2) |
| 2161 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2162 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2163 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2164 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2165 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2166 | 'debian') |
| 2167 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2168 | |
| 2169 | def test_live_reconfiguration(self): |
| 2170 | "Test that live reconfiguration works" |
| 2171 | self.worker.hold_jobs_in_build = True |
| 2172 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2173 | A.addApproval('CRVW', 2) |
| 2174 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2175 | self.waitUntilSettled() |
| 2176 | |
| 2177 | self.sched.reconfigure(self.config) |
| 2178 | |
| 2179 | self.worker.hold_jobs_in_build = False |
| 2180 | self.worker.release() |
| 2181 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2182 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2183 | 'SUCCESS') |
| 2184 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2185 | 'SUCCESS') |
| 2186 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2187 | 'SUCCESS') |
| 2188 | self.assertEqual(A.data['status'], 'MERGED') |
| 2189 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2190 | |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2191 | def test_live_reconfiguration_functions(self): |
| 2192 | "Test live reconfiguration with a custom function" |
| 2193 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2194 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2195 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 2196 | A.addApproval('CRVW', 2) |
| 2197 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2198 | self.waitUntilSettled() |
| 2199 | |
| 2200 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2201 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2202 | 'debian') |
| 2203 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2204 | |
| 2205 | self.config.set('zuul', 'layout_config', |
| 2206 | 'tests/fixtures/layout-live-' |
| 2207 | 'reconfiguration-functions.yaml') |
| 2208 | self.sched.reconfigure(self.config) |
| 2209 | self.worker.build_history = [] |
| 2210 | |
| 2211 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
| 2212 | B.addApproval('CRVW', 2) |
| 2213 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2214 | self.waitUntilSettled() |
| 2215 | |
| 2216 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2217 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2218 | 'wheezy') |
| 2219 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2220 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2221 | def test_delayed_repo_init(self): |
| 2222 | self.config.set('zuul', 'layout_config', |
| 2223 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
| 2224 | self.sched.reconfigure(self.config) |
| 2225 | |
| 2226 | self.init_repo("org/new-project") |
| 2227 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2228 | |
| 2229 | A.addApproval('CRVW', 2) |
| 2230 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2231 | self.waitUntilSettled() |
| 2232 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2233 | 'SUCCESS') |
| 2234 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2235 | 'SUCCESS') |
| 2236 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2237 | 'SUCCESS') |
| 2238 | self.assertEqual(A.data['status'], 'MERGED') |
| 2239 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2240 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2241 | def test_repo_deleted(self): |
| 2242 | self.config.set('zuul', 'layout_config', |
| 2243 | 'tests/fixtures/layout-repo-deleted.yaml') |
| 2244 | self.sched.reconfigure(self.config) |
| 2245 | |
| 2246 | self.init_repo("org/delete-project") |
| 2247 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2248 | |
| 2249 | A.addApproval('CRVW', 2) |
| 2250 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2251 | self.waitUntilSettled() |
| 2252 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2253 | 'SUCCESS') |
| 2254 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2255 | 'SUCCESS') |
| 2256 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2257 | 'SUCCESS') |
| 2258 | self.assertEqual(A.data['status'], 'MERGED') |
| 2259 | self.assertEqual(A.reported, 2) |
| 2260 | |
| 2261 | # Delete org/new-project zuul repo. Should be recloned. |
| 2262 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2263 | |
| 2264 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2265 | |
| 2266 | B.addApproval('CRVW', 2) |
| 2267 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2268 | self.waitUntilSettled() |
| 2269 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2270 | 'SUCCESS') |
| 2271 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2272 | 'SUCCESS') |
| 2273 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2274 | 'SUCCESS') |
| 2275 | self.assertEqual(B.data['status'], 'MERGED') |
| 2276 | self.assertEqual(B.reported, 2) |
| 2277 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2278 | def test_timer(self): |
| 2279 | "Test that a periodic job is triggered" |
| 2280 | self.worker.hold_jobs_in_build = True |
| 2281 | self.config.set('zuul', 'layout_config', |
| 2282 | 'tests/fixtures/layout-timer.yaml') |
| 2283 | self.sched.reconfigure(self.config) |
| 2284 | self.registerJobs() |
| 2285 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2286 | # The pipeline triggers every second, so we should have seen |
| 2287 | # several by now. |
| 2288 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2289 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2290 | |
| 2291 | self.assertEqual(len(self.builds), 2) |
| 2292 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2293 | port = self.webapp.server.socket.getsockname()[1] |
| 2294 | |
| 2295 | f = urllib.urlopen("http://localhost:%s/status.json" % port) |
| 2296 | data = f.read() |
| 2297 | |
| 2298 | self.worker.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2299 | # Stop queuing timer triggered jobs so that the assertions |
| 2300 | # below don't race against more jobs being queued. |
| 2301 | self.config.set('zuul', 'layout_config', |
| 2302 | 'tests/fixtures/layout-no-timer.yaml') |
| 2303 | self.sched.reconfigure(self.config) |
| 2304 | self.registerJobs() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2305 | self.worker.release() |
| 2306 | self.waitUntilSettled() |
| 2307 | |
| 2308 | self.assertEqual(self.getJobFromHistory( |
| 2309 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2310 | self.assertEqual(self.getJobFromHistory( |
| 2311 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2312 | |
| 2313 | data = json.loads(data) |
| 2314 | status_jobs = set() |
| 2315 | for p in data['pipelines']: |
| 2316 | for q in p['change_queues']: |
| 2317 | for head in q['heads']: |
| 2318 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2319 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2320 | for job in change['jobs']: |
| 2321 | status_jobs.add(job['name']) |
| 2322 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2323 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2324 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2325 | def test_idle(self): |
| 2326 | "Test that frequent periodic jobs work" |
| 2327 | self.worker.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2328 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2329 | for x in range(1, 3): |
| 2330 | # Test that timer triggers periodic jobs even across |
| 2331 | # layout config reloads. |
| 2332 | # Start timer trigger |
| 2333 | self.config.set('zuul', 'layout_config', |
| 2334 | 'tests/fixtures/layout-idle.yaml') |
| 2335 | self.sched.reconfigure(self.config) |
| 2336 | self.registerJobs() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2337 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2338 | # The pipeline triggers every second, so we should have seen |
| 2339 | # several by now. |
| 2340 | time.sleep(5) |
| 2341 | self.waitUntilSettled() |
| 2342 | |
| 2343 | # Stop queuing timer triggered jobs so that the assertions |
| 2344 | # below don't race against more jobs being queued. |
| 2345 | self.config.set('zuul', 'layout_config', |
| 2346 | 'tests/fixtures/layout-no-timer.yaml') |
| 2347 | self.sched.reconfigure(self.config) |
| 2348 | self.registerJobs() |
| 2349 | |
| 2350 | self.assertEqual(len(self.builds), 2) |
| 2351 | self.worker.release('.*') |
| 2352 | self.waitUntilSettled() |
| 2353 | self.assertEqual(len(self.builds), 0) |
| 2354 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2355 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2356 | def test_check_smtp_pool(self): |
| 2357 | self.config.set('zuul', 'layout_config', |
| 2358 | 'tests/fixtures/layout-smtp.yaml') |
| 2359 | self.sched.reconfigure(self.config) |
| 2360 | |
| 2361 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2362 | self.waitUntilSettled() |
| 2363 | |
| 2364 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2365 | self.waitUntilSettled() |
| 2366 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2367 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2368 | |
| 2369 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2370 | # work on the knowledge of what the first message should be as |
| 2371 | # it is only configured to go to SMTP. |
| 2372 | |
| 2373 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2374 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2375 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2376 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2377 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2378 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2379 | |
| 2380 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2381 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2382 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2383 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2384 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2385 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2386 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2387 | def test_timer_smtp(self): |
| 2388 | "Test that a periodic job is triggered" |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2389 | self.worker.hold_jobs_in_build = True |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2390 | self.config.set('zuul', 'layout_config', |
| 2391 | 'tests/fixtures/layout-timer-smtp.yaml') |
| 2392 | self.sched.reconfigure(self.config) |
| 2393 | self.registerJobs() |
| 2394 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2395 | # The pipeline triggers every second, so we should have seen |
| 2396 | # several by now. |
| 2397 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2398 | self.waitUntilSettled() |
| 2399 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2400 | self.assertEqual(len(self.builds), 2) |
| 2401 | self.worker.release('.*') |
| 2402 | self.waitUntilSettled() |
| 2403 | self.assertEqual(len(self.history), 2) |
| 2404 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2405 | self.assertEqual(self.getJobFromHistory( |
| 2406 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2407 | self.assertEqual(self.getJobFromHistory( |
| 2408 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2409 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2410 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2411 | |
| 2412 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2413 | # work on the knowledge of what the first message should be as |
| 2414 | # it is only configured to go to SMTP. |
| 2415 | |
| 2416 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2417 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2418 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2419 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2420 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2421 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2422 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2423 | # Stop queuing timer triggered jobs and let any that may have |
| 2424 | # queued through so that end of test assertions pass. |
| 2425 | self.config.set('zuul', 'layout_config', |
| 2426 | 'tests/fixtures/layout-no-timer.yaml') |
| 2427 | self.sched.reconfigure(self.config) |
| 2428 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2429 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2430 | self.worker.release('.*') |
| 2431 | self.waitUntilSettled() |
| 2432 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2433 | def test_client_enqueue(self): |
| 2434 | "Test that the RPC client can enqueue a change" |
| 2435 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2436 | A.addApproval('CRVW', 2) |
| 2437 | A.addApproval('APRV', 1) |
| 2438 | |
| 2439 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2440 | self.gearman_server.port) |
| 2441 | r = client.enqueue(pipeline='gate', |
| 2442 | project='org/project', |
| 2443 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2444 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2445 | self.waitUntilSettled() |
| 2446 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2447 | 'SUCCESS') |
| 2448 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2449 | 'SUCCESS') |
| 2450 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2451 | 'SUCCESS') |
| 2452 | self.assertEqual(A.data['status'], 'MERGED') |
| 2453 | self.assertEqual(A.reported, 2) |
| 2454 | self.assertEqual(r, True) |
| 2455 | |
| 2456 | def test_client_enqueue_negative(self): |
| 2457 | "Test that the RPC client returns errors" |
| 2458 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2459 | self.gearman_server.port) |
| 2460 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2461 | "Invalid project"): |
| 2462 | r = client.enqueue(pipeline='gate', |
| 2463 | project='project-does-not-exist', |
| 2464 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2465 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2466 | client.shutdown() |
| 2467 | self.assertEqual(r, False) |
| 2468 | |
| 2469 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2470 | "Invalid pipeline"): |
| 2471 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 2472 | project='org/project', |
| 2473 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2474 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2475 | client.shutdown() |
| 2476 | self.assertEqual(r, False) |
| 2477 | |
| 2478 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2479 | "Invalid trigger"): |
| 2480 | r = client.enqueue(pipeline='gate', |
| 2481 | project='org/project', |
| 2482 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2483 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2484 | client.shutdown() |
| 2485 | self.assertEqual(r, False) |
| 2486 | |
| 2487 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2488 | "Invalid change"): |
| 2489 | r = client.enqueue(pipeline='gate', |
| 2490 | project='org/project', |
| 2491 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2492 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2493 | client.shutdown() |
| 2494 | self.assertEqual(r, False) |
| 2495 | |
| 2496 | self.waitUntilSettled() |
| 2497 | self.assertEqual(len(self.history), 0) |
| 2498 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2499 | |
| 2500 | def test_client_promote(self): |
| 2501 | "Test that the RPC client can promote a change" |
| 2502 | self.worker.hold_jobs_in_build = True |
| 2503 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2504 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2505 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2506 | A.addApproval('CRVW', 2) |
| 2507 | B.addApproval('CRVW', 2) |
| 2508 | C.addApproval('CRVW', 2) |
| 2509 | |
| 2510 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2511 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2512 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2513 | |
| 2514 | self.waitUntilSettled() |
| 2515 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 2516 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 2517 | enqueue_times = {} |
| 2518 | for item in items: |
| 2519 | enqueue_times[str(item.change)] = item.enqueue_time |
| 2520 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2521 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2522 | self.gearman_server.port) |
| 2523 | r = client.promote(pipeline='gate', |
| 2524 | change_ids=['2,1', '3,1']) |
| 2525 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 2526 | # ensure that enqueue times are durable |
| 2527 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 2528 | for item in items: |
| 2529 | self.assertEqual( |
| 2530 | enqueue_times[str(item.change)], item.enqueue_time) |
| 2531 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 2532 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2533 | self.worker.release('.*-merge') |
| 2534 | self.waitUntilSettled() |
| 2535 | self.worker.release('.*-merge') |
| 2536 | self.waitUntilSettled() |
| 2537 | self.worker.release('.*-merge') |
| 2538 | self.waitUntilSettled() |
| 2539 | |
| 2540 | self.assertEqual(len(self.builds), 6) |
| 2541 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2542 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2543 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2544 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 2545 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 2546 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 2547 | |
| 2548 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 2549 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 2550 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 2551 | |
| 2552 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 2553 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 2554 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 2555 | |
| 2556 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 2557 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 2558 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 2559 | |
| 2560 | self.worker.release() |
| 2561 | self.waitUntilSettled() |
| 2562 | |
| 2563 | self.assertEqual(A.data['status'], 'MERGED') |
| 2564 | self.assertEqual(A.reported, 2) |
| 2565 | self.assertEqual(B.data['status'], 'MERGED') |
| 2566 | self.assertEqual(B.reported, 2) |
| 2567 | self.assertEqual(C.data['status'], 'MERGED') |
| 2568 | self.assertEqual(C.reported, 2) |
| 2569 | |
| 2570 | client.shutdown() |
| 2571 | self.assertEqual(r, True) |
| 2572 | |
| 2573 | def test_client_promote_dependent(self): |
| 2574 | "Test that the RPC client can promote a dependent change" |
| 2575 | # C (depends on B) -> B -> A ; then promote C to get: |
| 2576 | # A -> C (depends on B) -> B |
| 2577 | self.worker.hold_jobs_in_build = True |
| 2578 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2579 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2580 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2581 | |
| 2582 | C.setDependsOn(B, 1) |
| 2583 | |
| 2584 | A.addApproval('CRVW', 2) |
| 2585 | B.addApproval('CRVW', 2) |
| 2586 | C.addApproval('CRVW', 2) |
| 2587 | |
| 2588 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2589 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2590 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2591 | |
| 2592 | self.waitUntilSettled() |
| 2593 | |
| 2594 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2595 | self.gearman_server.port) |
| 2596 | r = client.promote(pipeline='gate', |
| 2597 | change_ids=['3,1']) |
| 2598 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 2599 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2600 | self.worker.release('.*-merge') |
| 2601 | self.waitUntilSettled() |
| 2602 | self.worker.release('.*-merge') |
| 2603 | self.waitUntilSettled() |
| 2604 | self.worker.release('.*-merge') |
| 2605 | self.waitUntilSettled() |
| 2606 | |
| 2607 | self.assertEqual(len(self.builds), 6) |
| 2608 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2609 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2610 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2611 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 2612 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 2613 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 2614 | |
| 2615 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 2616 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 2617 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 2618 | |
| 2619 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 2620 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 2621 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 2622 | |
| 2623 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 2624 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 2625 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 2626 | |
| 2627 | self.worker.release() |
| 2628 | self.waitUntilSettled() |
| 2629 | |
| 2630 | self.assertEqual(A.data['status'], 'MERGED') |
| 2631 | self.assertEqual(A.reported, 2) |
| 2632 | self.assertEqual(B.data['status'], 'MERGED') |
| 2633 | self.assertEqual(B.reported, 2) |
| 2634 | self.assertEqual(C.data['status'], 'MERGED') |
| 2635 | self.assertEqual(C.reported, 2) |
| 2636 | |
| 2637 | client.shutdown() |
| 2638 | self.assertEqual(r, True) |
| 2639 | |
| 2640 | def test_client_promote_negative(self): |
| 2641 | "Test that the RPC client returns errors for promotion" |
| 2642 | self.worker.hold_jobs_in_build = True |
| 2643 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2644 | A.addApproval('CRVW', 2) |
| 2645 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2646 | self.waitUntilSettled() |
| 2647 | |
| 2648 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2649 | self.gearman_server.port) |
| 2650 | |
| 2651 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 2652 | r = client.promote(pipeline='nonexistent', |
| 2653 | change_ids=['2,1', '3,1']) |
| 2654 | client.shutdown() |
| 2655 | self.assertEqual(r, False) |
| 2656 | |
| 2657 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 2658 | r = client.promote(pipeline='gate', |
| 2659 | change_ids=['4,1']) |
| 2660 | client.shutdown() |
| 2661 | self.assertEqual(r, False) |
| 2662 | |
| 2663 | self.worker.hold_jobs_in_build = False |
| 2664 | self.worker.release() |
| 2665 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 2666 | |
| 2667 | def test_queue_rate_limiting(self): |
| 2668 | "Test that DependentPipelines are rate limited with dep across window" |
| 2669 | self.config.set('zuul', 'layout_config', |
| 2670 | 'tests/fixtures/layout-rate-limit.yaml') |
| 2671 | self.sched.reconfigure(self.config) |
| 2672 | self.worker.hold_jobs_in_build = True |
| 2673 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2674 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2675 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2676 | |
| 2677 | C.setDependsOn(B, 1) |
| 2678 | self.worker.addFailTest('project-test1', A) |
| 2679 | |
| 2680 | A.addApproval('CRVW', 2) |
| 2681 | B.addApproval('CRVW', 2) |
| 2682 | C.addApproval('CRVW', 2) |
| 2683 | |
| 2684 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2685 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2686 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2687 | self.waitUntilSettled() |
| 2688 | |
| 2689 | # Only A and B will have their merge jobs queued because |
| 2690 | # window is 2. |
| 2691 | self.assertEqual(len(self.builds), 2) |
| 2692 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2693 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 2694 | |
| 2695 | self.worker.release('.*-merge') |
| 2696 | self.waitUntilSettled() |
| 2697 | self.worker.release('.*-merge') |
| 2698 | self.waitUntilSettled() |
| 2699 | |
| 2700 | # Only A and B will have their test jobs queued because |
| 2701 | # window is 2. |
| 2702 | self.assertEqual(len(self.builds), 4) |
| 2703 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2704 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2705 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2706 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 2707 | |
| 2708 | self.worker.release('project-.*') |
| 2709 | self.waitUntilSettled() |
| 2710 | |
| 2711 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 2712 | # A failed so window is reduced by 1 to 1. |
| 2713 | self.assertEqual(queue.window, 1) |
| 2714 | self.assertEqual(queue.window_floor, 1) |
| 2715 | self.assertEqual(A.data['status'], 'NEW') |
| 2716 | |
| 2717 | # Gate is reset and only B's merge job is queued because |
| 2718 | # window shrunk to 1. |
| 2719 | self.assertEqual(len(self.builds), 1) |
| 2720 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2721 | |
| 2722 | self.worker.release('.*-merge') |
| 2723 | self.waitUntilSettled() |
| 2724 | |
| 2725 | # Only B's test jobs are queued because window is still 1. |
| 2726 | self.assertEqual(len(self.builds), 2) |
| 2727 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2728 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2729 | |
| 2730 | self.worker.release('project-.*') |
| 2731 | self.waitUntilSettled() |
| 2732 | |
| 2733 | # B was successfully merged so window is increased to 2. |
| 2734 | self.assertEqual(queue.window, 2) |
| 2735 | self.assertEqual(queue.window_floor, 1) |
| 2736 | self.assertEqual(B.data['status'], 'MERGED') |
| 2737 | |
| 2738 | # Only C is left and its merge job is queued. |
| 2739 | self.assertEqual(len(self.builds), 1) |
| 2740 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2741 | |
| 2742 | self.worker.release('.*-merge') |
| 2743 | self.waitUntilSettled() |
| 2744 | |
| 2745 | # After successful merge job the test jobs for C are queued. |
| 2746 | self.assertEqual(len(self.builds), 2) |
| 2747 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2748 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2749 | |
| 2750 | self.worker.release('project-.*') |
| 2751 | self.waitUntilSettled() |
| 2752 | |
| 2753 | # C successfully merged so window is bumped to 3. |
| 2754 | self.assertEqual(queue.window, 3) |
| 2755 | self.assertEqual(queue.window_floor, 1) |
| 2756 | self.assertEqual(C.data['status'], 'MERGED') |
| 2757 | |
| 2758 | def test_queue_rate_limiting_dependent(self): |
| 2759 | "Test that DependentPipelines are rate limited with dep in window" |
| 2760 | self.config.set('zuul', 'layout_config', |
| 2761 | 'tests/fixtures/layout-rate-limit.yaml') |
| 2762 | self.sched.reconfigure(self.config) |
| 2763 | self.worker.hold_jobs_in_build = True |
| 2764 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2765 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2766 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2767 | |
| 2768 | B.setDependsOn(A, 1) |
| 2769 | |
| 2770 | self.worker.addFailTest('project-test1', A) |
| 2771 | |
| 2772 | A.addApproval('CRVW', 2) |
| 2773 | B.addApproval('CRVW', 2) |
| 2774 | C.addApproval('CRVW', 2) |
| 2775 | |
| 2776 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2777 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2778 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2779 | self.waitUntilSettled() |
| 2780 | |
| 2781 | # Only A and B will have their merge jobs queued because |
| 2782 | # window is 2. |
| 2783 | self.assertEqual(len(self.builds), 2) |
| 2784 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2785 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 2786 | |
| 2787 | self.worker.release('.*-merge') |
| 2788 | self.waitUntilSettled() |
| 2789 | self.worker.release('.*-merge') |
| 2790 | self.waitUntilSettled() |
| 2791 | |
| 2792 | # Only A and B will have their test jobs queued because |
| 2793 | # window is 2. |
| 2794 | self.assertEqual(len(self.builds), 4) |
| 2795 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2796 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2797 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2798 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 2799 | |
| 2800 | self.worker.release('project-.*') |
| 2801 | self.waitUntilSettled() |
| 2802 | |
| 2803 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 2804 | # A failed so window is reduced by 1 to 1. |
| 2805 | self.assertEqual(queue.window, 1) |
| 2806 | self.assertEqual(queue.window_floor, 1) |
| 2807 | self.assertEqual(A.data['status'], 'NEW') |
| 2808 | self.assertEqual(B.data['status'], 'NEW') |
| 2809 | |
| 2810 | # Gate is reset and only C's merge job is queued because |
| 2811 | # window shrunk to 1 and A and B were dequeued. |
| 2812 | self.assertEqual(len(self.builds), 1) |
| 2813 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 2814 | |
| 2815 | self.worker.release('.*-merge') |
| 2816 | self.waitUntilSettled() |
| 2817 | |
| 2818 | # Only C's test jobs are queued because window is still 1. |
| 2819 | self.assertEqual(len(self.builds), 2) |
| 2820 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2821 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 2822 | |
| 2823 | self.worker.release('project-.*') |
| 2824 | self.waitUntilSettled() |
| 2825 | |
| 2826 | # C was successfully merged so window is increased to 2. |
| 2827 | self.assertEqual(queue.window, 2) |
| 2828 | self.assertEqual(queue.window_floor, 1) |
| 2829 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 2830 | |
| 2831 | def test_worker_update_metadata(self): |
| 2832 | "Test if a worker can send back metadata about itself" |
| 2833 | self.worker.hold_jobs_in_build = True |
| 2834 | |
| 2835 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2836 | A.addApproval('CRVW', 2) |
| 2837 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2838 | self.waitUntilSettled() |
| 2839 | |
| 2840 | self.assertEqual(len(self.launcher.builds), 1) |
| 2841 | |
| 2842 | self.log.debug('Current builds:') |
| 2843 | self.log.debug(self.launcher.builds) |
| 2844 | |
| 2845 | start = time.time() |
| 2846 | while True: |
| 2847 | if time.time() - start > 10: |
| 2848 | raise Exception("Timeout waiting for gearman server to report " |
| 2849 | + "back to the client") |
| 2850 | build = self.launcher.builds.values()[0] |
| 2851 | if build.worker.name == "My Worker": |
| 2852 | break |
| 2853 | else: |
| 2854 | time.sleep(0) |
| 2855 | |
| 2856 | self.log.debug(build) |
| 2857 | self.assertEqual("My Worker", build.worker.name) |
| 2858 | self.assertEqual("localhost", build.worker.hostname) |
| 2859 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 2860 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 2861 | self.assertEqual("FakeBuilder", build.worker.program) |
| 2862 | self.assertEqual("v1.1", build.worker.version) |
| 2863 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 2864 | |
| 2865 | self.worker.hold_jobs_in_build = False |
| 2866 | self.worker.release() |
| 2867 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 2868 | |
| 2869 | def test_footer_message(self): |
| 2870 | "Test a pipeline's footer message is correctly added to the report." |
| 2871 | self.config.set('zuul', 'layout_config', |
| 2872 | 'tests/fixtures/layout-footer-message.yaml') |
| 2873 | self.sched.reconfigure(self.config) |
| 2874 | self.registerJobs() |
| 2875 | |
| 2876 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2877 | A.addApproval('CRVW', 2) |
| 2878 | self.worker.addFailTest('test1', A) |
| 2879 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2880 | self.waitUntilSettled() |
| 2881 | |
| 2882 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2883 | B.addApproval('CRVW', 2) |
| 2884 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2885 | self.waitUntilSettled() |
| 2886 | |
| 2887 | self.assertEqual(2, len(self.smtp_messages)) |
| 2888 | |
| 2889 | failure_body = """\ |
| 2890 | Build failed. For information on how to proceed, see \ |
| 2891 | http://wiki.example.org/Test_Failures |
| 2892 | |
| 2893 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 2894 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 2895 | |
| 2896 | For CI problems and help debugging, contact ci@example.org""" |
| 2897 | |
| 2898 | success_body = """\ |
| 2899 | Build succeeded. |
| 2900 | |
| 2901 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 2902 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 2903 | |
| 2904 | For CI problems and help debugging, contact ci@example.org""" |
| 2905 | |
| 2906 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 2907 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 2908 | |
| 2909 | def test_merge_failure_reporters(self): |
| 2910 | """Check that the config is set up correctly""" |
| 2911 | |
| 2912 | self.config.set('zuul', 'layout_config', |
| 2913 | 'tests/fixtures/layout-merge-failure.yaml') |
| 2914 | self.sched.reconfigure(self.config) |
| 2915 | self.registerJobs() |
| 2916 | |
| 2917 | self.assertEqual( |
| 2918 | "Merge Failed.\n\nThis change was unable to be automatically " |
| 2919 | "merged with the current state of the repository. Please rebase " |
| 2920 | "your change and upload a new patchset.", |
| 2921 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 2922 | self.assertEqual( |
| 2923 | "The merge failed! For more information...", |
| 2924 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 2925 | |
| 2926 | self.assertEqual( |
| 2927 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 2928 | self.assertEqual( |
| 2929 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 2930 | |
| 2931 | self.assertTrue(isinstance( |
| 2932 | self.sched.layout.pipelines['check'].merge_failure_actions[0]. |
| 2933 | reporter, zuul.reporter.gerrit.Reporter)) |
| 2934 | |
| 2935 | self.assertTrue( |
| 2936 | ( |
| 2937 | isinstance(self.sched.layout.pipelines['gate']. |
| 2938 | merge_failure_actions[0].reporter, |
| 2939 | zuul.reporter.smtp.Reporter) and |
| 2940 | isinstance(self.sched.layout.pipelines['gate']. |
| 2941 | merge_failure_actions[1].reporter, |
| 2942 | zuul.reporter.gerrit.Reporter) |
| 2943 | ) or ( |
| 2944 | isinstance(self.sched.layout.pipelines['gate']. |
| 2945 | merge_failure_actions[0].reporter, |
| 2946 | zuul.reporter.gerrit.Reporter) and |
| 2947 | isinstance(self.sched.layout.pipelines['gate']. |
| 2948 | merge_failure_actions[1].reporter, |
| 2949 | zuul.reporter.smtp.Reporter) |
| 2950 | ) |
| 2951 | ) |
| 2952 | |
| 2953 | def test_merge_failure_reports(self): |
| 2954 | """Check that when a change fails to merge the correct message is sent |
| 2955 | to the correct reporter""" |
| 2956 | self.config.set('zuul', 'layout_config', |
| 2957 | 'tests/fixtures/layout-merge-failure.yaml') |
| 2958 | self.sched.reconfigure(self.config) |
| 2959 | self.registerJobs() |
| 2960 | |
| 2961 | # Check a test failure isn't reported to SMTP |
| 2962 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2963 | A.addApproval('CRVW', 2) |
| 2964 | self.worker.addFailTest('project-test1', A) |
| 2965 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2966 | self.waitUntilSettled() |
| 2967 | |
| 2968 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 2969 | self.assertEqual(0, len(self.smtp_messages)) |
| 2970 | |
| 2971 | # Check a merge failure is reported to SMTP |
| 2972 | # B should be merged, but C will conflict with B |
| 2973 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2974 | B.addPatchset(['conflict']) |
| 2975 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2976 | C.addPatchset(['conflict']) |
| 2977 | B.addApproval('CRVW', 2) |
| 2978 | C.addApproval('CRVW', 2) |
| 2979 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2980 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2981 | self.waitUntilSettled() |
| 2982 | |
| 2983 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 2984 | self.assertEqual(1, len(self.smtp_messages)) |
| 2985 | self.assertEqual('The merge failed! For more information...', |
| 2986 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 2987 | |
| 2988 | def test_swift_instructions(self): |
| 2989 | "Test that the correct swift instructions are sent to the workers" |
| 2990 | self.config.set('zuul', 'layout_config', |
| 2991 | 'tests/fixtures/layout-swift.yaml') |
| 2992 | self.sched.reconfigure(self.config) |
| 2993 | self.registerJobs() |
| 2994 | |
| 2995 | self.worker.hold_jobs_in_build = True |
| 2996 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2997 | |
| 2998 | A.addApproval('CRVW', 2) |
| 2999 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3000 | self.waitUntilSettled() |
| 3001 | |
| 3002 | self.assertEqual( |
| 3003 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3004 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3005 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3006 | self.assertEqual(5, |
| 3007 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3008 | split('\n'))) |
| 3009 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3010 | |
| 3011 | self.assertEqual( |
| 3012 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3013 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3014 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3015 | self.assertEqual(5, |
| 3016 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3017 | split('\n'))) |
| 3018 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3019 | |
| 3020 | self.assertEqual( |
| 3021 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3022 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3023 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3024 | self.assertEqual(5, |
| 3025 | len(self.builds[1]. |
| 3026 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3027 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3028 | |
| 3029 | self.worker.hold_jobs_in_build = False |
| 3030 | self.worker.release() |
| 3031 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3032 | |
| 3033 | def test_client_get_running_jobs(self): |
| 3034 | "Test that the RPC client can get a list of running jobs" |
| 3035 | self.worker.hold_jobs_in_build = True |
| 3036 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3037 | A.addApproval('CRVW', 2) |
| 3038 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3039 | self.waitUntilSettled() |
| 3040 | |
| 3041 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3042 | self.gearman_server.port) |
| 3043 | |
| 3044 | # Wait for gearman server to send the initial workData back to zuul |
| 3045 | start = time.time() |
| 3046 | while True: |
| 3047 | if time.time() - start > 10: |
| 3048 | raise Exception("Timeout waiting for gearman server to report " |
| 3049 | + "back to the client") |
| 3050 | build = self.launcher.builds.values()[0] |
| 3051 | if build.worker.name == "My Worker": |
| 3052 | break |
| 3053 | else: |
| 3054 | time.sleep(0) |
| 3055 | |
| 3056 | running_items = client.get_running_jobs() |
| 3057 | |
| 3058 | self.assertEqual(1, len(running_items)) |
| 3059 | running_item = running_items[0] |
| 3060 | self.assertEqual([], running_item['failing_reasons']) |
| 3061 | self.assertEqual([], running_item['items_behind']) |
| 3062 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3063 | self.assertEqual(None, running_item['item_ahead']) |
| 3064 | self.assertEqual('org/project', running_item['project']) |
| 3065 | self.assertEqual(None, running_item['remaining_time']) |
| 3066 | self.assertEqual(True, running_item['active']) |
| 3067 | self.assertEqual('1,1', running_item['id']) |
| 3068 | |
| 3069 | self.assertEqual(3, len(running_item['jobs'])) |
| 3070 | for job in running_item['jobs']: |
| 3071 | if job['name'] == 'project-merge': |
| 3072 | self.assertEqual('project-merge', job['name']) |
| 3073 | self.assertEqual('gate', job['pipeline']) |
| 3074 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3075 | self.assertEqual('https://server/job/project-merge/0/', |
| 3076 | job['url']) |
| 3077 | self.assertEqual(7, len(job['worker'])) |
| 3078 | self.assertEqual(False, job['canceled']) |
| 3079 | self.assertEqual(True, job['voting']) |
| 3080 | self.assertEqual(None, job['result']) |
| 3081 | self.assertEqual('gate', job['pipeline']) |
| 3082 | break |
| 3083 | |
| 3084 | self.worker.hold_jobs_in_build = False |
| 3085 | self.worker.release() |
| 3086 | self.waitUntilSettled() |
| 3087 | |
| 3088 | running_items = client.get_running_jobs() |
| 3089 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3090 | |
| 3091 | def test_nonvoting_pipeline(self): |
| 3092 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3093 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3094 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3095 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3096 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3097 | self.waitUntilSettled() |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3098 | self.assertEqual( |
| 3099 | self.getJobFromHistory('experimental-project-test').result, |
| 3100 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3101 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3102 | |
| 3103 | def test_crd_gate(self): |
| 3104 | "Test cross-repo dependencies" |
| 3105 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3106 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3107 | A.addApproval('CRVW', 2) |
| 3108 | B.addApproval('CRVW', 2) |
| 3109 | |
| 3110 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3111 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3112 | AM2.setMerged() |
| 3113 | AM1.setMerged() |
| 3114 | |
| 3115 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3116 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3117 | BM2.setMerged() |
| 3118 | BM1.setMerged() |
| 3119 | |
| 3120 | # A -> AM1 -> AM2 |
| 3121 | # B -> BM1 -> BM2 |
| 3122 | # A Depends-On: B |
| 3123 | # M2 is here to make sure it is never queried. If it is, it |
| 3124 | # means zuul is walking down the entire history of merged |
| 3125 | # changes. |
| 3126 | |
| 3127 | B.setDependsOn(BM1, 1) |
| 3128 | BM1.setDependsOn(BM2, 1) |
| 3129 | |
| 3130 | A.setDependsOn(AM1, 1) |
| 3131 | AM1.setDependsOn(AM2, 1) |
| 3132 | |
| 3133 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3134 | A.subject, B.data['id']) |
| 3135 | |
| 3136 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3137 | self.waitUntilSettled() |
| 3138 | |
| 3139 | self.assertEqual(A.data['status'], 'NEW') |
| 3140 | self.assertEqual(B.data['status'], 'NEW') |
| 3141 | |
| 3142 | source = self.sched.layout.pipelines['gate'].source |
| 3143 | source.maintainCache([]) |
| 3144 | |
| 3145 | self.worker.hold_jobs_in_build = True |
| 3146 | B.addApproval('APRV', 1) |
| 3147 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3148 | self.waitUntilSettled() |
| 3149 | |
| 3150 | self.worker.release('.*-merge') |
| 3151 | self.waitUntilSettled() |
| 3152 | self.worker.release('.*-merge') |
| 3153 | self.waitUntilSettled() |
| 3154 | self.worker.hold_jobs_in_build = False |
| 3155 | self.worker.release() |
| 3156 | self.waitUntilSettled() |
| 3157 | |
| 3158 | self.assertEqual(AM2.queried, 0) |
| 3159 | self.assertEqual(BM2.queried, 0) |
| 3160 | self.assertEqual(A.data['status'], 'MERGED') |
| 3161 | self.assertEqual(B.data['status'], 'MERGED') |
| 3162 | self.assertEqual(A.reported, 2) |
| 3163 | self.assertEqual(B.reported, 2) |
| 3164 | |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3165 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 3166 | '2,1 1,1') |
| 3167 | |
| 3168 | def test_crd_branch(self): |
| 3169 | "Test cross-repo dependencies in multiple branches" |
| 3170 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3171 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3172 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3173 | C.data['id'] = B.data['id'] |
| 3174 | A.addApproval('CRVW', 2) |
| 3175 | B.addApproval('CRVW', 2) |
| 3176 | C.addApproval('CRVW', 2) |
| 3177 | |
| 3178 | # A Depends-On: B+C |
| 3179 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3180 | A.subject, B.data['id']) |
| 3181 | |
| 3182 | self.worker.hold_jobs_in_build = True |
| 3183 | B.addApproval('APRV', 1) |
| 3184 | C.addApproval('APRV', 1) |
| 3185 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3186 | self.waitUntilSettled() |
| 3187 | |
| 3188 | self.worker.release('.*-merge') |
| 3189 | self.waitUntilSettled() |
| 3190 | self.worker.release('.*-merge') |
| 3191 | self.waitUntilSettled() |
| 3192 | self.worker.release('.*-merge') |
| 3193 | self.waitUntilSettled() |
| 3194 | self.worker.hold_jobs_in_build = False |
| 3195 | self.worker.release() |
| 3196 | self.waitUntilSettled() |
| 3197 | |
| 3198 | self.assertEqual(A.data['status'], 'MERGED') |
| 3199 | self.assertEqual(B.data['status'], 'MERGED') |
| 3200 | self.assertEqual(C.data['status'], 'MERGED') |
| 3201 | self.assertEqual(A.reported, 2) |
| 3202 | self.assertEqual(B.reported, 2) |
| 3203 | self.assertEqual(C.reported, 2) |
| 3204 | |
| 3205 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 3206 | '2,1 3,1 1,1') |
| 3207 | |
| 3208 | def test_crd_multiline(self): |
| 3209 | "Test multiple depends-on lines in commit" |
| 3210 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3211 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3212 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 3213 | A.addApproval('CRVW', 2) |
| 3214 | B.addApproval('CRVW', 2) |
| 3215 | C.addApproval('CRVW', 2) |
| 3216 | |
| 3217 | # A Depends-On: B+C |
| 3218 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3219 | A.subject, B.data['id'], C.data['id']) |
| 3220 | |
| 3221 | self.worker.hold_jobs_in_build = True |
| 3222 | B.addApproval('APRV', 1) |
| 3223 | C.addApproval('APRV', 1) |
| 3224 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3225 | self.waitUntilSettled() |
| 3226 | |
| 3227 | self.worker.release('.*-merge') |
| 3228 | self.waitUntilSettled() |
| 3229 | self.worker.release('.*-merge') |
| 3230 | self.waitUntilSettled() |
| 3231 | self.worker.release('.*-merge') |
| 3232 | self.waitUntilSettled() |
| 3233 | self.worker.hold_jobs_in_build = False |
| 3234 | self.worker.release() |
| 3235 | self.waitUntilSettled() |
| 3236 | |
| 3237 | self.assertEqual(A.data['status'], 'MERGED') |
| 3238 | self.assertEqual(B.data['status'], 'MERGED') |
| 3239 | self.assertEqual(C.data['status'], 'MERGED') |
| 3240 | self.assertEqual(A.reported, 2) |
| 3241 | self.assertEqual(B.reported, 2) |
| 3242 | self.assertEqual(C.reported, 2) |
| 3243 | |
| 3244 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 3245 | '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3246 | |
| 3247 | def test_crd_unshared_gate(self): |
| 3248 | "Test cross-repo dependencies in unshared gate queues" |
| 3249 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3250 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3251 | A.addApproval('CRVW', 2) |
| 3252 | B.addApproval('CRVW', 2) |
| 3253 | |
| 3254 | # A Depends-On: B |
| 3255 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3256 | A.subject, B.data['id']) |
| 3257 | |
| 3258 | # A and B do not share a queue, make sure that A is unable to |
| 3259 | # enqueue B (and therefore, A is unable to be enqueued). |
| 3260 | B.addApproval('APRV', 1) |
| 3261 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3262 | self.waitUntilSettled() |
| 3263 | |
| 3264 | self.assertEqual(A.data['status'], 'NEW') |
| 3265 | self.assertEqual(B.data['status'], 'NEW') |
| 3266 | self.assertEqual(A.reported, 0) |
| 3267 | self.assertEqual(B.reported, 0) |
| 3268 | self.assertEqual(len(self.history), 0) |
| 3269 | |
| 3270 | # Enqueue and merge B alone. |
| 3271 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3272 | self.waitUntilSettled() |
| 3273 | |
| 3274 | self.assertEqual(B.data['status'], 'MERGED') |
| 3275 | self.assertEqual(B.reported, 2) |
| 3276 | |
| 3277 | # Now that B is merged, A should be able to be enqueued and |
| 3278 | # merged. |
| 3279 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3280 | self.waitUntilSettled() |
| 3281 | |
| 3282 | self.assertEqual(A.data['status'], 'MERGED') |
| 3283 | self.assertEqual(A.reported, 2) |
| 3284 | |
| 3285 | def test_crd_cycle(self): |
| 3286 | "Test cross-repo dependency cycles" |
| 3287 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3288 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3289 | A.addApproval('CRVW', 2) |
| 3290 | B.addApproval('CRVW', 2) |
| 3291 | |
| 3292 | # A -> B -> A (via commit-depends) |
| 3293 | |
| 3294 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3295 | A.subject, B.data['id']) |
| 3296 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3297 | B.subject, A.data['id']) |
| 3298 | |
| 3299 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3300 | self.waitUntilSettled() |
| 3301 | |
| 3302 | self.assertEqual(A.reported, 0) |
| 3303 | self.assertEqual(B.reported, 0) |
| 3304 | self.assertEqual(A.data['status'], 'NEW') |
| 3305 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3306 | |
| 3307 | def test_crd_check(self): |
| 3308 | "Test cross-repo dependencies in independent pipelines" |
| 3309 | |
| 3310 | self.gearman_server.hold_jobs_in_queue = True |
| 3311 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3312 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3313 | |
| 3314 | # A Depends-On: B |
| 3315 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3316 | A.subject, B.data['id']) |
| 3317 | |
| 3318 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3319 | self.waitUntilSettled() |
| 3320 | |
| 3321 | queue = self.gearman_server.getQueue() |
| 3322 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 3323 | self.gearman_server.hold_jobs_in_queue = False |
| 3324 | self.gearman_server.release() |
| 3325 | self.waitUntilSettled() |
| 3326 | |
| 3327 | path = os.path.join(self.git_root, "org/project1") |
| 3328 | repo = git.Repo(path) |
| 3329 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3330 | repo_messages.reverse() |
| 3331 | correct_messages = ['initial commit', 'A-1'] |
| 3332 | self.assertEqual(repo_messages, correct_messages) |
| 3333 | |
| 3334 | path = os.path.join(self.git_root, "org/project2") |
| 3335 | repo = git.Repo(path) |
| 3336 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 3337 | repo_messages.reverse() |
| 3338 | correct_messages = ['initial commit', 'B-1'] |
| 3339 | self.assertEqual(repo_messages, correct_messages) |
| 3340 | |
| 3341 | self.assertEqual(A.data['status'], 'NEW') |
| 3342 | self.assertEqual(B.data['status'], 'NEW') |
| 3343 | self.assertEqual(A.reported, 1) |
| 3344 | self.assertEqual(B.reported, 0) |
| 3345 | |
| 3346 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 3347 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3348 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3349 | def test_crd_check_git_depends(self): |
| 3350 | "Test single-repo dependencies in independent pipelines" |
| 3351 | self.gearman_server.hold_jobs_in_queue = True |
| 3352 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3353 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3354 | |
| 3355 | # Add two git-dependent changes and make sure they both report |
| 3356 | # success. |
| 3357 | B.setDependsOn(A, 1) |
| 3358 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3359 | self.waitUntilSettled() |
| 3360 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3361 | self.waitUntilSettled() |
| 3362 | |
| 3363 | self.gearman_server.hold_jobs_in_queue = False |
| 3364 | self.gearman_server.release() |
| 3365 | self.waitUntilSettled() |
| 3366 | |
| 3367 | self.assertEqual(A.data['status'], 'NEW') |
| 3368 | self.assertEqual(B.data['status'], 'NEW') |
| 3369 | self.assertEqual(A.reported, 1) |
| 3370 | self.assertEqual(B.reported, 1) |
| 3371 | |
| 3372 | self.assertEqual(self.history[0].changes, '1,1') |
| 3373 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
| 3374 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 3375 | |
| 3376 | self.assertIn('Build succeeded', A.messages[0]) |
| 3377 | self.assertIn('Build succeeded', B.messages[0]) |
| 3378 | |
| 3379 | def test_crd_check_duplicate(self): |
| 3380 | "Test duplicate check in independent pipelines" |
| 3381 | self.gearman_server.hold_jobs_in_queue = True |
| 3382 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3383 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3384 | check_pipeline = self.sched.layout.pipelines['check'] |
| 3385 | |
| 3386 | # Add two git-dependent changes... |
| 3387 | B.setDependsOn(A, 1) |
| 3388 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3389 | self.waitUntilSettled() |
| 3390 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3391 | |
| 3392 | # ...make sure the live one is not duplicated... |
| 3393 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3394 | self.waitUntilSettled() |
| 3395 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3396 | |
| 3397 | # ...but the non-live one is able to be. |
| 3398 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3399 | self.waitUntilSettled() |
| 3400 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 3401 | |
| 3402 | self.gearman_server.hold_jobs_in_queue = False |
| 3403 | self.gearman_server.release('.*-merge') |
| 3404 | self.waitUntilSettled() |
| 3405 | self.gearman_server.release('.*-merge') |
| 3406 | self.waitUntilSettled() |
| 3407 | self.gearman_server.release() |
| 3408 | self.waitUntilSettled() |
| 3409 | |
| 3410 | self.assertEqual(A.data['status'], 'NEW') |
| 3411 | self.assertEqual(B.data['status'], 'NEW') |
| 3412 | self.assertEqual(A.reported, 1) |
| 3413 | self.assertEqual(B.reported, 1) |
| 3414 | |
| 3415 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 3416 | self.assertEqual(self.history[1].changes, '1,1') |
| 3417 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 3418 | |
| 3419 | self.assertIn('Build succeeded', A.messages[0]) |
| 3420 | self.assertIn('Build succeeded', B.messages[0]) |
| 3421 | |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3422 | def test_crd_check_reconfiguration(self): |
| 3423 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 3424 | |
| 3425 | self.gearman_server.hold_jobs_in_queue = True |
| 3426 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3427 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3428 | |
| 3429 | # A Depends-On: B |
| 3430 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3431 | A.subject, B.data['id']) |
| 3432 | |
| 3433 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3434 | self.waitUntilSettled() |
| 3435 | |
| 3436 | self.sched.reconfigure(self.config) |
| 3437 | |
| 3438 | # Make sure the items still share a change queue, and the |
| 3439 | # first one is not live. |
| 3440 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1) |
| 3441 | queue = self.sched.layout.pipelines['check'].queues[0] |
| 3442 | first_item = queue.queue[0] |
| 3443 | for item in queue.queue: |
| 3444 | self.assertEqual(item.queue, first_item.queue) |
| 3445 | self.assertFalse(first_item.live) |
| 3446 | self.assertTrue(queue.queue[1].live) |
| 3447 | |
| 3448 | self.gearman_server.hold_jobs_in_queue = False |
| 3449 | self.gearman_server.release() |
| 3450 | self.waitUntilSettled() |
| 3451 | |
| 3452 | self.assertEqual(A.data['status'], 'NEW') |
| 3453 | self.assertEqual(B.data['status'], 'NEW') |
| 3454 | self.assertEqual(A.reported, 1) |
| 3455 | self.assertEqual(B.reported, 0) |
| 3456 | |
| 3457 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 3458 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 3459 | |
| 3460 | def test_crd_check_ignore_dependencies(self): |
| 3461 | "Test cross-repo dependencies can be ignored" |
| 3462 | self.config.set('zuul', 'layout_config', |
| 3463 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
| 3464 | self.sched.reconfigure(self.config) |
| 3465 | self.registerJobs() |
| 3466 | |
| 3467 | self.gearman_server.hold_jobs_in_queue = True |
| 3468 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3469 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3470 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 3471 | |
| 3472 | # A Depends-On: B |
| 3473 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3474 | A.subject, B.data['id']) |
| 3475 | # C git-depends on B |
| 3476 | C.setDependsOn(B, 1) |
| 3477 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3478 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3479 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 3480 | self.waitUntilSettled() |
| 3481 | |
| 3482 | # Make sure none of the items share a change queue, and all |
| 3483 | # are live. |
| 3484 | check_pipeline = self.sched.layout.pipelines['check'] |
| 3485 | self.assertEqual(len(check_pipeline.queues), 3) |
| 3486 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 3487 | for item in check_pipeline.getAllItems(): |
| 3488 | self.assertTrue(item.live) |
| 3489 | |
| 3490 | self.gearman_server.hold_jobs_in_queue = False |
| 3491 | self.gearman_server.release() |
| 3492 | self.waitUntilSettled() |
| 3493 | |
| 3494 | self.assertEqual(A.data['status'], 'NEW') |
| 3495 | self.assertEqual(B.data['status'], 'NEW') |
| 3496 | self.assertEqual(C.data['status'], 'NEW') |
| 3497 | self.assertEqual(A.reported, 1) |
| 3498 | self.assertEqual(B.reported, 1) |
| 3499 | self.assertEqual(C.reported, 1) |
| 3500 | |
| 3501 | # Each job should have tested exactly one change |
| 3502 | for job in self.history: |
| 3503 | self.assertEqual(len(job.changes.split()), 1) |