James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | import logging |
| 19 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 20 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 21 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 22 | import time |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 23 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 25 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 26 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 27 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 28 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 29 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 31 | import zuul.rpcclient |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 32 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 33 | import zuul.reporter.smtp |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 34 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
| 39 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 40 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 41 | logging.basicConfig(level=logging.DEBUG, |
| 42 | format='%(asctime)s %(name)-32s ' |
| 43 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
| 45 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 46 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 47 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 48 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 49 | def test_jobs_launched(self): |
| 50 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 51 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 52 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 53 | A.addApproval('code-review', 2) |
| 54 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 55 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 56 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 61 | 'SUCCESS') |
| 62 | self.assertEqual(A.data['status'], 'MERGED') |
| 63 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 64 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 65 | 'image1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 66 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 67 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 68 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 70 | value='1|g') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 72 | kind='ms') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 74 | value='1|c') |
| 75 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 76 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 77 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 79 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 80 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 81 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 82 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 83 | for build in self.builds: |
| 84 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 85 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 86 | def test_initial_pipeline_gauges(self): |
| 87 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 88 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 89 | value='0|g') |
| 90 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 91 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 92 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 93 | def test_job_branch(self): |
| 94 | "Test the correct variant of a job runs on a branch" |
| 95 | self.create_branch('org/project', 'stable') |
| 96 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 97 | A.addApproval('code-review', 2) |
| 98 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 99 | self.waitUntilSettled() |
| 100 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 101 | 'SUCCESS') |
| 102 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 103 | 'SUCCESS') |
| 104 | self.assertEqual(A.data['status'], 'MERGED') |
| 105 | self.assertEqual(A.reported, 2, |
| 106 | "A should report start and success") |
| 107 | self.assertIn('gate', A.messages[1], |
| 108 | "A should transit gate") |
| 109 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 110 | 'image2') |
| 111 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 112 | def test_parallel_changes(self): |
| 113 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 114 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 115 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 116 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 117 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 118 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 119 | A.addApproval('code-review', 2) |
| 120 | B.addApproval('code-review', 2) |
| 121 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 122 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 123 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 124 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 125 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 126 | |
| 127 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 128 | self.assertEqual(len(self.builds), 1) |
| 129 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 130 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 131 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 132 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 133 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 134 | self.assertEqual(len(self.builds), 3) |
| 135 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 136 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 138 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 139 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 140 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 141 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 142 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 144 | self.assertEqual(len(self.builds), 5) |
| 145 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 146 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 147 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 148 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 149 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 150 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 152 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 153 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 154 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 155 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 158 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 159 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 160 | self.assertEqual(len(self.builds), 6) |
| 161 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 164 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 165 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 168 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 169 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 173 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 174 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 175 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 176 | self.launch_server.hold_jobs_in_build = False |
| 177 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 180 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 181 | self.assertEqual(len(self.history), 9) |
| 182 | self.assertEqual(A.data['status'], 'MERGED') |
| 183 | self.assertEqual(B.data['status'], 'MERGED') |
| 184 | self.assertEqual(C.data['status'], 'MERGED') |
| 185 | self.assertEqual(A.reported, 2) |
| 186 | self.assertEqual(B.reported, 2) |
| 187 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 188 | |
| 189 | def test_failed_changes(self): |
| 190 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 191 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 192 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 193 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 194 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 195 | A.addApproval('code-review', 2) |
| 196 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 197 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 198 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 199 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 200 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 201 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 202 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 203 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 204 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 205 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 206 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 207 | # A/project-merge is complete |
| 208 | self.assertBuilds([ |
| 209 | dict(name='project-test1', changes='1,1'), |
| 210 | dict(name='project-test2', changes='1,1'), |
| 211 | dict(name='project-merge', changes='1,1 2,1'), |
| 212 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 213 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 214 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 215 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 216 | # A/project-merge is complete |
| 217 | # B/project-merge is complete |
| 218 | self.assertBuilds([ |
| 219 | dict(name='project-test1', changes='1,1'), |
| 220 | dict(name='project-test2', changes='1,1'), |
| 221 | dict(name='project-test1', changes='1,1 2,1'), |
| 222 | dict(name='project-test2', changes='1,1 2,1'), |
| 223 | ]) |
| 224 | |
| 225 | # Release project-test1 for A which will fail. This will |
| 226 | # abort both running B jobs and relaunch project-merge for B. |
| 227 | self.builds[0].release() |
| 228 | self.waitUntilSettled() |
| 229 | |
| 230 | self.orderedRelease() |
| 231 | self.assertHistory([ |
| 232 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 233 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 234 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 235 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 236 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 237 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 238 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 239 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 240 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 241 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 242 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 243 | self.assertEqual(A.data['status'], 'NEW') |
| 244 | self.assertEqual(B.data['status'], 'MERGED') |
| 245 | self.assertEqual(A.reported, 2) |
| 246 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 247 | |
| 248 | def test_independent_queues(self): |
| 249 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 250 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 251 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 252 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 253 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 254 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 255 | A.addApproval('code-review', 2) |
| 256 | B.addApproval('code-review', 2) |
| 257 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 258 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 259 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 260 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 261 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 262 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 263 | self.waitUntilSettled() |
| 264 | |
| 265 | # There should be one merge job at the head of each queue running |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 266 | self.assertBuilds([ |
| 267 | dict(name='project-merge', changes='1,1'), |
| 268 | dict(name='project-merge', changes='2,1'), |
| 269 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 270 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 271 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 272 | self.builds[0].release() |
| 273 | self.waitUntilSettled() |
| 274 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 275 | self.waitUntilSettled() |
| 276 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 277 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 278 | self.waitUntilSettled() |
| 279 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 280 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 281 | self.assertBuilds([ |
| 282 | dict(name='project-test1', changes='1,1'), |
| 283 | dict(name='project-test2', changes='1,1'), |
| 284 | dict(name='project-test1', changes='2,1'), |
| 285 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 286 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 287 | dict(name='project-test1', changes='2,1 3,1'), |
| 288 | dict(name='project-test2', changes='2,1 3,1'), |
| 289 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 290 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 291 | self.orderedRelease() |
| 292 | self.assertHistory([ |
| 293 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 294 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 295 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 296 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 298 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 299 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 300 | dict( |
| 301 | name='project1-project2-integration', |
| 302 | result='SUCCESS', |
| 303 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 304 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 305 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
| 306 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 307 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 308 | self.assertEqual(A.data['status'], 'MERGED') |
| 309 | self.assertEqual(B.data['status'], 'MERGED') |
| 310 | self.assertEqual(C.data['status'], 'MERGED') |
| 311 | self.assertEqual(A.reported, 2) |
| 312 | self.assertEqual(B.reported, 2) |
| 313 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 314 | |
| 315 | def test_failed_change_at_head(self): |
| 316 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 317 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 318 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 319 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 320 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 321 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 322 | A.addApproval('code-review', 2) |
| 323 | B.addApproval('code-review', 2) |
| 324 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 325 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 326 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 327 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 328 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 329 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 330 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 331 | |
| 332 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 333 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 334 | self.assertBuilds([ |
| 335 | dict(name='project-merge', changes='1,1'), |
| 336 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 338 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 339 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 340 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 341 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 342 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | self.waitUntilSettled() |
| 344 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 345 | self.assertBuilds([ |
| 346 | dict(name='project-test1', changes='1,1'), |
| 347 | dict(name='project-test2', changes='1,1'), |
| 348 | dict(name='project-test1', changes='1,1 2,1'), |
| 349 | dict(name='project-test2', changes='1,1 2,1'), |
| 350 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 351 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 352 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 354 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 355 | self.waitUntilSettled() |
| 356 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 357 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 358 | self.assertBuilds([ |
| 359 | dict(name='project-test2', changes='1,1'), |
| 360 | dict(name='project-merge', changes='2,1'), |
| 361 | ]) |
| 362 | # Unordered history comparison because the aborts can finish |
| 363 | # in any order. |
| 364 | self.assertHistory([ |
| 365 | dict(name='project-merge', result='SUCCESS', |
| 366 | changes='1,1'), |
| 367 | dict(name='project-merge', result='SUCCESS', |
| 368 | changes='1,1 2,1'), |
| 369 | dict(name='project-merge', result='SUCCESS', |
| 370 | changes='1,1 2,1 3,1'), |
| 371 | dict(name='project-test1', result='FAILURE', |
| 372 | changes='1,1'), |
| 373 | dict(name='project-test1', result='ABORTED', |
| 374 | changes='1,1 2,1'), |
| 375 | dict(name='project-test2', result='ABORTED', |
| 376 | changes='1,1 2,1'), |
| 377 | dict(name='project-test1', result='ABORTED', |
| 378 | changes='1,1 2,1 3,1'), |
| 379 | dict(name='project-test2', result='ABORTED', |
| 380 | changes='1,1 2,1 3,1'), |
| 381 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 383 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 384 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 385 | self.launch_server.release('.*-merge') |
| 386 | self.waitUntilSettled() |
| 387 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 389 | self.assertBuilds([]) |
| 390 | self.assertHistory([ |
| 391 | dict(name='project-merge', result='SUCCESS', |
| 392 | changes='1,1'), |
| 393 | dict(name='project-merge', result='SUCCESS', |
| 394 | changes='1,1 2,1'), |
| 395 | dict(name='project-merge', result='SUCCESS', |
| 396 | changes='1,1 2,1 3,1'), |
| 397 | dict(name='project-test1', result='FAILURE', |
| 398 | changes='1,1'), |
| 399 | dict(name='project-test1', result='ABORTED', |
| 400 | changes='1,1 2,1'), |
| 401 | dict(name='project-test2', result='ABORTED', |
| 402 | changes='1,1 2,1'), |
| 403 | dict(name='project-test1', result='ABORTED', |
| 404 | changes='1,1 2,1 3,1'), |
| 405 | dict(name='project-test2', result='ABORTED', |
| 406 | changes='1,1 2,1 3,1'), |
| 407 | dict(name='project-merge', result='SUCCESS', |
| 408 | changes='2,1'), |
| 409 | dict(name='project-merge', result='SUCCESS', |
| 410 | changes='2,1 3,1'), |
| 411 | dict(name='project-test2', result='SUCCESS', |
| 412 | changes='1,1'), |
| 413 | dict(name='project-test1', result='SUCCESS', |
| 414 | changes='2,1'), |
| 415 | dict(name='project-test2', result='SUCCESS', |
| 416 | changes='2,1'), |
| 417 | dict(name='project-test1', result='SUCCESS', |
| 418 | changes='2,1 3,1'), |
| 419 | dict(name='project-test2', result='SUCCESS', |
| 420 | changes='2,1 3,1'), |
| 421 | ], ordered=False) |
| 422 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 423 | self.assertEqual(A.data['status'], 'NEW') |
| 424 | self.assertEqual(B.data['status'], 'MERGED') |
| 425 | self.assertEqual(C.data['status'], 'MERGED') |
| 426 | self.assertEqual(A.reported, 2) |
| 427 | self.assertEqual(B.reported, 2) |
| 428 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 429 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 430 | def test_failed_change_in_middle(self): |
| 431 | "Test a failed change in the middle of the queue" |
| 432 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 433 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 434 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 435 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 436 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 437 | A.addApproval('code-review', 2) |
| 438 | B.addApproval('code-review', 2) |
| 439 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 440 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 441 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 442 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 443 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 444 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 445 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 446 | |
| 447 | self.waitUntilSettled() |
| 448 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 449 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 451 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 452 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 453 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 454 | self.waitUntilSettled() |
| 455 | |
| 456 | self.assertEqual(len(self.builds), 6) |
| 457 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 458 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 459 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 460 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 461 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 462 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 463 | |
| 464 | self.release(self.builds[2]) |
| 465 | self.waitUntilSettled() |
| 466 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 467 | # project-test1 and project-test2 for A |
| 468 | # project-test2 for B |
| 469 | # project-merge for C (without B) |
| 470 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 471 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 472 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 473 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 474 | self.waitUntilSettled() |
| 475 | |
| 476 | # project-test1 and project-test2 for A |
| 477 | # project-test2 for B |
| 478 | # project-test1 and project-test2 for C |
| 479 | self.assertEqual(len(self.builds), 5) |
| 480 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 481 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 482 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 483 | builds = items[0].current_build_set.getBuilds() |
| 484 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 485 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 486 | builds = items[1].current_build_set.getBuilds() |
| 487 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 488 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 489 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 490 | builds = items[2].current_build_set.getBuilds() |
| 491 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 492 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 493 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 494 | self.launch_server.hold_jobs_in_build = False |
| 495 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 496 | self.waitUntilSettled() |
| 497 | |
| 498 | self.assertEqual(len(self.builds), 0) |
| 499 | self.assertEqual(len(self.history), 12) |
| 500 | self.assertEqual(A.data['status'], 'MERGED') |
| 501 | self.assertEqual(B.data['status'], 'NEW') |
| 502 | self.assertEqual(C.data['status'], 'MERGED') |
| 503 | self.assertEqual(A.reported, 2) |
| 504 | self.assertEqual(B.reported, 2) |
| 505 | self.assertEqual(C.reported, 2) |
| 506 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 507 | def test_failed_change_at_head_with_queue(self): |
| 508 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 509 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 510 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 511 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 512 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 513 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 514 | A.addApproval('code-review', 2) |
| 515 | B.addApproval('code-review', 2) |
| 516 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 517 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 518 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 519 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 520 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 521 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 522 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 523 | |
| 524 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 525 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 526 | self.assertEqual(len(self.builds), 0) |
| 527 | self.assertEqual(len(queue), 1) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 528 | self.assertEqual(queue[0].name, 'launcher:launch') |
| 529 | job_args = json.loads(queue[0].arguments) |
| 530 | self.assertEqual(job_args['job'], 'project-merge') |
| 531 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 532 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 533 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 534 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 535 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 536 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 537 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 538 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 539 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 540 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 541 | self.assertEqual(len(self.builds), 0) |
| 542 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 543 | |
| 544 | self.assertEqual( |
| 545 | json.loads(queue[0].arguments)['job'], 'project-test1') |
| 546 | self.assertEqual( |
| 547 | json.loads(queue[1].arguments)['job'], 'project-test2') |
| 548 | self.assertEqual( |
| 549 | json.loads(queue[2].arguments)['job'], 'project-test1') |
| 550 | self.assertEqual( |
| 551 | json.loads(queue[3].arguments)['job'], 'project-test2') |
| 552 | self.assertEqual( |
| 553 | json.loads(queue[4].arguments)['job'], 'project-test1') |
| 554 | self.assertEqual( |
| 555 | json.loads(queue[5].arguments)['job'], 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 556 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 557 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 558 | self.waitUntilSettled() |
| 559 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 560 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 561 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 562 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 563 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 564 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 565 | self.gearman_server.hold_jobs_in_queue = False |
| 566 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 567 | self.waitUntilSettled() |
| 568 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 569 | self.assertEqual(len(self.builds), 0) |
| 570 | self.assertEqual(len(self.history), 11) |
| 571 | self.assertEqual(A.data['status'], 'NEW') |
| 572 | self.assertEqual(B.data['status'], 'MERGED') |
| 573 | self.assertEqual(C.data['status'], 'MERGED') |
| 574 | self.assertEqual(A.reported, 2) |
| 575 | self.assertEqual(B.reported, 2) |
| 576 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 577 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 578 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 579 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 580 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 582 | A.addApproval('code-review', 2) |
| 583 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 584 | self.waitUntilSettled() |
| 585 | time.sleep(2) |
| 586 | |
| 587 | data = json.loads(self.sched.formatStatusJSON()) |
| 588 | found_job = None |
| 589 | for pipeline in data['pipelines']: |
| 590 | if pipeline['name'] != 'gate': |
| 591 | continue |
| 592 | for queue in pipeline['change_queues']: |
| 593 | for head in queue['heads']: |
| 594 | for item in head: |
| 595 | for job in item['jobs']: |
| 596 | if job['name'] == 'project-merge': |
| 597 | found_job = job |
| 598 | break |
| 599 | |
| 600 | self.assertIsNotNone(found_job) |
| 601 | if iteration == 1: |
| 602 | self.assertIsNotNone(found_job['estimated_time']) |
| 603 | self.assertIsNone(found_job['remaining_time']) |
| 604 | else: |
| 605 | self.assertIsNotNone(found_job['estimated_time']) |
| 606 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 607 | self.assertIsNotNone(found_job['remaining_time']) |
| 608 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 609 | self.launch_server.hold_jobs_in_build = False |
| 610 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 611 | self.waitUntilSettled() |
| 612 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 613 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 614 | def test_time_database(self): |
| 615 | "Test the time database" |
| 616 | |
| 617 | self._test_time_database(1) |
| 618 | self._test_time_database(2) |
| 619 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 620 | def test_two_failed_changes_at_head(self): |
| 621 | "Test that changes are reparented correctly if 2 fail at head" |
| 622 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 623 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 624 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 625 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 626 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 627 | A.addApproval('code-review', 2) |
| 628 | B.addApproval('code-review', 2) |
| 629 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 630 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 631 | self.launch_server.failJob('project-test1', A) |
| 632 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 633 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 634 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 635 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 636 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 637 | self.waitUntilSettled() |
| 638 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 639 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 640 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 641 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 642 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 643 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 644 | self.waitUntilSettled() |
| 645 | |
| 646 | self.assertEqual(len(self.builds), 6) |
| 647 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 648 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 649 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 650 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 651 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 652 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 653 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 654 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 655 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 656 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 657 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 658 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 659 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 660 | |
| 661 | # Fail change B first |
| 662 | self.release(self.builds[2]) |
| 663 | self.waitUntilSettled() |
| 664 | |
| 665 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 666 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 667 | self.waitUntilSettled() |
| 668 | |
| 669 | self.assertEqual(len(self.builds), 5) |
| 670 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 671 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 672 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 673 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 674 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 675 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 676 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 677 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 678 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 679 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 680 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 681 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | |
| 683 | # Finish running all passing jobs for change A |
| 684 | self.release(self.builds[1]) |
| 685 | self.waitUntilSettled() |
| 686 | # Fail and report change A |
| 687 | self.release(self.builds[0]) |
| 688 | self.waitUntilSettled() |
| 689 | |
| 690 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 691 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 692 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 693 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 694 | self.waitUntilSettled() |
| 695 | |
| 696 | self.assertEqual(len(self.builds), 4) |
| 697 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 698 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 699 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 700 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 701 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 702 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 703 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 704 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 706 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | # After A failed and B and C restarted, B should be back in |
| 708 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 709 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 710 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 711 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 712 | self.launch_server.hold_jobs_in_build = False |
| 713 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 714 | self.waitUntilSettled() |
| 715 | |
| 716 | self.assertEqual(len(self.builds), 0) |
| 717 | self.assertEqual(len(self.history), 21) |
| 718 | self.assertEqual(A.data['status'], 'NEW') |
| 719 | self.assertEqual(B.data['status'], 'NEW') |
| 720 | self.assertEqual(C.data['status'], 'MERGED') |
| 721 | self.assertEqual(A.reported, 2) |
| 722 | self.assertEqual(B.reported, 2) |
| 723 | self.assertEqual(C.reported, 2) |
| 724 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 725 | def test_patch_order(self): |
| 726 | "Test that dependent patches are tested in the right order" |
| 727 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 728 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 729 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 730 | A.addApproval('code-review', 2) |
| 731 | B.addApproval('code-review', 2) |
| 732 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 733 | |
| 734 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 735 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 736 | M2.setMerged() |
| 737 | M1.setMerged() |
| 738 | |
| 739 | # C -> B -> A -> M1 -> M2 |
| 740 | # M2 is here to make sure it is never queried. If it is, it |
| 741 | # means zuul is walking down the entire history of merged |
| 742 | # changes. |
| 743 | |
| 744 | C.setDependsOn(B, 1) |
| 745 | B.setDependsOn(A, 1) |
| 746 | A.setDependsOn(M1, 1) |
| 747 | M1.setDependsOn(M2, 1) |
| 748 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 749 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 750 | |
| 751 | self.waitUntilSettled() |
| 752 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 753 | self.assertEqual(A.data['status'], 'NEW') |
| 754 | self.assertEqual(B.data['status'], 'NEW') |
| 755 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 756 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 757 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 758 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 759 | |
| 760 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 761 | self.assertEqual(M2.queried, 0) |
| 762 | self.assertEqual(A.data['status'], 'MERGED') |
| 763 | self.assertEqual(B.data['status'], 'MERGED') |
| 764 | self.assertEqual(C.data['status'], 'MERGED') |
| 765 | self.assertEqual(A.reported, 2) |
| 766 | self.assertEqual(B.reported, 2) |
| 767 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 768 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 769 | def test_needed_changes_enqueue(self): |
| 770 | "Test that a needed change is enqueued ahead" |
| 771 | # A Given a git tree like this, if we enqueue |
| 772 | # / \ change C, we should walk up and down the tree |
| 773 | # B G and enqueue changes in the order ABCDEFG. |
| 774 | # /|\ This is also the order that you would get if |
| 775 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 776 | # / the ordering is stable across re-enqueue events. |
| 777 | # D |
| 778 | |
| 779 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 780 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 781 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 782 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 783 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 784 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 785 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 786 | B.setDependsOn(A, 1) |
| 787 | C.setDependsOn(B, 1) |
| 788 | D.setDependsOn(C, 1) |
| 789 | E.setDependsOn(B, 1) |
| 790 | F.setDependsOn(B, 1) |
| 791 | G.setDependsOn(A, 1) |
| 792 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 793 | A.addApproval('code-review', 2) |
| 794 | B.addApproval('code-review', 2) |
| 795 | C.addApproval('code-review', 2) |
| 796 | D.addApproval('code-review', 2) |
| 797 | E.addApproval('code-review', 2) |
| 798 | F.addApproval('code-review', 2) |
| 799 | G.addApproval('code-review', 2) |
| 800 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 801 | |
| 802 | self.waitUntilSettled() |
| 803 | |
| 804 | self.assertEqual(A.data['status'], 'NEW') |
| 805 | self.assertEqual(B.data['status'], 'NEW') |
| 806 | self.assertEqual(C.data['status'], 'NEW') |
| 807 | self.assertEqual(D.data['status'], 'NEW') |
| 808 | self.assertEqual(E.data['status'], 'NEW') |
| 809 | self.assertEqual(F.data['status'], 'NEW') |
| 810 | self.assertEqual(G.data['status'], 'NEW') |
| 811 | |
| 812 | # We're about to add approvals to changes without adding the |
| 813 | # triggering events to Zuul, so that we can be sure that it is |
| 814 | # enqueing the changes based on dependencies, not because of |
| 815 | # triggering events. Since it will have the changes cached |
| 816 | # already (without approvals), we need to clear the cache |
| 817 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 818 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 819 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 820 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 821 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 822 | A.addApproval('approved', 1) |
| 823 | B.addApproval('approved', 1) |
| 824 | D.addApproval('approved', 1) |
| 825 | E.addApproval('approved', 1) |
| 826 | F.addApproval('approved', 1) |
| 827 | G.addApproval('approved', 1) |
| 828 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 829 | |
| 830 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 831 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 832 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 833 | self.launch_server.hold_jobs_in_build = False |
| 834 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 835 | self.waitUntilSettled() |
| 836 | |
| 837 | self.assertEqual(A.data['status'], 'MERGED') |
| 838 | self.assertEqual(B.data['status'], 'MERGED') |
| 839 | self.assertEqual(C.data['status'], 'MERGED') |
| 840 | self.assertEqual(D.data['status'], 'MERGED') |
| 841 | self.assertEqual(E.data['status'], 'MERGED') |
| 842 | self.assertEqual(F.data['status'], 'MERGED') |
| 843 | self.assertEqual(G.data['status'], 'MERGED') |
| 844 | self.assertEqual(A.reported, 2) |
| 845 | self.assertEqual(B.reported, 2) |
| 846 | self.assertEqual(C.reported, 2) |
| 847 | self.assertEqual(D.reported, 2) |
| 848 | self.assertEqual(E.reported, 2) |
| 849 | self.assertEqual(F.reported, 2) |
| 850 | self.assertEqual(G.reported, 2) |
| 851 | self.assertEqual(self.history[6].changes, |
| 852 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 853 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 854 | def test_source_cache(self): |
| 855 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 856 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 857 | |
| 858 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 859 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 860 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 861 | A.addApproval('code-review', 2) |
| 862 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 863 | |
| 864 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 865 | M1.setMerged() |
| 866 | |
| 867 | B.setDependsOn(A, 1) |
| 868 | A.setDependsOn(M1, 1) |
| 869 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 870 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 871 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 872 | |
| 873 | self.waitUntilSettled() |
| 874 | |
| 875 | for build in self.builds: |
| 876 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 877 | build.release() |
| 878 | self.waitUntilSettled() |
| 879 | for build in self.builds: |
| 880 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 881 | build.release() |
| 882 | self.waitUntilSettled() |
| 883 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 884 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 885 | self.waitUntilSettled() |
| 886 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 887 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 888 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 889 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 890 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 891 | self.launch_server.hold_jobs_in_build = False |
| 892 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 893 | self.waitUntilSettled() |
| 894 | |
| 895 | self.assertEqual(A.data['status'], 'MERGED') |
| 896 | self.assertEqual(B.data['status'], 'MERGED') |
| 897 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 898 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 899 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 900 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 901 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 902 | # TODO: move to test_gerrit (this is a unit test!) |
| 903 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 904 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 905 | source = tenant.layout.pipelines['gate'].source |
| 906 | |
| 907 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 908 | # it easier for users to create events for testing. |
| 909 | event = zuul.model.TriggerEvent() |
| 910 | event.trigger_name = 'gerrit' |
| 911 | event.change_number = '1' |
| 912 | event.patch_number = '2' |
| 913 | |
| 914 | a = source.getChange(event) |
| 915 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 916 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 917 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 918 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 919 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 920 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 921 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 922 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 923 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 924 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 925 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 926 | @skip("Disabled for early v3 development") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 927 | def test_build_configuration(self): |
| 928 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 929 | |
| 930 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 931 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 932 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 933 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 934 | A.addApproval('code-review', 2) |
| 935 | B.addApproval('code-review', 2) |
| 936 | C.addApproval('code-review', 2) |
| 937 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 938 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 939 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 940 | self.waitUntilSettled() |
| 941 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 942 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 943 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 944 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 945 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 946 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 947 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 948 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 949 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 950 | self.gearman_server.hold_jobs_in_queue = False |
| 951 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 952 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 953 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 954 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 955 | repo = git.Repo(path) |
| 956 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 957 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 958 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 959 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 960 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 961 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 962 | def test_build_configuration_conflict(self): |
| 963 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 964 | |
| 965 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 966 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 967 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 968 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 969 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 970 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 971 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 972 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 973 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 974 | A.addApproval('code-review', 2) |
| 975 | B.addApproval('code-review', 2) |
| 976 | C.addApproval('code-review', 2) |
| 977 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 978 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 979 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 980 | self.waitUntilSettled() |
| 981 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 982 | self.assertEqual(A.reported, 1) |
| 983 | self.assertEqual(B.reported, 1) |
| 984 | self.assertEqual(C.reported, 1) |
| 985 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 986 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 987 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 988 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 989 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 990 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 991 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 992 | |
| 993 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 994 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 995 | self.gearman_server.hold_jobs_in_queue = False |
| 996 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 997 | self.waitUntilSettled() |
| 998 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 999 | self.assertEqual(A.data['status'], 'MERGED') |
| 1000 | self.assertEqual(B.data['status'], 'NEW') |
| 1001 | self.assertEqual(C.data['status'], 'MERGED') |
| 1002 | self.assertEqual(A.reported, 2) |
| 1003 | self.assertEqual(B.reported, 2) |
| 1004 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1005 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1006 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1007 | def test_post(self): |
| 1008 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1009 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1010 | e = { |
| 1011 | "type": "ref-updated", |
| 1012 | "submitter": { |
| 1013 | "name": "User Name", |
| 1014 | }, |
| 1015 | "refUpdate": { |
| 1016 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1017 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1018 | "refName": "master", |
| 1019 | "project": "org/project", |
| 1020 | } |
| 1021 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1022 | self.fake_gerrit.addEvent(e) |
| 1023 | self.waitUntilSettled() |
| 1024 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1025 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1026 | self.assertEqual(len(self.history), 1) |
| 1027 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1028 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1029 | def test_post_ignore_deletes(self): |
| 1030 | "Test that deleting refs does not trigger post jobs" |
| 1031 | |
| 1032 | e = { |
| 1033 | "type": "ref-updated", |
| 1034 | "submitter": { |
| 1035 | "name": "User Name", |
| 1036 | }, |
| 1037 | "refUpdate": { |
| 1038 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1039 | "newRev": "0000000000000000000000000000000000000000", |
| 1040 | "refName": "master", |
| 1041 | "project": "org/project", |
| 1042 | } |
| 1043 | } |
| 1044 | self.fake_gerrit.addEvent(e) |
| 1045 | self.waitUntilSettled() |
| 1046 | |
| 1047 | job_names = [x.name for x in self.history] |
| 1048 | self.assertEqual(len(self.history), 0) |
| 1049 | self.assertNotIn('project-post', job_names) |
| 1050 | |
| 1051 | def test_post_ignore_deletes_negative(self): |
| 1052 | "Test that deleting refs does trigger post jobs" |
| 1053 | |
Adam Gandelman | c5e4f1d | 2016-11-29 14:27:17 -0800 | [diff] [blame] | 1054 | self.updateConfigLayout('layout-dont-ignore-ref-deletes') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1055 | self.sched.reconfigure(self.config) |
| 1056 | |
| 1057 | e = { |
| 1058 | "type": "ref-updated", |
| 1059 | "submitter": { |
| 1060 | "name": "User Name", |
| 1061 | }, |
| 1062 | "refUpdate": { |
| 1063 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1064 | "newRev": "0000000000000000000000000000000000000000", |
| 1065 | "refName": "master", |
| 1066 | "project": "org/project", |
| 1067 | } |
| 1068 | } |
| 1069 | self.fake_gerrit.addEvent(e) |
| 1070 | self.waitUntilSettled() |
| 1071 | |
| 1072 | job_names = [x.name for x in self.history] |
| 1073 | self.assertEqual(len(self.history), 1) |
| 1074 | self.assertIn('project-post', job_names) |
| 1075 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1076 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1077 | def test_build_configuration_branch(self): |
| 1078 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1079 | |
| 1080 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1081 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1082 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1083 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1084 | A.addApproval('code-review', 2) |
| 1085 | B.addApproval('code-review', 2) |
| 1086 | C.addApproval('code-review', 2) |
| 1087 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1088 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1089 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1090 | self.waitUntilSettled() |
| 1091 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1092 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1093 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1094 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1095 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1096 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1097 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1098 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1099 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1100 | self.gearman_server.hold_jobs_in_queue = False |
| 1101 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1102 | self.waitUntilSettled() |
| 1103 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1104 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1105 | repo = git.Repo(path) |
| 1106 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1107 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1108 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1109 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1110 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1111 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1112 | def test_build_configuration_branch_interaction(self): |
| 1113 | "Test that switching between branches works" |
| 1114 | self.test_build_configuration() |
| 1115 | self.test_build_configuration_branch() |
| 1116 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1117 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1118 | repo = git.Repo(path) |
| 1119 | repo.heads.master.commit = repo.commit('init') |
| 1120 | self.test_build_configuration() |
| 1121 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1122 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1123 | def test_build_configuration_multi_branch(self): |
| 1124 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1125 | |
| 1126 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1127 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1128 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1129 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1130 | A.addApproval('code-review', 2) |
| 1131 | B.addApproval('code-review', 2) |
| 1132 | C.addApproval('code-review', 2) |
| 1133 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1134 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1135 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1136 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1137 | queue = self.gearman_server.getQueue() |
| 1138 | job_A = None |
| 1139 | for job in queue: |
| 1140 | if 'project-merge' in job.name: |
| 1141 | job_A = job |
| 1142 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1143 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1144 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1145 | 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] | 1146 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1147 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1148 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1149 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1150 | job_B = None |
| 1151 | for job in queue: |
| 1152 | if 'project-merge' in job.name: |
| 1153 | job_B = job |
| 1154 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1155 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1156 | 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] | 1157 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1158 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1159 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1160 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1161 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1162 | for job in queue: |
| 1163 | if 'project-merge' in job.name: |
| 1164 | job_C = job |
| 1165 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1166 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1167 | 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] | 1168 | 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] | 1169 | self.gearman_server.hold_jobs_in_queue = False |
| 1170 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1171 | self.waitUntilSettled() |
| 1172 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1173 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1174 | repo = git.Repo(path) |
| 1175 | |
| 1176 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1177 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1178 | 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] | 1179 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1180 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1181 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1182 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1183 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 1184 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1185 | |
| 1186 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1187 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1188 | 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] | 1189 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1190 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1191 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1192 | self.assertEqual(repo_shas[0], commit_B) |
| 1193 | |
| 1194 | repo_messages = [c.message.strip() |
| 1195 | for c in repo.iter_commits(ref_A)] |
| 1196 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1197 | repo_messages.reverse() |
| 1198 | correct_messages = ['initial commit', 'A-1'] |
| 1199 | self.assertEqual(repo_messages, correct_messages) |
| 1200 | self.assertEqual(repo_shas[0], commit_A) |
| 1201 | |
| 1202 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1203 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1204 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1205 | def test_dependent_changes_dequeue(self): |
| 1206 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1207 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1208 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1209 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1210 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1211 | A.addApproval('code-review', 2) |
| 1212 | B.addApproval('code-review', 2) |
| 1213 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1214 | |
| 1215 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1216 | M1.setMerged() |
| 1217 | |
| 1218 | # C -> B -> A -> M1 |
| 1219 | |
| 1220 | C.setDependsOn(B, 1) |
| 1221 | B.setDependsOn(A, 1) |
| 1222 | A.setDependsOn(M1, 1) |
| 1223 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1224 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1225 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1226 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1227 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1228 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1229 | |
| 1230 | self.waitUntilSettled() |
| 1231 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1232 | self.assertEqual(A.data['status'], 'NEW') |
| 1233 | self.assertEqual(A.reported, 2) |
| 1234 | self.assertEqual(B.data['status'], 'NEW') |
| 1235 | self.assertEqual(B.reported, 2) |
| 1236 | self.assertEqual(C.data['status'], 'NEW') |
| 1237 | self.assertEqual(C.reported, 2) |
| 1238 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1239 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1240 | def test_failing_dependent_changes(self): |
| 1241 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1242 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1243 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1244 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1245 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1246 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1247 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1248 | A.addApproval('code-review', 2) |
| 1249 | B.addApproval('code-review', 2) |
| 1250 | C.addApproval('code-review', 2) |
| 1251 | D.addApproval('code-review', 2) |
| 1252 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1253 | |
| 1254 | # E, D -> C -> B, A |
| 1255 | |
| 1256 | D.setDependsOn(C, 1) |
| 1257 | C.setDependsOn(B, 1) |
| 1258 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1259 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1260 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1261 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1262 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1263 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1264 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1265 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1266 | |
| 1267 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1268 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1269 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1270 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1271 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1272 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1273 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1274 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1275 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1276 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1277 | self.waitUntilSettled() |
| 1278 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1279 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1280 | for build in self.builds: |
| 1281 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1282 | build.release() |
| 1283 | self.waitUntilSettled() |
| 1284 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1285 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1286 | self.waitUntilSettled() |
| 1287 | |
| 1288 | self.assertEqual(A.data['status'], 'MERGED') |
| 1289 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1290 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1291 | self.assertEqual(B.data['status'], 'NEW') |
| 1292 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1293 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1294 | self.assertEqual(C.data['status'], 'NEW') |
| 1295 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1296 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1297 | self.assertEqual(D.data['status'], 'NEW') |
| 1298 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1299 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1300 | self.assertEqual(E.data['status'], 'MERGED') |
| 1301 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1302 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1303 | self.assertEqual(len(self.history), 18) |
| 1304 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1305 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1306 | "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] | 1307 | # If it's dequeued more than once, we should see extra |
| 1308 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1309 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1310 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1311 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1312 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1313 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1314 | A.addApproval('code-review', 2) |
| 1315 | B.addApproval('code-review', 2) |
| 1316 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1317 | |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1318 | self.launch_server.failJob('project-test1', A) |
| 1319 | self.launch_server.failJob('project-test2', A) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1320 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1321 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1322 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1323 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1324 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1325 | |
| 1326 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1327 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1328 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1329 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1330 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1331 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1332 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1333 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1334 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1335 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1336 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | self.waitUntilSettled() |
| 1338 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1339 | self.assertEqual(len(self.builds), 9) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1340 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1341 | self.assertEqual(self.builds[1].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1342 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1343 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1344 | self.assertEqual(self.builds[4].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1345 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1346 | self.assertEqual(self.builds[6].name, 'project-test1') |
| 1347 | self.assertEqual(self.builds[7].name, 'project-test2') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1348 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1349 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1350 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1351 | self.waitUntilSettled() |
| 1352 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1353 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1354 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1355 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1356 | self.launch_server.hold_jobs_in_build = False |
| 1357 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1358 | self.waitUntilSettled() |
| 1359 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1360 | self.assertEqual(len(self.builds), 0) |
| 1361 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1363 | self.assertEqual(A.data['status'], 'NEW') |
| 1364 | self.assertEqual(B.data['status'], 'MERGED') |
| 1365 | self.assertEqual(C.data['status'], 'MERGED') |
| 1366 | self.assertEqual(A.reported, 2) |
| 1367 | self.assertEqual(B.reported, 2) |
| 1368 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1369 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1370 | @skip("Disabled for early v3 development") |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1371 | def test_nonvoting_job(self): |
| 1372 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1373 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1374 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1375 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1376 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1377 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1378 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1379 | |
| 1380 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1381 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1382 | self.assertEqual(A.data['status'], 'MERGED') |
| 1383 | self.assertEqual(A.reported, 2) |
| 1384 | self.assertEqual( |
| 1385 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1386 | 'SUCCESS') |
| 1387 | self.assertEqual( |
| 1388 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1389 | 'SUCCESS') |
| 1390 | self.assertEqual( |
| 1391 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1392 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1393 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1394 | for build in self.builds: |
| 1395 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1396 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1397 | def test_check_queue_success(self): |
| 1398 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1399 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1400 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1401 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1402 | |
| 1403 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1404 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1405 | self.assertEqual(A.data['status'], 'NEW') |
| 1406 | self.assertEqual(A.reported, 1) |
| 1407 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1408 | 'SUCCESS') |
| 1409 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1410 | 'SUCCESS') |
| 1411 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1412 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1413 | |
| 1414 | def test_check_queue_failure(self): |
| 1415 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1416 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1417 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1418 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1419 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1420 | |
| 1421 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1422 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1423 | self.assertEqual(A.data['status'], 'NEW') |
| 1424 | self.assertEqual(A.reported, 1) |
| 1425 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1426 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1427 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1428 | 'SUCCESS') |
| 1429 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1430 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1431 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1432 | @skip("Disabled for early v3 development") |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1433 | def test_dependent_behind_dequeue(self): |
| 1434 | "test that dependent changes behind dequeued changes work" |
| 1435 | # This complicated test is a reproduction of a real life bug |
| 1436 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1437 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1438 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1439 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1440 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1441 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1442 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1443 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1444 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1445 | D.setDependsOn(C, 1) |
| 1446 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1447 | A.addApproval('code-review', 2) |
| 1448 | B.addApproval('code-review', 2) |
| 1449 | C.addApproval('code-review', 2) |
| 1450 | D.addApproval('code-review', 2) |
| 1451 | E.addApproval('code-review', 2) |
| 1452 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1453 | |
| 1454 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1455 | |
| 1456 | # Change object re-use in the gerrit trigger is hidden if |
| 1457 | # changes are added in quick succession; waiting makes it more |
| 1458 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1459 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1460 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1461 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1462 | self.waitUntilSettled() |
| 1463 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1464 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1465 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1466 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1467 | self.waitUntilSettled() |
| 1468 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1469 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1470 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1471 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1472 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1473 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1474 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1475 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1476 | self.waitUntilSettled() |
| 1477 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1478 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1479 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1480 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1481 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1482 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1483 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1484 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1485 | self.waitUntilSettled() |
| 1486 | |
| 1487 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1488 | |
| 1489 | # Grab pointers to the jobs we want to release before |
| 1490 | # releasing any, because list indexes may change as |
| 1491 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1492 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1493 | a.release() |
| 1494 | b.release() |
| 1495 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1496 | self.waitUntilSettled() |
| 1497 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1498 | self.launch_server.hold_jobs_in_build = False |
| 1499 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1500 | self.waitUntilSettled() |
| 1501 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1502 | self.assertEqual(A.data['status'], 'NEW') |
| 1503 | self.assertEqual(B.data['status'], 'MERGED') |
| 1504 | self.assertEqual(C.data['status'], 'MERGED') |
| 1505 | self.assertEqual(D.data['status'], 'MERGED') |
| 1506 | self.assertEqual(E.data['status'], 'MERGED') |
| 1507 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1508 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1509 | self.assertEqual(A.reported, 2) |
| 1510 | self.assertEqual(B.reported, 2) |
| 1511 | self.assertEqual(C.reported, 2) |
| 1512 | self.assertEqual(D.reported, 2) |
| 1513 | self.assertEqual(E.reported, 2) |
| 1514 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1515 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1516 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1517 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1518 | |
| 1519 | def test_merger_repack(self): |
| 1520 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1521 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1522 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1523 | A.addApproval('code-review', 2) |
| 1524 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1525 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1526 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1527 | 'SUCCESS') |
| 1528 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1529 | 'SUCCESS') |
| 1530 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1531 | 'SUCCESS') |
| 1532 | self.assertEqual(A.data['status'], 'MERGED') |
| 1533 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1534 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1535 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1536 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1537 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1538 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1539 | |
| 1540 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1541 | A.addApproval('code-review', 2) |
| 1542 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1543 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1544 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1545 | 'SUCCESS') |
| 1546 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1547 | 'SUCCESS') |
| 1548 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1549 | 'SUCCESS') |
| 1550 | self.assertEqual(A.data['status'], 'MERGED') |
| 1551 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1552 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1553 | def test_merger_repack_large_change(self): |
| 1554 | "Test that the merger works with large changes after a repack" |
| 1555 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1556 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1557 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1558 | url = self.fake_gerrit.getGitUrl( |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1559 | tenant.layout.project_configs.get('org/project1')) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1560 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1561 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1562 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1563 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1564 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1565 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1566 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1567 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1568 | A.addApproval('code-review', 2) |
| 1569 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1570 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1571 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1572 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1573 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1574 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1575 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1576 | 'SUCCESS') |
| 1577 | self.assertEqual(A.data['status'], 'MERGED') |
| 1578 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1579 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1580 | @skip("Disabled for early v3 development") |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1581 | def test_nonexistent_job(self): |
| 1582 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1583 | # Set to the state immediately after a restart |
| 1584 | self.resetGearmanServer() |
| 1585 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1586 | |
| 1587 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1588 | A.addApproval('code-review', 2) |
| 1589 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1590 | # There may be a thread about to report a lost change |
| 1591 | while A.reported < 2: |
| 1592 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1593 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1594 | self.assertFalse(job_names) |
| 1595 | self.assertEqual(A.data['status'], 'NEW') |
| 1596 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1597 | self.assertEmptyQueues() |
| 1598 | |
| 1599 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1600 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1601 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1602 | A.addApproval('code-review', 2) |
| 1603 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1604 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1605 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1606 | 'SUCCESS') |
| 1607 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1608 | 'SUCCESS') |
| 1609 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1610 | 'SUCCESS') |
| 1611 | self.assertEqual(A.data['status'], 'MERGED') |
| 1612 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1613 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1614 | def test_new_patchset_dequeues_old(self): |
| 1615 | "Test that a new patchset causes the old to be dequeued" |
| 1616 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1617 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1618 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1619 | M.setMerged() |
| 1620 | |
| 1621 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1622 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1623 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1624 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1625 | A.addApproval('code-review', 2) |
| 1626 | B.addApproval('code-review', 2) |
| 1627 | C.addApproval('code-review', 2) |
| 1628 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1629 | |
| 1630 | C.setDependsOn(B, 1) |
| 1631 | B.setDependsOn(A, 1) |
| 1632 | A.setDependsOn(M, 1) |
| 1633 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1634 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1635 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1636 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1637 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1638 | self.waitUntilSettled() |
| 1639 | |
| 1640 | B.addPatchset() |
| 1641 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1642 | self.waitUntilSettled() |
| 1643 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1644 | self.launch_server.hold_jobs_in_build = False |
| 1645 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1646 | self.waitUntilSettled() |
| 1647 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1648 | self.assertEqual(A.data['status'], 'MERGED') |
| 1649 | self.assertEqual(A.reported, 2) |
| 1650 | self.assertEqual(B.data['status'], 'NEW') |
| 1651 | self.assertEqual(B.reported, 2) |
| 1652 | self.assertEqual(C.data['status'], 'NEW') |
| 1653 | self.assertEqual(C.reported, 2) |
| 1654 | self.assertEqual(D.data['status'], 'MERGED') |
| 1655 | self.assertEqual(D.reported, 2) |
| 1656 | 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] | 1657 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1658 | def test_new_patchset_check(self): |
| 1659 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1660 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1661 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1662 | |
| 1663 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1664 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1665 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1666 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1667 | |
| 1668 | # Add two git-dependent changes |
| 1669 | B.setDependsOn(A, 1) |
| 1670 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1671 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1672 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1673 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1674 | |
| 1675 | # A live item, and a non-live/live pair |
| 1676 | items = check_pipeline.getAllItems() |
| 1677 | self.assertEqual(len(items), 3) |
| 1678 | |
| 1679 | self.assertEqual(items[0].change.number, '1') |
| 1680 | self.assertEqual(items[0].change.patchset, '1') |
| 1681 | self.assertFalse(items[0].live) |
| 1682 | |
| 1683 | self.assertEqual(items[1].change.number, '2') |
| 1684 | self.assertEqual(items[1].change.patchset, '1') |
| 1685 | self.assertTrue(items[1].live) |
| 1686 | |
| 1687 | self.assertEqual(items[2].change.number, '1') |
| 1688 | self.assertEqual(items[2].change.patchset, '1') |
| 1689 | self.assertTrue(items[2].live) |
| 1690 | |
| 1691 | # Add a new patchset to A |
| 1692 | A.addPatchset() |
| 1693 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1694 | self.waitUntilSettled() |
| 1695 | |
| 1696 | # The live copy of A,1 should be gone, but the non-live and B |
| 1697 | # should continue, and we should have a new A,2 |
| 1698 | items = check_pipeline.getAllItems() |
| 1699 | self.assertEqual(len(items), 3) |
| 1700 | |
| 1701 | self.assertEqual(items[0].change.number, '1') |
| 1702 | self.assertEqual(items[0].change.patchset, '1') |
| 1703 | self.assertFalse(items[0].live) |
| 1704 | |
| 1705 | self.assertEqual(items[1].change.number, '2') |
| 1706 | self.assertEqual(items[1].change.patchset, '1') |
| 1707 | self.assertTrue(items[1].live) |
| 1708 | |
| 1709 | self.assertEqual(items[2].change.number, '1') |
| 1710 | self.assertEqual(items[2].change.patchset, '2') |
| 1711 | self.assertTrue(items[2].live) |
| 1712 | |
| 1713 | # Add a new patchset to B |
| 1714 | B.addPatchset() |
| 1715 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1716 | self.waitUntilSettled() |
| 1717 | |
| 1718 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1719 | # but we should have a new B,2 (still based on A,1) |
| 1720 | items = check_pipeline.getAllItems() |
| 1721 | self.assertEqual(len(items), 3) |
| 1722 | |
| 1723 | self.assertEqual(items[0].change.number, '1') |
| 1724 | self.assertEqual(items[0].change.patchset, '2') |
| 1725 | self.assertTrue(items[0].live) |
| 1726 | |
| 1727 | self.assertEqual(items[1].change.number, '1') |
| 1728 | self.assertEqual(items[1].change.patchset, '1') |
| 1729 | self.assertFalse(items[1].live) |
| 1730 | |
| 1731 | self.assertEqual(items[2].change.number, '2') |
| 1732 | self.assertEqual(items[2].change.patchset, '2') |
| 1733 | self.assertTrue(items[2].live) |
| 1734 | |
| 1735 | self.builds[0].release() |
| 1736 | self.waitUntilSettled() |
| 1737 | self.builds[0].release() |
| 1738 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1739 | self.launch_server.hold_jobs_in_build = False |
| 1740 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1741 | self.waitUntilSettled() |
| 1742 | |
| 1743 | self.assertEqual(A.reported, 1) |
| 1744 | self.assertEqual(B.reported, 1) |
| 1745 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1746 | self.assertEqual(self.history[0].changes, '1,1') |
| 1747 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1748 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1749 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1750 | self.assertEqual(self.history[2].changes, '1,2') |
| 1751 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1752 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1753 | |
| 1754 | def test_abandoned_gate(self): |
| 1755 | "Test that an abandoned change is dequeued from gate" |
| 1756 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1757 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1758 | |
| 1759 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1760 | A.addApproval('code-review', 2) |
| 1761 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1762 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1763 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1764 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1765 | |
| 1766 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1767 | self.waitUntilSettled() |
| 1768 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1769 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1770 | self.waitUntilSettled() |
| 1771 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1772 | self.assertBuilds([]) |
| 1773 | self.assertHistory([ |
| 1774 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1775 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1776 | self.assertEqual(A.reported, 1, |
| 1777 | "Abandoned gate change should report only start") |
| 1778 | |
| 1779 | def test_abandoned_check(self): |
| 1780 | "Test that an abandoned change is dequeued from check" |
| 1781 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1782 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1783 | |
| 1784 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1785 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1786 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1787 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1788 | |
| 1789 | # Add two git-dependent changes |
| 1790 | B.setDependsOn(A, 1) |
| 1791 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1792 | self.waitUntilSettled() |
| 1793 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1794 | self.waitUntilSettled() |
| 1795 | # A live item, and a non-live/live pair |
| 1796 | items = check_pipeline.getAllItems() |
| 1797 | self.assertEqual(len(items), 3) |
| 1798 | |
| 1799 | self.assertEqual(items[0].change.number, '1') |
| 1800 | self.assertFalse(items[0].live) |
| 1801 | |
| 1802 | self.assertEqual(items[1].change.number, '2') |
| 1803 | self.assertTrue(items[1].live) |
| 1804 | |
| 1805 | self.assertEqual(items[2].change.number, '1') |
| 1806 | self.assertTrue(items[2].live) |
| 1807 | |
| 1808 | # Abandon A |
| 1809 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1810 | self.waitUntilSettled() |
| 1811 | |
| 1812 | # The live copy of A should be gone, but the non-live and B |
| 1813 | # should continue |
| 1814 | items = check_pipeline.getAllItems() |
| 1815 | self.assertEqual(len(items), 2) |
| 1816 | |
| 1817 | self.assertEqual(items[0].change.number, '1') |
| 1818 | self.assertFalse(items[0].live) |
| 1819 | |
| 1820 | self.assertEqual(items[1].change.number, '2') |
| 1821 | self.assertTrue(items[1].live) |
| 1822 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1823 | self.launch_server.hold_jobs_in_build = False |
| 1824 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1825 | self.waitUntilSettled() |
| 1826 | |
| 1827 | self.assertEqual(len(self.history), 4) |
| 1828 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1829 | 'Build should have been aborted') |
| 1830 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1831 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1832 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1833 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1834 | def test_abandoned_not_timer(self): |
| 1835 | "Test that an abandoned change does not cancel timer jobs" |
| 1836 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1837 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1838 | |
| 1839 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1840 | self.updateConfigLayout( |
| 1841 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1842 | self.sched.reconfigure(self.config) |
| 1843 | self.registerJobs() |
| 1844 | # The pipeline triggers every second, so we should have seen |
| 1845 | # several by now. |
| 1846 | time.sleep(5) |
| 1847 | self.waitUntilSettled() |
| 1848 | # Stop queuing timer triggered jobs so that the assertions |
| 1849 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1850 | self.updateConfigLayout( |
| 1851 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1852 | self.sched.reconfigure(self.config) |
| 1853 | self.registerJobs() |
| 1854 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1855 | |
| 1856 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1857 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1858 | self.waitUntilSettled() |
| 1859 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1860 | |
| 1861 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1862 | self.waitUntilSettled() |
| 1863 | |
| 1864 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1865 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1866 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1867 | self.waitUntilSettled() |
| 1868 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1869 | def test_zuul_url_return(self): |
| 1870 | "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] | 1871 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1872 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1873 | |
| 1874 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1875 | A.addApproval('code-review', 2) |
| 1876 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1877 | self.waitUntilSettled() |
| 1878 | |
| 1879 | self.assertEqual(len(self.builds), 1) |
| 1880 | for build in self.builds: |
| 1881 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1882 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1883 | self.launch_server.hold_jobs_in_build = False |
| 1884 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1885 | self.waitUntilSettled() |
| 1886 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1887 | def test_new_patchset_dequeues_old_on_head(self): |
| 1888 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1889 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1890 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1891 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1892 | M.setMerged() |
| 1893 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1894 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1895 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1896 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1897 | A.addApproval('code-review', 2) |
| 1898 | B.addApproval('code-review', 2) |
| 1899 | C.addApproval('code-review', 2) |
| 1900 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1901 | |
| 1902 | C.setDependsOn(B, 1) |
| 1903 | B.setDependsOn(A, 1) |
| 1904 | A.setDependsOn(M, 1) |
| 1905 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1906 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1907 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1908 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1909 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1910 | self.waitUntilSettled() |
| 1911 | |
| 1912 | A.addPatchset() |
| 1913 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1914 | self.waitUntilSettled() |
| 1915 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1916 | self.launch_server.hold_jobs_in_build = False |
| 1917 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1918 | self.waitUntilSettled() |
| 1919 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1920 | self.assertEqual(A.data['status'], 'NEW') |
| 1921 | self.assertEqual(A.reported, 2) |
| 1922 | self.assertEqual(B.data['status'], 'NEW') |
| 1923 | self.assertEqual(B.reported, 2) |
| 1924 | self.assertEqual(C.data['status'], 'NEW') |
| 1925 | self.assertEqual(C.reported, 2) |
| 1926 | self.assertEqual(D.data['status'], 'MERGED') |
| 1927 | self.assertEqual(D.reported, 2) |
| 1928 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1929 | |
| 1930 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1931 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1932 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1933 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1934 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1935 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1936 | A.addApproval('code-review', 2) |
| 1937 | B.addApproval('code-review', 2) |
| 1938 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1939 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1940 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1941 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1942 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1943 | self.waitUntilSettled() |
| 1944 | |
| 1945 | B.addPatchset() |
| 1946 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1947 | self.waitUntilSettled() |
| 1948 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1949 | self.launch_server.hold_jobs_in_build = False |
| 1950 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1951 | self.waitUntilSettled() |
| 1952 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1953 | self.assertEqual(A.data['status'], 'MERGED') |
| 1954 | self.assertEqual(A.reported, 2) |
| 1955 | self.assertEqual(B.data['status'], 'NEW') |
| 1956 | self.assertEqual(B.reported, 2) |
| 1957 | self.assertEqual(C.data['status'], 'MERGED') |
| 1958 | self.assertEqual(C.reported, 2) |
| 1959 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1960 | |
| 1961 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1962 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1963 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1964 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1965 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1966 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1967 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1968 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1969 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1970 | self.waitUntilSettled() |
| 1971 | |
| 1972 | B.addPatchset() |
| 1973 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1974 | self.waitUntilSettled() |
| 1975 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1976 | self.launch_server.hold_jobs_in_build = False |
| 1977 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1978 | self.waitUntilSettled() |
| 1979 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1980 | self.assertEqual(A.data['status'], 'NEW') |
| 1981 | self.assertEqual(A.reported, 1) |
| 1982 | self.assertEqual(B.data['status'], 'NEW') |
| 1983 | self.assertEqual(B.reported, 1) |
| 1984 | self.assertEqual(C.data['status'], 'NEW') |
| 1985 | self.assertEqual(C.reported, 1) |
| 1986 | self.assertEqual(len(self.history), 10) |
| 1987 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1988 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1989 | def test_noop_job(self): |
| 1990 | "Test that the internal noop job works" |
| 1991 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1992 | A.addApproval('code-review', 2) |
| 1993 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1994 | self.waitUntilSettled() |
| 1995 | |
| 1996 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1997 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1998 | self.assertEqual(len(self.history), 0) |
| 1999 | self.assertEqual(A.data['status'], 'MERGED') |
| 2000 | self.assertEqual(A.reported, 2) |
| 2001 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2002 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2003 | def test_no_job_project(self): |
| 2004 | "Test that reports with no jobs don't get sent" |
| 2005 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2006 | 'master', 'A') |
| 2007 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2008 | self.waitUntilSettled() |
| 2009 | |
| 2010 | # Change wasn't reported to |
| 2011 | self.assertEqual(A.reported, False) |
| 2012 | |
| 2013 | # Check queue is empty afterwards |
| 2014 | check_pipeline = self.sched.layout.pipelines['check'] |
| 2015 | items = check_pipeline.getAllItems() |
| 2016 | self.assertEqual(len(items), 0) |
| 2017 | |
| 2018 | self.assertEqual(len(self.history), 0) |
| 2019 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2020 | def test_zuul_refs(self): |
| 2021 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2022 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2023 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2024 | M1.setMerged() |
| 2025 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2026 | M2.setMerged() |
| 2027 | |
| 2028 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2029 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2030 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2031 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2032 | A.addApproval('code-review', 2) |
| 2033 | B.addApproval('code-review', 2) |
| 2034 | C.addApproval('code-review', 2) |
| 2035 | D.addApproval('code-review', 2) |
| 2036 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2037 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2038 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2039 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2040 | |
| 2041 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2042 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2043 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2044 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2045 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2046 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2047 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2048 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2049 | self.waitUntilSettled() |
| 2050 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2051 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2052 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2053 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2054 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2055 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2056 | a_build = x |
| 2057 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2058 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2059 | b_build = x |
| 2060 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2061 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2062 | c_build = x |
| 2063 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2064 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2065 | d_build = x |
| 2066 | if a_build and b_build and c_build and d_build: |
| 2067 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2068 | |
| 2069 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2070 | self.assertIsNotNone(a_zref) |
| 2071 | self.assertIsNotNone(b_zref) |
| 2072 | self.assertIsNotNone(c_zref) |
| 2073 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2074 | |
| 2075 | # And they should all be different |
| 2076 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2077 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2078 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2079 | # should have a, not b, and should not be in project2 |
| 2080 | self.assertTrue(a_build.hasChanges(A)) |
| 2081 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2082 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2083 | # should have a and b, and should not be in project2 |
| 2084 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2085 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2086 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2087 | # should have a and b in 1, c in 2 |
| 2088 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2089 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2090 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2091 | # should have a and b in 1, c and d in 2 |
| 2092 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2093 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2094 | self.launch_server.hold_jobs_in_build = False |
| 2095 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2096 | self.waitUntilSettled() |
| 2097 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2098 | self.assertEqual(A.data['status'], 'MERGED') |
| 2099 | self.assertEqual(A.reported, 2) |
| 2100 | self.assertEqual(B.data['status'], 'MERGED') |
| 2101 | self.assertEqual(B.reported, 2) |
| 2102 | self.assertEqual(C.data['status'], 'MERGED') |
| 2103 | self.assertEqual(C.reported, 2) |
| 2104 | self.assertEqual(D.data['status'], 'MERGED') |
| 2105 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2106 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2107 | @skip("Disabled for early v3 development") |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2108 | def test_rerun_on_error(self): |
| 2109 | "Test that if a worker fails to run a job, it is run again" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2110 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2111 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2112 | A.addApproval('code-review', 2) |
| 2113 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2114 | self.waitUntilSettled() |
| 2115 | |
| 2116 | self.builds[0].run_error = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2117 | self.launch_server.hold_jobs_in_build = False |
| 2118 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2119 | self.waitUntilSettled() |
| 2120 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2121 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2122 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2123 | def test_statsd(self): |
| 2124 | "Test each of the statsd methods used in the scheduler" |
| 2125 | import extras |
| 2126 | statsd = extras.try_import('statsd.statsd') |
| 2127 | statsd.incr('test-incr') |
| 2128 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2129 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2130 | self.assertReportedStat('test-incr', '1|c') |
| 2131 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2132 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2133 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2134 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2135 | def test_stuck_job_cleanup(self): |
| 2136 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2137 | # This job won't be registered at startup because it is not in |
| 2138 | # the standard layout, but we need it to already be registerd |
| 2139 | # for when we reconfigure, as that is when Zuul will attempt |
| 2140 | # to run the new job. |
| 2141 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2142 | self.gearman_server.hold_jobs_in_queue = True |
| 2143 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2144 | A.addApproval('code-review', 2) |
| 2145 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2146 | self.waitUntilSettled() |
| 2147 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2148 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2149 | self.updateConfigLayout( |
| 2150 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2151 | self.sched.reconfigure(self.config) |
| 2152 | self.waitUntilSettled() |
| 2153 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2154 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2155 | self.waitUntilSettled() |
| 2156 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2157 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2158 | |
| 2159 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2160 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2161 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2162 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2163 | def test_file_head(self): |
| 2164 | # This is a regression test for an observed bug. A change |
| 2165 | # with a file named "HEAD" in the root directory of the repo |
| 2166 | # was processed by a merger. It then was unable to reset the |
| 2167 | # repo because of: |
| 2168 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2169 | # with exit code 128 |
| 2170 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2171 | # and filename |
| 2172 | # Use '--' to separate filenames from revisions' |
| 2173 | |
| 2174 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2175 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2176 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2177 | |
| 2178 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2179 | self.waitUntilSettled() |
| 2180 | |
| 2181 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2182 | self.waitUntilSettled() |
| 2183 | |
| 2184 | self.assertIn('Build succeeded', A.messages[0]) |
| 2185 | self.assertIn('Build succeeded', B.messages[0]) |
| 2186 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2187 | @skip("Disabled for early v3 development") |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2188 | def test_file_jobs(self): |
| 2189 | "Test that file jobs run only when appropriate" |
| 2190 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2191 | A.addPatchset(['pip-requires']) |
| 2192 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2193 | A.addApproval('code-review', 2) |
| 2194 | B.addApproval('code-review', 2) |
| 2195 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2196 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2197 | self.waitUntilSettled() |
| 2198 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2199 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2200 | if x.name == 'project-testfile'] |
| 2201 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2202 | self.assertEqual(len(testfile_jobs), 1) |
| 2203 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2204 | self.assertEqual(A.data['status'], 'MERGED') |
| 2205 | self.assertEqual(A.reported, 2) |
| 2206 | self.assertEqual(B.data['status'], 'MERGED') |
| 2207 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2208 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2209 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2210 | "Test that jobs with irrelevant-files filter run only when appropriate" |
| 2211 | self.updateConfigLayout('layout-irrelevant-files') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2212 | self.sched.reconfigure(self.config) |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2213 | |
| 2214 | if should_skip: |
| 2215 | files = {'ignoreme': 'ignored\n'} |
| 2216 | else: |
| 2217 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2218 | |
| 2219 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2220 | 'master', |
| 2221 | 'test irrelevant-files', |
| 2222 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2223 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2224 | self.waitUntilSettled() |
| 2225 | |
| 2226 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2227 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2228 | |
| 2229 | if should_skip: |
| 2230 | self.assertEqual([], tested_change_ids) |
| 2231 | else: |
| 2232 | self.assertIn(change.data['number'], tested_change_ids) |
| 2233 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2234 | def test_irrelevant_files_match_skips_job(self): |
| 2235 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2236 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2237 | def test_irrelevant_files_no_match_runs_job(self): |
| 2238 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2239 | |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2240 | def test_inherited_jobs_keep_matchers(self): |
| 2241 | self.updateConfigLayout('layout-inheritance') |
| 2242 | self.sched.reconfigure(self.config) |
| 2243 | |
| 2244 | files = {'ignoreme': 'ignored\n'} |
| 2245 | |
| 2246 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2247 | 'master', |
| 2248 | 'test irrelevant-files', |
| 2249 | files=files) |
| 2250 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2251 | self.waitUntilSettled() |
| 2252 | |
| 2253 | run_jobs = set([build.name for build in self.history]) |
| 2254 | |
| 2255 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2256 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2257 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2258 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2259 | def test_test_config(self): |
| 2260 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2261 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2262 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2263 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2264 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2265 | def test_queue_names(self): |
| 2266 | "Test shared change queue names" |
| 2267 | project1 = self.sched.layout.projects['org/project1'] |
| 2268 | project2 = self.sched.layout.projects['org/project2'] |
| 2269 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2270 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2271 | self.assertEqual(q1.name, 'integration') |
| 2272 | self.assertEqual(q2.name, 'integration') |
| 2273 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2274 | self.updateConfigLayout( |
| 2275 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2276 | with testtools.ExpectedException( |
| 2277 | Exception, "More than one name assigned to change queue"): |
| 2278 | self.sched.reconfigure(self.config) |
| 2279 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2280 | def test_queue_precedence(self): |
| 2281 | "Test that queue precedence works" |
| 2282 | |
| 2283 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2284 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2285 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2286 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2287 | A.addApproval('code-review', 2) |
| 2288 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2289 | |
| 2290 | self.waitUntilSettled() |
| 2291 | self.gearman_server.hold_jobs_in_queue = False |
| 2292 | self.gearman_server.release() |
| 2293 | self.waitUntilSettled() |
| 2294 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2295 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2296 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2297 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2298 | self.waitUntilSettled() |
| 2299 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2300 | self.log.debug(self.history) |
| 2301 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2302 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2303 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2304 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2305 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2306 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2307 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2308 | @skip("Disabled for early v3 development") |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2309 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2310 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2311 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2312 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2313 | A.addApproval('code-review', 2) |
| 2314 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2315 | self.waitUntilSettled() |
| 2316 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2317 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2318 | self.waitUntilSettled() |
| 2319 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2320 | port = self.webapp.server.socket.getsockname()[1] |
| 2321 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2322 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2323 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2324 | headers = f.info() |
| 2325 | self.assertIn('Content-Length', headers) |
| 2326 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2327 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2328 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2329 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2330 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2331 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2332 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2333 | data = f.read() |
| 2334 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2335 | self.launch_server.hold_jobs_in_build = False |
| 2336 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2337 | self.waitUntilSettled() |
| 2338 | |
| 2339 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2340 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2341 | for p in data['pipelines']: |
| 2342 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2343 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2344 | self.assertEqual(q['window'], 20) |
| 2345 | else: |
| 2346 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2347 | for head in q['heads']: |
| 2348 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2349 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2350 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2351 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2352 | status_jobs.append(job) |
| 2353 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2354 | self.assertEqual('https://server/job/project-merge/0/', |
| 2355 | status_jobs[0]['url']) |
| 2356 | self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0', |
| 2357 | status_jobs[0]['report_url']) |
| 2358 | |
| 2359 | self.assertEqual('project-test1', status_jobs[1]['name']) |
| 2360 | self.assertEqual('https://server/job/project-test1/1/', |
| 2361 | status_jobs[1]['url']) |
| 2362 | self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1', |
| 2363 | status_jobs[1]['report_url']) |
| 2364 | |
| 2365 | self.assertEqual('project-test2', status_jobs[2]['name']) |
| 2366 | self.assertEqual('https://server/job/project-test2/2/', |
| 2367 | status_jobs[2]['url']) |
| 2368 | self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2', |
| 2369 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2370 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2371 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2372 | def test_merging_queues(self): |
| 2373 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2374 | self.updateConfigLayout( |
| 2375 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2376 | self.sched.reconfigure(self.config) |
| 2377 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2378 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2379 | @skip("Disabled for early v3 development") |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2380 | def test_mutex(self): |
| 2381 | "Test job mutexes" |
| 2382 | self.config.set('zuul', 'layout_config', |
| 2383 | 'tests/fixtures/layout-mutex.yaml') |
| 2384 | self.sched.reconfigure(self.config) |
| 2385 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2386 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2387 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2388 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2389 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2390 | |
| 2391 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2392 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2393 | self.waitUntilSettled() |
| 2394 | self.assertEqual(len(self.builds), 3) |
| 2395 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2396 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2397 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2398 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2399 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2400 | self.waitUntilSettled() |
| 2401 | |
| 2402 | self.assertEqual(len(self.builds), 3) |
| 2403 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2404 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2405 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2406 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2407 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2408 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2409 | self.waitUntilSettled() |
| 2410 | |
| 2411 | self.assertEqual(len(self.builds), 3) |
| 2412 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2413 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2414 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2415 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2416 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2417 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2418 | self.waitUntilSettled() |
| 2419 | |
| 2420 | self.assertEqual(len(self.builds), 3) |
| 2421 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2422 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2423 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2424 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2425 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2426 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2427 | self.waitUntilSettled() |
| 2428 | |
| 2429 | self.assertEqual(len(self.builds), 2) |
| 2430 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2431 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2432 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2433 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2434 | self.launch_server.hold_jobs_in_build = False |
| 2435 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2436 | |
| 2437 | self.waitUntilSettled() |
| 2438 | self.assertEqual(len(self.builds), 0) |
| 2439 | |
| 2440 | self.assertEqual(A.reported, 1) |
| 2441 | self.assertEqual(B.reported, 1) |
| 2442 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2443 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2444 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2445 | def test_node_label(self): |
| 2446 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2447 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2448 | |
| 2449 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2450 | A.addApproval('code-review', 2) |
| 2451 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2452 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2453 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2454 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2455 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2456 | 'debian') |
| 2457 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2458 | |
| 2459 | def test_live_reconfiguration(self): |
| 2460 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2461 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2462 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2463 | A.addApproval('code-review', 2) |
| 2464 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2465 | self.waitUntilSettled() |
| 2466 | |
| 2467 | self.sched.reconfigure(self.config) |
| 2468 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2469 | self.launch_server.hold_jobs_in_build = False |
| 2470 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2471 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2472 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2473 | 'SUCCESS') |
| 2474 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2475 | 'SUCCESS') |
| 2476 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2477 | 'SUCCESS') |
| 2478 | self.assertEqual(A.data['status'], 'MERGED') |
| 2479 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2480 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2481 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2482 | def test_live_reconfiguration_merge_conflict(self): |
| 2483 | # A real-world bug: a change in a gate queue has a merge |
| 2484 | # conflict and a job is added to its project while it's |
| 2485 | # sitting in the queue. The job gets added to the change and |
| 2486 | # enqueued and the change gets stuck. |
| 2487 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2488 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2489 | |
| 2490 | # This change is fine. It's here to stop the queue long |
| 2491 | # enough for the next change to be subject to the |
| 2492 | # reconfiguration, as well as to provide a conflict for the |
| 2493 | # next change. This change will succeed and merge. |
| 2494 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2495 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2496 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2497 | |
| 2498 | # This change will be in merge conflict. During the |
| 2499 | # reconfiguration, we will add a job. We want to make sure |
| 2500 | # that doesn't cause it to get stuck. |
| 2501 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2502 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2503 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2504 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2505 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2506 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2507 | |
| 2508 | self.waitUntilSettled() |
| 2509 | |
| 2510 | # No jobs have run yet |
| 2511 | self.assertEqual(A.data['status'], 'NEW') |
| 2512 | self.assertEqual(A.reported, 1) |
| 2513 | self.assertEqual(B.data['status'], 'NEW') |
| 2514 | self.assertEqual(B.reported, 1) |
| 2515 | self.assertEqual(len(self.history), 0) |
| 2516 | |
| 2517 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2518 | self.updateConfigLayout( |
| 2519 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2520 | self.sched.reconfigure(self.config) |
| 2521 | self.waitUntilSettled() |
| 2522 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2523 | self.launch_server.hold_jobs_in_build = False |
| 2524 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2525 | self.waitUntilSettled() |
| 2526 | |
| 2527 | self.assertEqual(A.data['status'], 'MERGED') |
| 2528 | self.assertEqual(A.reported, 2) |
| 2529 | self.assertEqual(B.data['status'], 'NEW') |
| 2530 | self.assertEqual(B.reported, 2) |
| 2531 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2532 | 'SUCCESS') |
| 2533 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2534 | 'SUCCESS') |
| 2535 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2536 | 'SUCCESS') |
| 2537 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2538 | 'SUCCESS') |
| 2539 | self.assertEqual(len(self.history), 4) |
| 2540 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2541 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2542 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2543 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2544 | # that tests a job added to a job tree with a failed root does |
| 2545 | # not run. |
| 2546 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2547 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2548 | |
| 2549 | # This change is fine. It's here to stop the queue long |
| 2550 | # enough for the next change to be subject to the |
| 2551 | # reconfiguration. This change will succeed and merge. |
| 2552 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2553 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2554 | A.addApproval('code-review', 2) |
| 2555 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2556 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2557 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2558 | self.waitUntilSettled() |
| 2559 | |
| 2560 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2561 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2562 | B.addApproval('code-review', 2) |
| 2563 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2564 | self.waitUntilSettled() |
| 2565 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2566 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2567 | self.waitUntilSettled() |
| 2568 | |
| 2569 | # Both -merge jobs have run, but no others. |
| 2570 | self.assertEqual(A.data['status'], 'NEW') |
| 2571 | self.assertEqual(A.reported, 1) |
| 2572 | self.assertEqual(B.data['status'], 'NEW') |
| 2573 | self.assertEqual(B.reported, 1) |
| 2574 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2575 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2576 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2577 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2578 | self.assertEqual(len(self.history), 2) |
| 2579 | |
| 2580 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2581 | self.updateConfigLayout( |
| 2582 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2583 | self.sched.reconfigure(self.config) |
| 2584 | self.waitUntilSettled() |
| 2585 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2586 | self.launch_server.hold_jobs_in_build = False |
| 2587 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2588 | self.waitUntilSettled() |
| 2589 | |
| 2590 | self.assertEqual(A.data['status'], 'MERGED') |
| 2591 | self.assertEqual(A.reported, 2) |
| 2592 | self.assertEqual(B.data['status'], 'NEW') |
| 2593 | self.assertEqual(B.reported, 2) |
| 2594 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2595 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2596 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2597 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2598 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2599 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2600 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2601 | self.assertEqual(len(self.history), 5) |
| 2602 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2603 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2604 | def test_live_reconfiguration_failed_job(self): |
| 2605 | # Test that a change with a removed failing job does not |
| 2606 | # disrupt reconfiguration. If a change has a failed job and |
| 2607 | # that job is removed during a reconfiguration, we observed a |
| 2608 | # bug where the code to re-set build statuses would run on |
| 2609 | # that build and raise an exception because the job no longer |
| 2610 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2611 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2612 | |
| 2613 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2614 | |
| 2615 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2616 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2617 | |
| 2618 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2619 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2620 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2621 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2622 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2623 | self.waitUntilSettled() |
| 2624 | |
| 2625 | self.assertEqual(A.data['status'], 'NEW') |
| 2626 | self.assertEqual(A.reported, 0) |
| 2627 | |
| 2628 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2629 | 'SUCCESS') |
| 2630 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2631 | 'FAILURE') |
| 2632 | self.assertEqual(len(self.history), 2) |
| 2633 | |
| 2634 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2635 | self.updateConfigLayout( |
| 2636 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2637 | self.sched.reconfigure(self.config) |
| 2638 | self.waitUntilSettled() |
| 2639 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2640 | self.launch_server.hold_jobs_in_build = False |
| 2641 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2642 | self.waitUntilSettled() |
| 2643 | |
| 2644 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2645 | 'SUCCESS') |
| 2646 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2647 | 'SUCCESS') |
| 2648 | self.assertEqual(len(self.history), 4) |
| 2649 | |
| 2650 | self.assertEqual(A.data['status'], 'NEW') |
| 2651 | self.assertEqual(A.reported, 1) |
| 2652 | self.assertIn('Build succeeded', A.messages[0]) |
| 2653 | # Ensure the removed job was not included in the report. |
| 2654 | self.assertNotIn('project-test1', A.messages[0]) |
| 2655 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2656 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2657 | def test_live_reconfiguration_shared_queue(self): |
| 2658 | # Test that a change with a failing job which was removed from |
| 2659 | # this project but otherwise still exists in the system does |
| 2660 | # not disrupt reconfiguration. |
| 2661 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2662 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2663 | |
| 2664 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2665 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2666 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2667 | |
| 2668 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2669 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2670 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2671 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2672 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2673 | self.waitUntilSettled() |
| 2674 | |
| 2675 | self.assertEqual(A.data['status'], 'NEW') |
| 2676 | self.assertEqual(A.reported, 0) |
| 2677 | |
| 2678 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2679 | 'SUCCESS') |
| 2680 | self.assertEqual(self.getJobFromHistory( |
| 2681 | 'project1-project2-integration').result, 'FAILURE') |
| 2682 | self.assertEqual(len(self.history), 2) |
| 2683 | |
| 2684 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2685 | self.updateConfigLayout( |
| 2686 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2687 | self.sched.reconfigure(self.config) |
| 2688 | self.waitUntilSettled() |
| 2689 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2690 | self.launch_server.hold_jobs_in_build = False |
| 2691 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2692 | self.waitUntilSettled() |
| 2693 | |
| 2694 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2695 | 'SUCCESS') |
| 2696 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2697 | 'SUCCESS') |
| 2698 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2699 | 'SUCCESS') |
| 2700 | self.assertEqual(self.getJobFromHistory( |
| 2701 | 'project1-project2-integration').result, 'FAILURE') |
| 2702 | self.assertEqual(len(self.history), 4) |
| 2703 | |
| 2704 | self.assertEqual(A.data['status'], 'NEW') |
| 2705 | self.assertEqual(A.reported, 1) |
| 2706 | self.assertIn('Build succeeded', A.messages[0]) |
| 2707 | # Ensure the removed job was not included in the report. |
| 2708 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2709 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2710 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2711 | def test_double_live_reconfiguration_shared_queue(self): |
| 2712 | # This was a real-world regression. A change is added to |
| 2713 | # gate; a reconfigure happens, a second change which depends |
| 2714 | # on the first is added, and a second reconfiguration happens. |
| 2715 | # Ensure that both changes merge. |
| 2716 | |
| 2717 | # A failure may indicate incorrect caching or cleaning up of |
| 2718 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2719 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2720 | |
| 2721 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2722 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2723 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2724 | A.addApproval('code-review', 2) |
| 2725 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2726 | |
| 2727 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2728 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2729 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2730 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2731 | self.waitUntilSettled() |
| 2732 | |
| 2733 | # Reconfigure (with only one change in the pipeline). |
| 2734 | self.sched.reconfigure(self.config) |
| 2735 | self.waitUntilSettled() |
| 2736 | |
| 2737 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2738 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2739 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2740 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2741 | self.waitUntilSettled() |
| 2742 | |
| 2743 | # Reconfigure (with both in the pipeline). |
| 2744 | self.sched.reconfigure(self.config) |
| 2745 | self.waitUntilSettled() |
| 2746 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2747 | self.launch_server.hold_jobs_in_build = False |
| 2748 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2749 | self.waitUntilSettled() |
| 2750 | |
| 2751 | self.assertEqual(len(self.history), 8) |
| 2752 | |
| 2753 | self.assertEqual(A.data['status'], 'MERGED') |
| 2754 | self.assertEqual(A.reported, 2) |
| 2755 | self.assertEqual(B.data['status'], 'MERGED') |
| 2756 | self.assertEqual(B.reported, 2) |
| 2757 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2758 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2759 | def test_live_reconfiguration_del_project(self): |
| 2760 | # Test project deletion from layout |
| 2761 | # while changes are enqueued |
| 2762 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2763 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2764 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2765 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2766 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2767 | |
| 2768 | # A Depends-On: B |
| 2769 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2770 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2771 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2772 | |
| 2773 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2774 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2775 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2776 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2777 | self.waitUntilSettled() |
| 2778 | self.assertEqual(len(self.builds), 5) |
| 2779 | |
| 2780 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2781 | self.updateConfigLayout( |
| 2782 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2783 | self.sched.reconfigure(self.config) |
| 2784 | self.waitUntilSettled() |
| 2785 | |
| 2786 | # Builds for C aborted, builds for A succeed, |
| 2787 | # and have change B applied ahead |
| 2788 | job_c = self.getJobFromHistory('project1-test1') |
| 2789 | self.assertEqual(job_c.changes, '3,1') |
| 2790 | self.assertEqual(job_c.result, 'ABORTED') |
| 2791 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2792 | self.launch_server.hold_jobs_in_build = False |
| 2793 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2794 | self.waitUntilSettled() |
| 2795 | |
| 2796 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2797 | '2,1 1,1') |
| 2798 | |
| 2799 | self.assertEqual(A.data['status'], 'NEW') |
| 2800 | self.assertEqual(B.data['status'], 'NEW') |
| 2801 | self.assertEqual(C.data['status'], 'NEW') |
| 2802 | self.assertEqual(A.reported, 1) |
| 2803 | self.assertEqual(B.reported, 0) |
| 2804 | self.assertEqual(C.reported, 0) |
| 2805 | |
| 2806 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2807 | self.assertIn('Build succeeded', A.messages[0]) |
| 2808 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2809 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2810 | def test_live_reconfiguration_functions(self): |
| 2811 | "Test live reconfiguration with a custom function" |
| 2812 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2813 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2814 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2815 | A.addApproval('code-review', 2) |
| 2816 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2817 | self.waitUntilSettled() |
| 2818 | |
| 2819 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2820 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2821 | 'debian') |
| 2822 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2823 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2824 | self.updateConfigLayout( |
| 2825 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2826 | self.sched.reconfigure(self.config) |
| 2827 | self.worker.build_history = [] |
| 2828 | |
| 2829 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2830 | B.addApproval('code-review', 2) |
| 2831 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2832 | self.waitUntilSettled() |
| 2833 | |
| 2834 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2835 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2836 | 'wheezy') |
| 2837 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2838 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2839 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2840 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2841 | self.updateConfigLayout( |
| 2842 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2843 | self.sched.reconfigure(self.config) |
| 2844 | |
| 2845 | self.init_repo("org/new-project") |
| 2846 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2847 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2848 | A.addApproval('code-review', 2) |
| 2849 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2850 | self.waitUntilSettled() |
| 2851 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2852 | 'SUCCESS') |
| 2853 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2854 | 'SUCCESS') |
| 2855 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2856 | 'SUCCESS') |
| 2857 | self.assertEqual(A.data['status'], 'MERGED') |
| 2858 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2859 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2860 | def test_repo_deleted(self): |
Paul Belanger | 66e9596 | 2016-11-11 12:11:06 -0500 | [diff] [blame] | 2861 | self.updateConfigLayout('layout-repo-deleted') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2862 | self.sched.reconfigure(self.config) |
| 2863 | |
| 2864 | self.init_repo("org/delete-project") |
| 2865 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2866 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2867 | A.addApproval('code-review', 2) |
| 2868 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2869 | self.waitUntilSettled() |
| 2870 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2871 | 'SUCCESS') |
| 2872 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2873 | 'SUCCESS') |
| 2874 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2875 | 'SUCCESS') |
| 2876 | self.assertEqual(A.data['status'], 'MERGED') |
| 2877 | self.assertEqual(A.reported, 2) |
| 2878 | |
| 2879 | # Delete org/new-project zuul repo. Should be recloned. |
| 2880 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2881 | |
| 2882 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2883 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2884 | B.addApproval('code-review', 2) |
| 2885 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2886 | self.waitUntilSettled() |
| 2887 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2888 | 'SUCCESS') |
| 2889 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2890 | 'SUCCESS') |
| 2891 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2892 | 'SUCCESS') |
| 2893 | self.assertEqual(B.data['status'], 'MERGED') |
| 2894 | self.assertEqual(B.reported, 2) |
| 2895 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2896 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2897 | def test_tags(self): |
| 2898 | "Test job tags" |
| 2899 | self.config.set('zuul', 'layout_config', |
| 2900 | 'tests/fixtures/layout-tags.yaml') |
| 2901 | self.sched.reconfigure(self.config) |
| 2902 | |
| 2903 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2904 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2905 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2906 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2907 | self.waitUntilSettled() |
| 2908 | |
| 2909 | results = {'project1-merge': 'extratag merge project1', |
| 2910 | 'project2-merge': 'merge'} |
| 2911 | |
| 2912 | for build in self.history: |
| 2913 | self.assertEqual(results.get(build.name, ''), |
| 2914 | build.parameters.get('BUILD_TAGS')) |
| 2915 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2916 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2917 | def test_timer(self): |
| 2918 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2919 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2920 | self.updateConfigLayout( |
| 2921 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2922 | self.sched.reconfigure(self.config) |
| 2923 | self.registerJobs() |
| 2924 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2925 | # The pipeline triggers every second, so we should have seen |
| 2926 | # several by now. |
| 2927 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2928 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2929 | |
| 2930 | self.assertEqual(len(self.builds), 2) |
| 2931 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2932 | port = self.webapp.server.socket.getsockname()[1] |
| 2933 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2934 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2935 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2936 | data = f.read() |
| 2937 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2938 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2939 | # Stop queuing timer triggered jobs so that the assertions |
| 2940 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2941 | self.updateConfigLayout( |
| 2942 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2943 | self.sched.reconfigure(self.config) |
| 2944 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2945 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2946 | self.waitUntilSettled() |
| 2947 | |
| 2948 | self.assertEqual(self.getJobFromHistory( |
| 2949 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2950 | self.assertEqual(self.getJobFromHistory( |
| 2951 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2952 | |
| 2953 | data = json.loads(data) |
| 2954 | status_jobs = set() |
| 2955 | for p in data['pipelines']: |
| 2956 | for q in p['change_queues']: |
| 2957 | for head in q['heads']: |
| 2958 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 2959 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2960 | for job in change['jobs']: |
| 2961 | status_jobs.add(job['name']) |
| 2962 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2963 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2964 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2965 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2966 | def test_idle(self): |
| 2967 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2968 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2969 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2970 | for x in range(1, 3): |
| 2971 | # Test that timer triggers periodic jobs even across |
| 2972 | # layout config reloads. |
| 2973 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2974 | self.updateConfigLayout( |
| 2975 | 'tests/fixtures/layout-idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2976 | self.sched.reconfigure(self.config) |
| 2977 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2978 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2979 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2980 | # The pipeline triggers every second, so we should have seen |
| 2981 | # several by now. |
| 2982 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2983 | |
| 2984 | # Stop queuing timer triggered jobs so that the assertions |
| 2985 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2986 | self.updateConfigLayout( |
| 2987 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2988 | self.sched.reconfigure(self.config) |
| 2989 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2990 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2991 | |
| 2992 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2993 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2994 | self.waitUntilSettled() |
| 2995 | self.assertEqual(len(self.builds), 0) |
| 2996 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2997 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2998 | def test_check_smtp_pool(self): |
Paul Belanger | 01be8ca | 2016-11-11 12:21:06 -0500 | [diff] [blame] | 2999 | self.updateConfigLayout('layout-smtp') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3000 | self.sched.reconfigure(self.config) |
| 3001 | |
| 3002 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3003 | self.waitUntilSettled() |
| 3004 | |
| 3005 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3006 | self.waitUntilSettled() |
| 3007 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3008 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3009 | |
| 3010 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3011 | # work on the knowledge of what the first message should be as |
| 3012 | # it is only configured to go to SMTP. |
| 3013 | |
| 3014 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3015 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3016 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3017 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3018 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3019 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3020 | |
| 3021 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3022 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3023 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3024 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3025 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3026 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3027 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3028 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3029 | def test_timer_smtp(self): |
| 3030 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3031 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3032 | self.updateConfigLayout( |
| 3033 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3034 | self.sched.reconfigure(self.config) |
| 3035 | self.registerJobs() |
| 3036 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3037 | # The pipeline triggers every second, so we should have seen |
| 3038 | # several by now. |
| 3039 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3040 | self.waitUntilSettled() |
| 3041 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3042 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3043 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3044 | self.waitUntilSettled() |
| 3045 | self.assertEqual(len(self.history), 2) |
| 3046 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3047 | self.assertEqual(self.getJobFromHistory( |
| 3048 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3049 | self.assertEqual(self.getJobFromHistory( |
| 3050 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3051 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3052 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3053 | |
| 3054 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3055 | # work on the knowledge of what the first message should be as |
| 3056 | # it is only configured to go to SMTP. |
| 3057 | |
| 3058 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3059 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3060 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3061 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3062 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3063 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3064 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3065 | # Stop queuing timer triggered jobs and let any that may have |
| 3066 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3067 | self.updateConfigLayout( |
| 3068 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3069 | self.sched.reconfigure(self.config) |
| 3070 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3071 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3072 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3073 | self.waitUntilSettled() |
| 3074 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3075 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3076 | "Test that the RPC client can enqueue a change" |
| 3077 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3078 | A.addApproval('code-review', 2) |
| 3079 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3080 | |
| 3081 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3082 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3083 | r = client.enqueue(tenant='tenant-one', |
| 3084 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3085 | project='org/project', |
| 3086 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3088 | self.waitUntilSettled() |
| 3089 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3090 | 'SUCCESS') |
| 3091 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3092 | 'SUCCESS') |
| 3093 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3094 | 'SUCCESS') |
| 3095 | self.assertEqual(A.data['status'], 'MERGED') |
| 3096 | self.assertEqual(A.reported, 2) |
| 3097 | self.assertEqual(r, True) |
| 3098 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3099 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3100 | def test_client_enqueue_ref(self): |
| 3101 | "Test that the RPC client can enqueue a ref" |
| 3102 | |
| 3103 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3104 | self.gearman_server.port) |
| 3105 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3106 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3107 | pipeline='post', |
| 3108 | project='org/project', |
| 3109 | trigger='gerrit', |
| 3110 | ref='master', |
| 3111 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3112 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3113 | self.waitUntilSettled() |
| 3114 | job_names = [x.name for x in self.history] |
| 3115 | self.assertEqual(len(self.history), 1) |
| 3116 | self.assertIn('project-post', job_names) |
| 3117 | self.assertEqual(r, True) |
| 3118 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3119 | def test_client_enqueue_negative(self): |
| 3120 | "Test that the RPC client returns errors" |
| 3121 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3122 | self.gearman_server.port) |
| 3123 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3124 | "Invalid tenant"): |
| 3125 | r = client.enqueue(tenant='tenant-foo', |
| 3126 | pipeline='gate', |
| 3127 | project='org/project', |
| 3128 | trigger='gerrit', |
| 3129 | change='1,1') |
| 3130 | client.shutdown() |
| 3131 | self.assertEqual(r, False) |
| 3132 | |
| 3133 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3134 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3135 | r = client.enqueue(tenant='tenant-one', |
| 3136 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3137 | project='project-does-not-exist', |
| 3138 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3139 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3140 | client.shutdown() |
| 3141 | self.assertEqual(r, False) |
| 3142 | |
| 3143 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3144 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3145 | r = client.enqueue(tenant='tenant-one', |
| 3146 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3147 | project='org/project', |
| 3148 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3149 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3150 | client.shutdown() |
| 3151 | self.assertEqual(r, False) |
| 3152 | |
| 3153 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3154 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3155 | r = client.enqueue(tenant='tenant-one', |
| 3156 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3157 | project='org/project', |
| 3158 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3159 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3160 | client.shutdown() |
| 3161 | self.assertEqual(r, False) |
| 3162 | |
| 3163 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3164 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3165 | r = client.enqueue(tenant='tenant-one', |
| 3166 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3167 | project='org/project', |
| 3168 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3169 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3170 | client.shutdown() |
| 3171 | self.assertEqual(r, False) |
| 3172 | |
| 3173 | self.waitUntilSettled() |
| 3174 | self.assertEqual(len(self.history), 0) |
| 3175 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3176 | |
| 3177 | def test_client_promote(self): |
| 3178 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3179 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3180 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3181 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3182 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3183 | A.addApproval('code-review', 2) |
| 3184 | B.addApproval('code-review', 2) |
| 3185 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3186 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3187 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3188 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3189 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3190 | |
| 3191 | self.waitUntilSettled() |
| 3192 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3193 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3194 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3195 | enqueue_times = {} |
| 3196 | for item in items: |
| 3197 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3198 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3199 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3200 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3201 | r = client.promote(tenant='tenant-one', |
| 3202 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3203 | change_ids=['2,1', '3,1']) |
| 3204 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3205 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3207 | for item in items: |
| 3208 | self.assertEqual( |
| 3209 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3210 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3211 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3212 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3213 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3214 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3215 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3216 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3217 | self.waitUntilSettled() |
| 3218 | |
| 3219 | self.assertEqual(len(self.builds), 6) |
| 3220 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3221 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3222 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3223 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3224 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3225 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3226 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3227 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3228 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3229 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3230 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3231 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3232 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3233 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3234 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3235 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3236 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3237 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3238 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3239 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3240 | self.waitUntilSettled() |
| 3241 | |
| 3242 | self.assertEqual(A.data['status'], 'MERGED') |
| 3243 | self.assertEqual(A.reported, 2) |
| 3244 | self.assertEqual(B.data['status'], 'MERGED') |
| 3245 | self.assertEqual(B.reported, 2) |
| 3246 | self.assertEqual(C.data['status'], 'MERGED') |
| 3247 | self.assertEqual(C.reported, 2) |
| 3248 | |
| 3249 | client.shutdown() |
| 3250 | self.assertEqual(r, True) |
| 3251 | |
| 3252 | def test_client_promote_dependent(self): |
| 3253 | "Test that the RPC client can promote a dependent change" |
| 3254 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3255 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3256 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3258 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3259 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3260 | |
| 3261 | C.setDependsOn(B, 1) |
| 3262 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3263 | A.addApproval('code-review', 2) |
| 3264 | B.addApproval('code-review', 2) |
| 3265 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3266 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3267 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3268 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3269 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3270 | |
| 3271 | self.waitUntilSettled() |
| 3272 | |
| 3273 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3274 | self.gearman_server.port) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3275 | r = client.promote(tenant='tenant-one', |
| 3276 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3277 | change_ids=['3,1']) |
| 3278 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3279 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3280 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3281 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3282 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3283 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3284 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3285 | self.waitUntilSettled() |
| 3286 | |
| 3287 | self.assertEqual(len(self.builds), 6) |
| 3288 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3289 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3290 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3291 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3292 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3293 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3294 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3295 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3296 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3297 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3298 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3299 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3300 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3301 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3302 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3303 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3304 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3305 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3306 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3307 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3308 | self.waitUntilSettled() |
| 3309 | |
| 3310 | self.assertEqual(A.data['status'], 'MERGED') |
| 3311 | self.assertEqual(A.reported, 2) |
| 3312 | self.assertEqual(B.data['status'], 'MERGED') |
| 3313 | self.assertEqual(B.reported, 2) |
| 3314 | self.assertEqual(C.data['status'], 'MERGED') |
| 3315 | self.assertEqual(C.reported, 2) |
| 3316 | |
| 3317 | client.shutdown() |
| 3318 | self.assertEqual(r, True) |
| 3319 | |
| 3320 | def test_client_promote_negative(self): |
| 3321 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3322 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3323 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3324 | A.addApproval('code-review', 2) |
| 3325 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3326 | self.waitUntilSettled() |
| 3327 | |
| 3328 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3329 | self.gearman_server.port) |
| 3330 | |
| 3331 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3332 | r = client.promote(tenant='tenant-one', |
| 3333 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3334 | change_ids=['2,1', '3,1']) |
| 3335 | client.shutdown() |
| 3336 | self.assertEqual(r, False) |
| 3337 | |
| 3338 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3339 | r = client.promote(tenant='tenant-one', |
| 3340 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3341 | change_ids=['4,1']) |
| 3342 | client.shutdown() |
| 3343 | self.assertEqual(r, False) |
| 3344 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3345 | self.launch_server.hold_jobs_in_build = False |
| 3346 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3348 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3349 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3350 | def test_queue_rate_limiting(self): |
| 3351 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3352 | self.updateConfigLayout( |
| 3353 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3354 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3355 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3356 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3357 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3358 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3359 | |
| 3360 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3361 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3362 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3363 | A.addApproval('code-review', 2) |
| 3364 | B.addApproval('code-review', 2) |
| 3365 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3366 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3367 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3368 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3369 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | # Only A and B will have their merge jobs queued because |
| 3373 | # window is 2. |
| 3374 | self.assertEqual(len(self.builds), 2) |
| 3375 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3376 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3377 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3378 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3379 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3380 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3381 | self.waitUntilSettled() |
| 3382 | |
| 3383 | # Only A and B will have their test jobs queued because |
| 3384 | # window is 2. |
| 3385 | self.assertEqual(len(self.builds), 4) |
| 3386 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3387 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3388 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3389 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3390 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3391 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3392 | self.waitUntilSettled() |
| 3393 | |
| 3394 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3395 | # A failed so window is reduced by 1 to 1. |
| 3396 | self.assertEqual(queue.window, 1) |
| 3397 | self.assertEqual(queue.window_floor, 1) |
| 3398 | self.assertEqual(A.data['status'], 'NEW') |
| 3399 | |
| 3400 | # Gate is reset and only B's merge job is queued because |
| 3401 | # window shrunk to 1. |
| 3402 | self.assertEqual(len(self.builds), 1) |
| 3403 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3404 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3405 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3406 | self.waitUntilSettled() |
| 3407 | |
| 3408 | # Only B's test jobs are queued because window is still 1. |
| 3409 | self.assertEqual(len(self.builds), 2) |
| 3410 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3411 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3412 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3413 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3414 | self.waitUntilSettled() |
| 3415 | |
| 3416 | # B was successfully merged so window is increased to 2. |
| 3417 | self.assertEqual(queue.window, 2) |
| 3418 | self.assertEqual(queue.window_floor, 1) |
| 3419 | self.assertEqual(B.data['status'], 'MERGED') |
| 3420 | |
| 3421 | # Only C is left and its merge job is queued. |
| 3422 | self.assertEqual(len(self.builds), 1) |
| 3423 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3424 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3425 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3426 | self.waitUntilSettled() |
| 3427 | |
| 3428 | # After successful merge job the test jobs for C are queued. |
| 3429 | self.assertEqual(len(self.builds), 2) |
| 3430 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3431 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3432 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3433 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3434 | self.waitUntilSettled() |
| 3435 | |
| 3436 | # C successfully merged so window is bumped to 3. |
| 3437 | self.assertEqual(queue.window, 3) |
| 3438 | self.assertEqual(queue.window_floor, 1) |
| 3439 | self.assertEqual(C.data['status'], 'MERGED') |
| 3440 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3441 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3442 | def test_queue_rate_limiting_dependent(self): |
| 3443 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3444 | self.updateConfigLayout( |
| 3445 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3446 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3447 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3448 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3449 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3450 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3451 | |
| 3452 | B.setDependsOn(A, 1) |
| 3453 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3454 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3455 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3456 | A.addApproval('code-review', 2) |
| 3457 | B.addApproval('code-review', 2) |
| 3458 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3459 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3460 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3461 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3462 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3463 | self.waitUntilSettled() |
| 3464 | |
| 3465 | # Only A and B will have their merge jobs queued because |
| 3466 | # window is 2. |
| 3467 | self.assertEqual(len(self.builds), 2) |
| 3468 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3469 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3470 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3471 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3472 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3473 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | # Only A and B will have their test jobs queued because |
| 3477 | # window is 2. |
| 3478 | self.assertEqual(len(self.builds), 4) |
| 3479 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3480 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3481 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3482 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3483 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3484 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | self.waitUntilSettled() |
| 3486 | |
| 3487 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3488 | # A failed so window is reduced by 1 to 1. |
| 3489 | self.assertEqual(queue.window, 1) |
| 3490 | self.assertEqual(queue.window_floor, 1) |
| 3491 | self.assertEqual(A.data['status'], 'NEW') |
| 3492 | self.assertEqual(B.data['status'], 'NEW') |
| 3493 | |
| 3494 | # Gate is reset and only C's merge job is queued because |
| 3495 | # window shrunk to 1 and A and B were dequeued. |
| 3496 | self.assertEqual(len(self.builds), 1) |
| 3497 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3498 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3499 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3500 | self.waitUntilSettled() |
| 3501 | |
| 3502 | # Only C's test jobs are queued because window is still 1. |
| 3503 | self.assertEqual(len(self.builds), 2) |
| 3504 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3505 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3506 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3507 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3508 | self.waitUntilSettled() |
| 3509 | |
| 3510 | # C was successfully merged so window is increased to 2. |
| 3511 | self.assertEqual(queue.window, 2) |
| 3512 | self.assertEqual(queue.window_floor, 1) |
| 3513 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3514 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3515 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3516 | def test_worker_update_metadata(self): |
| 3517 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3518 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3519 | |
| 3520 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3521 | A.addApproval('code-review', 2) |
| 3522 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3523 | self.waitUntilSettled() |
| 3524 | |
| 3525 | self.assertEqual(len(self.launcher.builds), 1) |
| 3526 | |
| 3527 | self.log.debug('Current builds:') |
| 3528 | self.log.debug(self.launcher.builds) |
| 3529 | |
| 3530 | start = time.time() |
| 3531 | while True: |
| 3532 | if time.time() - start > 10: |
| 3533 | raise Exception("Timeout waiting for gearman server to report " |
| 3534 | + "back to the client") |
| 3535 | build = self.launcher.builds.values()[0] |
| 3536 | if build.worker.name == "My Worker": |
| 3537 | break |
| 3538 | else: |
| 3539 | time.sleep(0) |
| 3540 | |
| 3541 | self.log.debug(build) |
| 3542 | self.assertEqual("My Worker", build.worker.name) |
| 3543 | self.assertEqual("localhost", build.worker.hostname) |
| 3544 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3545 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3546 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3547 | self.assertEqual("v1.1", build.worker.version) |
| 3548 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3549 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3550 | self.launch_server.hold_jobs_in_build = False |
| 3551 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3552 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3553 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3554 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3555 | def test_footer_message(self): |
| 3556 | "Test a pipeline's footer message is correctly added to the report." |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3557 | self.updateConfigLayout( |
| 3558 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3559 | self.sched.reconfigure(self.config) |
| 3560 | self.registerJobs() |
| 3561 | |
| 3562 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3563 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3564 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3565 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3566 | self.waitUntilSettled() |
| 3567 | |
| 3568 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3569 | B.addApproval('code-review', 2) |
| 3570 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3571 | self.waitUntilSettled() |
| 3572 | |
| 3573 | self.assertEqual(2, len(self.smtp_messages)) |
| 3574 | |
| 3575 | failure_body = """\ |
| 3576 | Build failed. For information on how to proceed, see \ |
| 3577 | http://wiki.example.org/Test_Failures |
| 3578 | |
| 3579 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3580 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3581 | |
| 3582 | For CI problems and help debugging, contact ci@example.org""" |
| 3583 | |
| 3584 | success_body = """\ |
| 3585 | Build succeeded. |
| 3586 | |
| 3587 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3588 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3589 | |
| 3590 | For CI problems and help debugging, contact ci@example.org""" |
| 3591 | |
| 3592 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3593 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3594 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3595 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3596 | def test_merge_failure_reporters(self): |
| 3597 | """Check that the config is set up correctly""" |
| 3598 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3599 | self.updateConfigLayout( |
| 3600 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3601 | self.sched.reconfigure(self.config) |
| 3602 | self.registerJobs() |
| 3603 | |
| 3604 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3605 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3606 | "dependencies was unable to be automatically merged with the " |
| 3607 | "current state of its repository. Please rebase the change and " |
| 3608 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3609 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3610 | self.assertEqual( |
| 3611 | "The merge failed! For more information...", |
| 3612 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3613 | |
| 3614 | self.assertEqual( |
| 3615 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3616 | self.assertEqual( |
| 3617 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3618 | |
| 3619 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3620 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3621 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3622 | |
| 3623 | self.assertTrue( |
| 3624 | ( |
| 3625 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3626 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3627 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3628 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3629 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3630 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3631 | ) or ( |
| 3632 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3633 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3634 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3635 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3636 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3637 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3638 | ) |
| 3639 | ) |
| 3640 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3641 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3642 | def test_merge_failure_reports(self): |
| 3643 | """Check that when a change fails to merge the correct message is sent |
| 3644 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3645 | self.updateConfigLayout( |
| 3646 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3647 | self.sched.reconfigure(self.config) |
| 3648 | self.registerJobs() |
| 3649 | |
| 3650 | # Check a test failure isn't reported to SMTP |
| 3651 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3652 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3653 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3654 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3655 | self.waitUntilSettled() |
| 3656 | |
| 3657 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3658 | self.assertEqual(0, len(self.smtp_messages)) |
| 3659 | |
| 3660 | # Check a merge failure is reported to SMTP |
| 3661 | # B should be merged, but C will conflict with B |
| 3662 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3663 | B.addPatchset(['conflict']) |
| 3664 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3665 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3666 | B.addApproval('code-review', 2) |
| 3667 | C.addApproval('code-review', 2) |
| 3668 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3669 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3670 | self.waitUntilSettled() |
| 3671 | |
| 3672 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3673 | self.assertEqual(1, len(self.smtp_messages)) |
| 3674 | self.assertEqual('The merge failed! For more information...', |
| 3675 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3676 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3677 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3678 | def test_default_merge_failure_reports(self): |
| 3679 | """Check that the default merge failure reports are correct.""" |
| 3680 | |
| 3681 | # A should report success, B should report merge failure. |
| 3682 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3683 | A.addPatchset(['conflict']) |
| 3684 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3685 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3686 | A.addApproval('code-review', 2) |
| 3687 | B.addApproval('code-review', 2) |
| 3688 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3689 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3690 | self.waitUntilSettled() |
| 3691 | |
| 3692 | self.assertEqual(3, len(self.history)) # A jobs |
| 3693 | self.assertEqual(A.reported, 2) |
| 3694 | self.assertEqual(B.reported, 2) |
| 3695 | self.assertEqual(A.data['status'], 'MERGED') |
| 3696 | self.assertEqual(B.data['status'], 'NEW') |
| 3697 | self.assertIn('Build succeeded', A.messages[1]) |
| 3698 | self.assertIn('Merge Failed', B.messages[1]) |
| 3699 | self.assertIn('automatically merged', B.messages[1]) |
| 3700 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3701 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3702 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3703 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3704 | def test_swift_instructions(self): |
| 3705 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3706 | self.updateConfigLayout( |
| 3707 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3708 | self.sched.reconfigure(self.config) |
| 3709 | self.registerJobs() |
| 3710 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3711 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3712 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3713 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3714 | A.addApproval('code-review', 2) |
| 3715 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3716 | self.waitUntilSettled() |
| 3717 | |
| 3718 | self.assertEqual( |
| 3719 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3720 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3721 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3722 | self.assertEqual(5, |
| 3723 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3724 | split('\n'))) |
| 3725 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3726 | |
| 3727 | self.assertEqual( |
| 3728 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3729 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3730 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3731 | self.assertEqual(5, |
| 3732 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3733 | split('\n'))) |
| 3734 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3735 | |
| 3736 | self.assertEqual( |
| 3737 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3738 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3739 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3740 | self.assertEqual(5, |
| 3741 | len(self.builds[1]. |
| 3742 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3743 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3744 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3745 | self.launch_server.hold_jobs_in_build = False |
| 3746 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3747 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3748 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3749 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3750 | def test_client_get_running_jobs(self): |
| 3751 | "Test that the RPC client can get a list of running jobs" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3752 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3753 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3754 | A.addApproval('code-review', 2) |
| 3755 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3756 | self.waitUntilSettled() |
| 3757 | |
| 3758 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3759 | self.gearman_server.port) |
| 3760 | |
| 3761 | # Wait for gearman server to send the initial workData back to zuul |
| 3762 | start = time.time() |
| 3763 | while True: |
| 3764 | if time.time() - start > 10: |
| 3765 | raise Exception("Timeout waiting for gearman server to report " |
| 3766 | + "back to the client") |
| 3767 | build = self.launcher.builds.values()[0] |
| 3768 | if build.worker.name == "My Worker": |
| 3769 | break |
| 3770 | else: |
| 3771 | time.sleep(0) |
| 3772 | |
| 3773 | running_items = client.get_running_jobs() |
| 3774 | |
| 3775 | self.assertEqual(1, len(running_items)) |
| 3776 | running_item = running_items[0] |
| 3777 | self.assertEqual([], running_item['failing_reasons']) |
| 3778 | self.assertEqual([], running_item['items_behind']) |
| 3779 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3780 | self.assertEqual(None, running_item['item_ahead']) |
| 3781 | self.assertEqual('org/project', running_item['project']) |
| 3782 | self.assertEqual(None, running_item['remaining_time']) |
| 3783 | self.assertEqual(True, running_item['active']) |
| 3784 | self.assertEqual('1,1', running_item['id']) |
| 3785 | |
| 3786 | self.assertEqual(3, len(running_item['jobs'])) |
| 3787 | for job in running_item['jobs']: |
| 3788 | if job['name'] == 'project-merge': |
| 3789 | self.assertEqual('project-merge', job['name']) |
| 3790 | self.assertEqual('gate', job['pipeline']) |
| 3791 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3792 | self.assertEqual('https://server/job/project-merge/0/', |
| 3793 | job['url']) |
| 3794 | self.assertEqual(7, len(job['worker'])) |
| 3795 | self.assertEqual(False, job['canceled']) |
| 3796 | self.assertEqual(True, job['voting']) |
| 3797 | self.assertEqual(None, job['result']) |
| 3798 | self.assertEqual('gate', job['pipeline']) |
| 3799 | break |
| 3800 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3801 | self.launch_server.hold_jobs_in_build = False |
| 3802 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3803 | self.waitUntilSettled() |
| 3804 | |
| 3805 | running_items = client.get_running_jobs() |
| 3806 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3807 | |
| 3808 | def test_nonvoting_pipeline(self): |
| 3809 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3810 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3811 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3812 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3813 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3814 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3815 | |
| 3816 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3817 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3818 | self.assertEqual( |
| 3819 | self.getJobFromHistory('experimental-project-test').result, |
| 3820 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3821 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3822 | |
| 3823 | def test_crd_gate(self): |
| 3824 | "Test cross-repo dependencies" |
| 3825 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3826 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3827 | A.addApproval('code-review', 2) |
| 3828 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3829 | |
| 3830 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3831 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3832 | AM2.setMerged() |
| 3833 | AM1.setMerged() |
| 3834 | |
| 3835 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3836 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3837 | BM2.setMerged() |
| 3838 | BM1.setMerged() |
| 3839 | |
| 3840 | # A -> AM1 -> AM2 |
| 3841 | # B -> BM1 -> BM2 |
| 3842 | # A Depends-On: B |
| 3843 | # M2 is here to make sure it is never queried. If it is, it |
| 3844 | # means zuul is walking down the entire history of merged |
| 3845 | # changes. |
| 3846 | |
| 3847 | B.setDependsOn(BM1, 1) |
| 3848 | BM1.setDependsOn(BM2, 1) |
| 3849 | |
| 3850 | A.setDependsOn(AM1, 1) |
| 3851 | AM1.setDependsOn(AM2, 1) |
| 3852 | |
| 3853 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3854 | A.subject, B.data['id']) |
| 3855 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3856 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3857 | self.waitUntilSettled() |
| 3858 | |
| 3859 | self.assertEqual(A.data['status'], 'NEW') |
| 3860 | self.assertEqual(B.data['status'], 'NEW') |
| 3861 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3862 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3863 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3864 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3865 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3866 | B.addApproval('approved', 1) |
| 3867 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3868 | self.waitUntilSettled() |
| 3869 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3870 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3871 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3872 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3873 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3874 | self.launch_server.hold_jobs_in_build = False |
| 3875 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3876 | self.waitUntilSettled() |
| 3877 | |
| 3878 | self.assertEqual(AM2.queried, 0) |
| 3879 | self.assertEqual(BM2.queried, 0) |
| 3880 | self.assertEqual(A.data['status'], 'MERGED') |
| 3881 | self.assertEqual(B.data['status'], 'MERGED') |
| 3882 | self.assertEqual(A.reported, 2) |
| 3883 | self.assertEqual(B.reported, 2) |
| 3884 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3885 | changes = self.getJobFromHistory( |
| 3886 | 'project-merge', 'org/project1').changes |
| 3887 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3888 | |
| 3889 | def test_crd_branch(self): |
| 3890 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3891 | |
| 3892 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3893 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3894 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3895 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3896 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3897 | A.addApproval('code-review', 2) |
| 3898 | B.addApproval('code-review', 2) |
| 3899 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3900 | |
| 3901 | # A Depends-On: B+C |
| 3902 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3903 | A.subject, B.data['id']) |
| 3904 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3905 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3906 | B.addApproval('approved', 1) |
| 3907 | C.addApproval('approved', 1) |
| 3908 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3909 | self.waitUntilSettled() |
| 3910 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3911 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3912 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3913 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3914 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3915 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3916 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3917 | self.launch_server.hold_jobs_in_build = False |
| 3918 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3919 | self.waitUntilSettled() |
| 3920 | |
| 3921 | self.assertEqual(A.data['status'], 'MERGED') |
| 3922 | self.assertEqual(B.data['status'], 'MERGED') |
| 3923 | self.assertEqual(C.data['status'], 'MERGED') |
| 3924 | self.assertEqual(A.reported, 2) |
| 3925 | self.assertEqual(B.reported, 2) |
| 3926 | self.assertEqual(C.reported, 2) |
| 3927 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3928 | changes = self.getJobFromHistory( |
| 3929 | 'project-merge', 'org/project1').changes |
| 3930 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3931 | |
| 3932 | def test_crd_multiline(self): |
| 3933 | "Test multiple depends-on lines in commit" |
| 3934 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3935 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3936 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3937 | A.addApproval('code-review', 2) |
| 3938 | B.addApproval('code-review', 2) |
| 3939 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3940 | |
| 3941 | # A Depends-On: B+C |
| 3942 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3943 | A.subject, B.data['id'], C.data['id']) |
| 3944 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3945 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3946 | B.addApproval('approved', 1) |
| 3947 | C.addApproval('approved', 1) |
| 3948 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3949 | self.waitUntilSettled() |
| 3950 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3951 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3952 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3953 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3954 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3955 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3956 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3957 | self.launch_server.hold_jobs_in_build = False |
| 3958 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3959 | self.waitUntilSettled() |
| 3960 | |
| 3961 | self.assertEqual(A.data['status'], 'MERGED') |
| 3962 | self.assertEqual(B.data['status'], 'MERGED') |
| 3963 | self.assertEqual(C.data['status'], 'MERGED') |
| 3964 | self.assertEqual(A.reported, 2) |
| 3965 | self.assertEqual(B.reported, 2) |
| 3966 | self.assertEqual(C.reported, 2) |
| 3967 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3968 | changes = self.getJobFromHistory( |
| 3969 | 'project-merge', 'org/project1').changes |
| 3970 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3971 | |
| 3972 | def test_crd_unshared_gate(self): |
| 3973 | "Test cross-repo dependencies in unshared gate queues" |
| 3974 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3975 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3976 | A.addApproval('code-review', 2) |
| 3977 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3978 | |
| 3979 | # A Depends-On: B |
| 3980 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3981 | A.subject, B.data['id']) |
| 3982 | |
| 3983 | # A and B do not share a queue, make sure that A is unable to |
| 3984 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3985 | B.addApproval('approved', 1) |
| 3986 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3987 | self.waitUntilSettled() |
| 3988 | |
| 3989 | self.assertEqual(A.data['status'], 'NEW') |
| 3990 | self.assertEqual(B.data['status'], 'NEW') |
| 3991 | self.assertEqual(A.reported, 0) |
| 3992 | self.assertEqual(B.reported, 0) |
| 3993 | self.assertEqual(len(self.history), 0) |
| 3994 | |
| 3995 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3996 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3997 | self.waitUntilSettled() |
| 3998 | |
| 3999 | self.assertEqual(B.data['status'], 'MERGED') |
| 4000 | self.assertEqual(B.reported, 2) |
| 4001 | |
| 4002 | # Now that B is merged, A should be able to be enqueued and |
| 4003 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4004 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4005 | self.waitUntilSettled() |
| 4006 | |
| 4007 | self.assertEqual(A.data['status'], 'MERGED') |
| 4008 | self.assertEqual(A.reported, 2) |
| 4009 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4010 | def test_crd_gate_reverse(self): |
| 4011 | "Test reverse cross-repo dependencies" |
| 4012 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4013 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4014 | A.addApproval('code-review', 2) |
| 4015 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4016 | |
| 4017 | # A Depends-On: B |
| 4018 | |
| 4019 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4020 | A.subject, B.data['id']) |
| 4021 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4022 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4023 | self.waitUntilSettled() |
| 4024 | |
| 4025 | self.assertEqual(A.data['status'], 'NEW') |
| 4026 | self.assertEqual(B.data['status'], 'NEW') |
| 4027 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4028 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4029 | A.addApproval('approved', 1) |
| 4030 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4031 | self.waitUntilSettled() |
| 4032 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4033 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4034 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4035 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4036 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4037 | self.launch_server.hold_jobs_in_build = False |
| 4038 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4039 | self.waitUntilSettled() |
| 4040 | |
| 4041 | self.assertEqual(A.data['status'], 'MERGED') |
| 4042 | self.assertEqual(B.data['status'], 'MERGED') |
| 4043 | self.assertEqual(A.reported, 2) |
| 4044 | self.assertEqual(B.reported, 2) |
| 4045 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4046 | changes = self.getJobFromHistory( |
| 4047 | 'project-merge', 'org/project1').changes |
| 4048 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4049 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4050 | def test_crd_cycle(self): |
| 4051 | "Test cross-repo dependency cycles" |
| 4052 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4053 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4054 | A.addApproval('code-review', 2) |
| 4055 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4056 | |
| 4057 | # A -> B -> A (via commit-depends) |
| 4058 | |
| 4059 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4060 | A.subject, B.data['id']) |
| 4061 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4062 | B.subject, A.data['id']) |
| 4063 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4064 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4065 | self.waitUntilSettled() |
| 4066 | |
| 4067 | self.assertEqual(A.reported, 0) |
| 4068 | self.assertEqual(B.reported, 0) |
| 4069 | self.assertEqual(A.data['status'], 'NEW') |
| 4070 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4071 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4072 | def test_crd_gate_unknown(self): |
| 4073 | "Test unknown projects in dependent pipeline" |
| 4074 | self.init_repo("org/unknown") |
| 4075 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4076 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4077 | A.addApproval('code-review', 2) |
| 4078 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4079 | |
| 4080 | # A Depends-On: B |
| 4081 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4082 | A.subject, B.data['id']) |
| 4083 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4084 | B.addApproval('approved', 1) |
| 4085 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4086 | self.waitUntilSettled() |
| 4087 | |
| 4088 | # Unknown projects cannot share a queue with any other |
| 4089 | # since they don't have common jobs with any other (they have no jobs). |
| 4090 | # Changes which depend on unknown project changes |
| 4091 | # should not be processed in dependent pipeline |
| 4092 | self.assertEqual(A.data['status'], 'NEW') |
| 4093 | self.assertEqual(B.data['status'], 'NEW') |
| 4094 | self.assertEqual(A.reported, 0) |
| 4095 | self.assertEqual(B.reported, 0) |
| 4096 | self.assertEqual(len(self.history), 0) |
| 4097 | |
| 4098 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4099 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4100 | B.setMerged() |
| 4101 | self.waitUntilSettled() |
| 4102 | self.assertEqual(len(self.history), 0) |
| 4103 | |
| 4104 | # Now that B is merged, A should be able to be enqueued and |
| 4105 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4106 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4107 | self.waitUntilSettled() |
| 4108 | |
| 4109 | self.assertEqual(A.data['status'], 'MERGED') |
| 4110 | self.assertEqual(A.reported, 2) |
| 4111 | self.assertEqual(B.data['status'], 'MERGED') |
| 4112 | self.assertEqual(B.reported, 0) |
| 4113 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4114 | def test_crd_check(self): |
| 4115 | "Test cross-repo dependencies in independent pipelines" |
| 4116 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4117 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4118 | self.gearman_server.hold_jobs_in_queue = True |
| 4119 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4120 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4121 | |
| 4122 | # A Depends-On: B |
| 4123 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4124 | A.subject, B.data['id']) |
| 4125 | |
| 4126 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4127 | self.waitUntilSettled() |
| 4128 | |
| 4129 | queue = self.gearman_server.getQueue() |
| 4130 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4131 | self.gearman_server.hold_jobs_in_queue = False |
| 4132 | self.gearman_server.release() |
| 4133 | self.waitUntilSettled() |
| 4134 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4135 | self.launch_server.release('.*-merge') |
| 4136 | self.waitUntilSettled() |
| 4137 | |
| 4138 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project1") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4139 | repo = git.Repo(path) |
| 4140 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4141 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4142 | correct_messages = [ |
| 4143 | 'initial commit', 'add content from fixture', 'A-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4144 | self.assertEqual(repo_messages, correct_messages) |
| 4145 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4146 | path = os.path.join(self.builds[0].jobdir.git_root, "org/project2") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4147 | repo = git.Repo(path) |
| 4148 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4149 | repo_messages.reverse() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4150 | correct_messages = [ |
| 4151 | 'initial commit', 'add content from fixture', 'B-1'] |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4152 | self.assertEqual(repo_messages, correct_messages) |
| 4153 | |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4154 | self.launch_server.hold_jobs_in_build = False |
| 4155 | self.launch_server.release() |
| 4156 | self.waitUntilSettled() |
| 4157 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4158 | self.assertEqual(A.data['status'], 'NEW') |
| 4159 | self.assertEqual(B.data['status'], 'NEW') |
| 4160 | self.assertEqual(A.reported, 1) |
| 4161 | self.assertEqual(B.reported, 0) |
| 4162 | |
| 4163 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4164 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4165 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4166 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4167 | def test_crd_check_git_depends(self): |
| 4168 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4169 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4170 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4171 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4172 | |
| 4173 | # Add two git-dependent changes and make sure they both report |
| 4174 | # success. |
| 4175 | B.setDependsOn(A, 1) |
| 4176 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4177 | self.waitUntilSettled() |
| 4178 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4179 | self.waitUntilSettled() |
| 4180 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4181 | self.orderedRelease() |
| 4182 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4183 | self.waitUntilSettled() |
| 4184 | |
| 4185 | self.assertEqual(A.data['status'], 'NEW') |
| 4186 | self.assertEqual(B.data['status'], 'NEW') |
| 4187 | self.assertEqual(A.reported, 1) |
| 4188 | self.assertEqual(B.reported, 1) |
| 4189 | |
| 4190 | self.assertEqual(self.history[0].changes, '1,1') |
| 4191 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4192 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4193 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4194 | |
| 4195 | self.assertIn('Build succeeded', A.messages[0]) |
| 4196 | self.assertIn('Build succeeded', B.messages[0]) |
| 4197 | |
| 4198 | def test_crd_check_duplicate(self): |
| 4199 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4200 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4201 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4202 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4203 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4204 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4205 | |
| 4206 | # Add two git-dependent changes... |
| 4207 | B.setDependsOn(A, 1) |
| 4208 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4209 | self.waitUntilSettled() |
| 4210 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4211 | |
| 4212 | # ...make sure the live one is not duplicated... |
| 4213 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4214 | self.waitUntilSettled() |
| 4215 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4216 | |
| 4217 | # ...but the non-live one is able to be. |
| 4218 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4219 | self.waitUntilSettled() |
| 4220 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4221 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4222 | # Release jobs in order to avoid races with change A jobs |
| 4223 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4224 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4225 | self.launch_server.hold_jobs_in_build = False |
| 4226 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4227 | self.waitUntilSettled() |
| 4228 | |
| 4229 | self.assertEqual(A.data['status'], 'NEW') |
| 4230 | self.assertEqual(B.data['status'], 'NEW') |
| 4231 | self.assertEqual(A.reported, 1) |
| 4232 | self.assertEqual(B.reported, 1) |
| 4233 | |
| 4234 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4235 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4236 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4237 | |
| 4238 | self.assertIn('Build succeeded', A.messages[0]) |
| 4239 | self.assertIn('Build succeeded', B.messages[0]) |
| 4240 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4241 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4242 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4243 | |
| 4244 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4245 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4246 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4247 | |
| 4248 | # A Depends-On: B |
| 4249 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4250 | A.subject, B.data['id']) |
| 4251 | |
| 4252 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4253 | self.waitUntilSettled() |
| 4254 | |
| 4255 | self.sched.reconfigure(self.config) |
| 4256 | |
| 4257 | # Make sure the items still share a change queue, and the |
| 4258 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4259 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4260 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4261 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4262 | first_item = queue.queue[0] |
| 4263 | for item in queue.queue: |
| 4264 | self.assertEqual(item.queue, first_item.queue) |
| 4265 | self.assertFalse(first_item.live) |
| 4266 | self.assertTrue(queue.queue[1].live) |
| 4267 | |
| 4268 | self.gearman_server.hold_jobs_in_queue = False |
| 4269 | self.gearman_server.release() |
| 4270 | self.waitUntilSettled() |
| 4271 | |
| 4272 | self.assertEqual(A.data['status'], 'NEW') |
| 4273 | self.assertEqual(B.data['status'], 'NEW') |
| 4274 | self.assertEqual(A.reported, 1) |
| 4275 | self.assertEqual(B.reported, 0) |
| 4276 | |
| 4277 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4278 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4279 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4280 | def test_crd_check_reconfiguration(self): |
| 4281 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4282 | |
| 4283 | def test_crd_undefined_project(self): |
| 4284 | """Test that undefined projects in dependencies are handled for |
| 4285 | independent pipelines""" |
| 4286 | # It's a hack for fake gerrit, |
| 4287 | # as it implies repo creation upon the creation of any change |
| 4288 | self.init_repo("org/unknown") |
| 4289 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4290 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4291 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4292 | def test_crd_check_ignore_dependencies(self): |
| 4293 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4294 | self.updateConfigLayout( |
| 4295 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4296 | self.sched.reconfigure(self.config) |
| 4297 | self.registerJobs() |
| 4298 | |
| 4299 | self.gearman_server.hold_jobs_in_queue = True |
| 4300 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4301 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4302 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4303 | |
| 4304 | # A Depends-On: B |
| 4305 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4306 | A.subject, B.data['id']) |
| 4307 | # C git-depends on B |
| 4308 | C.setDependsOn(B, 1) |
| 4309 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4310 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4311 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4312 | self.waitUntilSettled() |
| 4313 | |
| 4314 | # Make sure none of the items share a change queue, and all |
| 4315 | # are live. |
| 4316 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4317 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4318 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4319 | for item in check_pipeline.getAllItems(): |
| 4320 | self.assertTrue(item.live) |
| 4321 | |
| 4322 | self.gearman_server.hold_jobs_in_queue = False |
| 4323 | self.gearman_server.release() |
| 4324 | self.waitUntilSettled() |
| 4325 | |
| 4326 | self.assertEqual(A.data['status'], 'NEW') |
| 4327 | self.assertEqual(B.data['status'], 'NEW') |
| 4328 | self.assertEqual(C.data['status'], 'NEW') |
| 4329 | self.assertEqual(A.reported, 1) |
| 4330 | self.assertEqual(B.reported, 1) |
| 4331 | self.assertEqual(C.reported, 1) |
| 4332 | |
| 4333 | # Each job should have tested exactly one change |
| 4334 | for job in self.history: |
| 4335 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4336 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4337 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4338 | def test_crd_check_transitive(self): |
| 4339 | "Test transitive cross-repo dependencies" |
| 4340 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4341 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4342 | # and C,2 (not C,1 which would indicate stale data in the |
| 4343 | # cache for B). |
| 4344 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4345 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4346 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4347 | |
| 4348 | # A Depends-On: B |
| 4349 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4350 | A.subject, B.data['id']) |
| 4351 | |
| 4352 | # B Depends-On: C |
| 4353 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4354 | B.subject, C.data['id']) |
| 4355 | |
| 4356 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4357 | self.waitUntilSettled() |
| 4358 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4359 | |
| 4360 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4361 | self.waitUntilSettled() |
| 4362 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4363 | |
| 4364 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4365 | self.waitUntilSettled() |
| 4366 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4367 | |
| 4368 | C.addPatchset() |
| 4369 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4370 | self.waitUntilSettled() |
| 4371 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4372 | |
| 4373 | A.addPatchset() |
| 4374 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4375 | self.waitUntilSettled() |
| 4376 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4377 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4378 | def test_crd_check_unknown(self): |
| 4379 | "Test unknown projects in independent pipeline" |
| 4380 | self.init_repo("org/unknown") |
| 4381 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4382 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4383 | # A Depends-On: B |
| 4384 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4385 | A.subject, B.data['id']) |
| 4386 | |
| 4387 | # Make sure zuul has seen an event on B. |
| 4388 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4389 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4390 | self.waitUntilSettled() |
| 4391 | |
| 4392 | self.assertEqual(A.data['status'], 'NEW') |
| 4393 | self.assertEqual(A.reported, 1) |
| 4394 | self.assertEqual(B.data['status'], 'NEW') |
| 4395 | self.assertEqual(B.reported, 0) |
| 4396 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4397 | def test_crd_cycle_join(self): |
| 4398 | "Test an updated change creates a cycle" |
| 4399 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4400 | |
| 4401 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4402 | self.waitUntilSettled() |
| 4403 | |
| 4404 | # Create B->A |
| 4405 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4406 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4407 | B.subject, A.data['id']) |
| 4408 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4409 | self.waitUntilSettled() |
| 4410 | |
| 4411 | # Update A to add A->B (a cycle). |
| 4412 | A.addPatchset() |
| 4413 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4414 | A.subject, B.data['id']) |
| 4415 | # Normally we would submit the patchset-created event for |
| 4416 | # processing here, however, we have no way of noting whether |
| 4417 | # the dependency cycle detection correctly raised an |
| 4418 | # exception, so instead, we reach into the source driver and |
| 4419 | # call the method that would ultimately be called by the event |
| 4420 | # processing. |
| 4421 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4422 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4423 | source = tenant.layout.pipelines['gate'].source |
| 4424 | |
| 4425 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4426 | # it easier for users to create events for testing. |
| 4427 | event = zuul.model.TriggerEvent() |
| 4428 | event.trigger_name = 'gerrit' |
| 4429 | event.change_number = '1' |
| 4430 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4431 | with testtools.ExpectedException( |
| 4432 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4433 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4434 | self.log.debug("Got expected dependency cycle exception") |
| 4435 | |
| 4436 | # Now if we update B to remove the depends-on, everything |
| 4437 | # should be okay. B; A->B |
| 4438 | |
| 4439 | B.addPatchset() |
| 4440 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4441 | |
| 4442 | source.getChange(event, True) |
| 4443 | event.change_number = '2' |
| 4444 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4445 | |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4446 | def test_disable_at(self): |
| 4447 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4448 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4449 | self.updateConfigLayout('layout-disabled-at') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4450 | self.sched.reconfigure(self.config) |
| 4451 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4452 | tenant = self.sched.abide.tenants.get('openstack') |
| 4453 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4454 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4455 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4456 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4457 | |
| 4458 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4459 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4460 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4461 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4462 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4463 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4464 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4465 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4466 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4467 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4468 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4469 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4470 | self.launch_server.failJob('project-test1', A) |
| 4471 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4472 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4473 | self.launch_server.failJob('project-test1', D) |
| 4474 | self.launch_server.failJob('project-test1', E) |
| 4475 | self.launch_server.failJob('project-test1', F) |
| 4476 | self.launch_server.failJob('project-test1', G) |
| 4477 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4478 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4479 | self.launch_server.failJob('project-test1', J) |
| 4480 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4481 | |
| 4482 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4483 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4484 | self.waitUntilSettled() |
| 4485 | |
| 4486 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4487 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4488 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4489 | |
| 4490 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4491 | self.waitUntilSettled() |
| 4492 | |
| 4493 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4494 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4495 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4496 | |
| 4497 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4498 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4499 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4500 | self.waitUntilSettled() |
| 4501 | |
| 4502 | # We should be disabled now |
| 4503 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4504 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4505 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4506 | |
| 4507 | # We need to wait between each of these patches to make sure the |
| 4508 | # smtp messages come back in an expected order |
| 4509 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4510 | self.waitUntilSettled() |
| 4511 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4512 | self.waitUntilSettled() |
| 4513 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4514 | self.waitUntilSettled() |
| 4515 | |
| 4516 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4517 | # leaving a message on each change |
| 4518 | self.assertEqual(1, len(A.messages)) |
| 4519 | self.assertIn('Build failed.', A.messages[0]) |
| 4520 | self.assertEqual(1, len(B.messages)) |
| 4521 | self.assertIn('Build failed.', B.messages[0]) |
| 4522 | self.assertEqual(1, len(C.messages)) |
| 4523 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4524 | self.assertEqual(1, len(D.messages)) |
| 4525 | self.assertIn('Build failed.', D.messages[0]) |
| 4526 | self.assertEqual(1, len(E.messages)) |
| 4527 | self.assertIn('Build failed.', E.messages[0]) |
| 4528 | self.assertEqual(1, len(F.messages)) |
| 4529 | self.assertIn('Build failed.', F.messages[0]) |
| 4530 | |
| 4531 | # The last 3 (GHI) would have only reported via smtp. |
| 4532 | self.assertEqual(3, len(self.smtp_messages)) |
| 4533 | self.assertEqual(0, len(G.messages)) |
| 4534 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4535 | self.assertIn( |
| 4536 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4537 | self.assertEqual(0, len(H.messages)) |
| 4538 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4539 | self.assertIn( |
| 4540 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4541 | self.assertEqual(0, len(I.messages)) |
| 4542 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4543 | self.assertIn( |
| 4544 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4545 | |
| 4546 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4547 | # comes out of disabled |
| 4548 | self.sched.reconfigure(self.config) |
| 4549 | |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4550 | tenant = self.sched.abide.tenants.get('openstack') |
| 4551 | |
| 4552 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4553 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4554 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4555 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4556 | |
| 4557 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4558 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4559 | self.waitUntilSettled() |
| 4560 | |
| 4561 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4562 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4563 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4564 | |
| 4565 | # J and K went back to gerrit |
| 4566 | self.assertEqual(1, len(J.messages)) |
| 4567 | self.assertIn('Build failed.', J.messages[0]) |
| 4568 | self.assertEqual(1, len(K.messages)) |
| 4569 | self.assertIn('Build failed.', K.messages[0]) |
| 4570 | # No more messages reported via smtp |
| 4571 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4572 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4573 | @skip("Disabled for early v3 development") |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4574 | def test_rerun_on_abort(self): |
| 4575 | "Test that if a worker fails to run a job, it is run again" |
| 4576 | |
| 4577 | self.config.set('zuul', 'layout_config', |
| 4578 | 'tests/fixtures/layout-abort-attempts.yaml') |
| 4579 | self.sched.reconfigure(self.config) |
| 4580 | self.worker.hold_jobs_in_build = True |
| 4581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4582 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4583 | self.waitUntilSettled() |
| 4584 | |
| 4585 | self.worker.release('.*-merge') |
| 4586 | self.waitUntilSettled() |
| 4587 | |
| 4588 | self.assertEqual(len(self.builds), 2) |
| 4589 | self.builds[0].requeue = True |
| 4590 | self.worker.release('.*-test*') |
| 4591 | self.waitUntilSettled() |
| 4592 | |
| 4593 | for x in range(3): |
| 4594 | self.assertEqual(len(self.builds), 1) |
| 4595 | self.builds[0].requeue = True |
| 4596 | self.worker.release('.*-test1') |
| 4597 | self.waitUntilSettled() |
| 4598 | |
| 4599 | self.worker.hold_jobs_in_build = False |
| 4600 | self.worker.release() |
| 4601 | self.waitUntilSettled() |
| 4602 | self.assertEqual(len(self.history), 6) |
| 4603 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4604 | self.assertEqual(A.reported, 1) |
| 4605 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4606 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4607 | |
| 4608 | class TestDuplicatePipeline(ZuulTestCase): |
| 4609 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4610 | |
| 4611 | def test_duplicate_pipelines(self): |
| 4612 | "Test that a change matching multiple pipelines works" |
| 4613 | |
| 4614 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4615 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4616 | self.waitUntilSettled() |
| 4617 | |
| 4618 | self.assertHistory([ |
| 4619 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4620 | pipeline='dup1'), |
| 4621 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4622 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4623 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4624 | |
| 4625 | self.assertEqual(len(A.messages), 2) |
| 4626 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4627 | if 'dup1' in A.messages[0]: |
| 4628 | self.assertIn('dup1', A.messages[0]) |
| 4629 | self.assertNotIn('dup2', A.messages[0]) |
| 4630 | self.assertIn('project-test1', A.messages[0]) |
| 4631 | self.assertIn('dup2', A.messages[1]) |
| 4632 | self.assertNotIn('dup1', A.messages[1]) |
| 4633 | self.assertIn('project-test1', A.messages[1]) |
| 4634 | else: |
| 4635 | self.assertIn('dup1', A.messages[1]) |
| 4636 | self.assertNotIn('dup2', A.messages[1]) |
| 4637 | self.assertIn('project-test1', A.messages[1]) |
| 4638 | self.assertIn('dup2', A.messages[0]) |
| 4639 | self.assertNotIn('dup1', A.messages[0]) |
| 4640 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4641 | |
| 4642 | |
| 4643 | class TestSchedulerOneJobProject(ZuulTestCase): |
| 4644 | tenant_config_file = 'config/one-job-project/main.yaml' |
| 4645 | |
| 4646 | def test_one_job_project(self): |
| 4647 | "Test that queueing works with one job" |
| 4648 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4649 | 'master', 'A') |
| 4650 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4651 | 'master', 'B') |
| 4652 | A.addApproval('code-review', 2) |
| 4653 | B.addApproval('code-review', 2) |
| 4654 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4655 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4656 | self.waitUntilSettled() |
| 4657 | |
| 4658 | self.assertEqual(A.data['status'], 'MERGED') |
| 4659 | self.assertEqual(A.reported, 2) |
| 4660 | self.assertEqual(B.data['status'], 'MERGED') |
| 4661 | self.assertEqual(B.reported, 2) |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4662 | |
| 4663 | |
| 4664 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4665 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4666 | |
| 4667 | def test_job_from_templates_launched(self): |
| 4668 | "Test whether a job generated via a template can be launched" |
| 4669 | |
| 4670 | A = self.fake_gerrit.addFakeChange( |
| 4671 | 'org/templated-project', 'master', 'A') |
| 4672 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4673 | self.waitUntilSettled() |
| 4674 | |
| 4675 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4676 | 'SUCCESS') |
| 4677 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4678 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4679 | |
| 4680 | def test_layered_templates(self): |
| 4681 | "Test whether a job generated via a template can be launched" |
| 4682 | |
| 4683 | A = self.fake_gerrit.addFakeChange( |
| 4684 | 'org/layered-project', 'master', 'A') |
| 4685 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4686 | self.waitUntilSettled() |
| 4687 | |
| 4688 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4689 | 'SUCCESS') |
| 4690 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4691 | 'SUCCESS') |
| 4692 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4693 | ).result, 'SUCCESS') |
| 4694 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4695 | ).result, 'SUCCESS') |
| 4696 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4697 | ).result, 'SUCCESS') |
| 4698 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4699 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4700 | |
| 4701 | |
| 4702 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4703 | tenant_config_file = 'config/success-url/main.yaml' |
| 4704 | |
| 4705 | def test_success_url(self): |
| 4706 | "Ensure bad build params are ignored" |
| 4707 | self.sched.reconfigure(self.config) |
| 4708 | self.init_repo('org/docs') |
| 4709 | |
| 4710 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4711 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4712 | self.waitUntilSettled() |
| 4713 | |
| 4714 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4715 | self.assertEqual(len(self.history), 2) |
| 4716 | |
| 4717 | # Grab build id |
| 4718 | uuid = self.history[0].uuid[:7] |
| 4719 | |
| 4720 | # Two msgs: 'Starting...' + results |
| 4721 | self.assertEqual(len(self.smtp_messages), 2) |
| 4722 | body = self.smtp_messages[1]['body'].splitlines() |
| 4723 | self.assertEqual('Build succeeded.', body[0]) |
| 4724 | |
| 4725 | self.assertIn( |
| 4726 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4727 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4728 | body[2]) |
| 4729 | |
| 4730 | # NOTE: This default URL is currently hard-coded in launcher/server.py |
| 4731 | self.assertIn( |
| 4732 | '- docs-draft-test2 https://server/job', |
| 4733 | body[3]) |