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