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 |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 23 | import yaml |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 24 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 26 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 27 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 29 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 30 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 32 | import zuul.rpcclient |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 33 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 34 | import zuul.reporter.smtp |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
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'), |
| 286 | dict(name='project-test1', changes='2,1 3,1'), |
| 287 | dict(name='project-test2', changes='2,1 3,1'), |
| 288 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 289 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 290 | self.orderedRelease() |
| 291 | self.assertHistory([ |
| 292 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 293 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 294 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 295 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 296 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 298 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 299 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 300 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
| 301 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 302 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 303 | self.assertEqual(A.data['status'], 'MERGED') |
| 304 | self.assertEqual(B.data['status'], 'MERGED') |
| 305 | self.assertEqual(C.data['status'], 'MERGED') |
| 306 | self.assertEqual(A.reported, 2) |
| 307 | self.assertEqual(B.reported, 2) |
| 308 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 309 | |
| 310 | def test_failed_change_at_head(self): |
| 311 | "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] | 312 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 313 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 314 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 315 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 316 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 317 | A.addApproval('code-review', 2) |
| 318 | B.addApproval('code-review', 2) |
| 319 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 320 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 321 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 322 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 323 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 324 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 325 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 326 | |
| 327 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 328 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 329 | self.assertBuilds([ |
| 330 | dict(name='project-merge', changes='1,1'), |
| 331 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 332 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 333 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 334 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 335 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 336 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 337 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | self.waitUntilSettled() |
| 339 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 340 | self.assertBuilds([ |
| 341 | dict(name='project-test1', changes='1,1'), |
| 342 | dict(name='project-test2', changes='1,1'), |
| 343 | dict(name='project-test1', changes='1,1 2,1'), |
| 344 | dict(name='project-test2', changes='1,1 2,1'), |
| 345 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 346 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 347 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 348 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 349 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 350 | self.waitUntilSettled() |
| 351 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 352 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 353 | self.assertBuilds([ |
| 354 | dict(name='project-test2', changes='1,1'), |
| 355 | dict(name='project-merge', changes='2,1'), |
| 356 | ]) |
| 357 | # Unordered history comparison because the aborts can finish |
| 358 | # in any order. |
| 359 | self.assertHistory([ |
| 360 | dict(name='project-merge', result='SUCCESS', |
| 361 | changes='1,1'), |
| 362 | dict(name='project-merge', result='SUCCESS', |
| 363 | changes='1,1 2,1'), |
| 364 | dict(name='project-merge', result='SUCCESS', |
| 365 | changes='1,1 2,1 3,1'), |
| 366 | dict(name='project-test1', result='FAILURE', |
| 367 | changes='1,1'), |
| 368 | dict(name='project-test1', result='ABORTED', |
| 369 | changes='1,1 2,1'), |
| 370 | dict(name='project-test2', result='ABORTED', |
| 371 | changes='1,1 2,1'), |
| 372 | dict(name='project-test1', result='ABORTED', |
| 373 | changes='1,1 2,1 3,1'), |
| 374 | dict(name='project-test2', result='ABORTED', |
| 375 | changes='1,1 2,1 3,1'), |
| 376 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 377 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 378 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 379 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 380 | self.launch_server.release('.*-merge') |
| 381 | self.waitUntilSettled() |
| 382 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 383 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 384 | self.assertBuilds([]) |
| 385 | self.assertHistory([ |
| 386 | dict(name='project-merge', result='SUCCESS', |
| 387 | changes='1,1'), |
| 388 | dict(name='project-merge', result='SUCCESS', |
| 389 | changes='1,1 2,1'), |
| 390 | dict(name='project-merge', result='SUCCESS', |
| 391 | changes='1,1 2,1 3,1'), |
| 392 | dict(name='project-test1', result='FAILURE', |
| 393 | changes='1,1'), |
| 394 | dict(name='project-test1', result='ABORTED', |
| 395 | changes='1,1 2,1'), |
| 396 | dict(name='project-test2', result='ABORTED', |
| 397 | changes='1,1 2,1'), |
| 398 | dict(name='project-test1', result='ABORTED', |
| 399 | changes='1,1 2,1 3,1'), |
| 400 | dict(name='project-test2', result='ABORTED', |
| 401 | changes='1,1 2,1 3,1'), |
| 402 | dict(name='project-merge', result='SUCCESS', |
| 403 | changes='2,1'), |
| 404 | dict(name='project-merge', result='SUCCESS', |
| 405 | changes='2,1 3,1'), |
| 406 | dict(name='project-test2', result='SUCCESS', |
| 407 | changes='1,1'), |
| 408 | dict(name='project-test1', result='SUCCESS', |
| 409 | changes='2,1'), |
| 410 | dict(name='project-test2', result='SUCCESS', |
| 411 | changes='2,1'), |
| 412 | dict(name='project-test1', result='SUCCESS', |
| 413 | changes='2,1 3,1'), |
| 414 | dict(name='project-test2', result='SUCCESS', |
| 415 | changes='2,1 3,1'), |
| 416 | ], ordered=False) |
| 417 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 418 | self.assertEqual(A.data['status'], 'NEW') |
| 419 | self.assertEqual(B.data['status'], 'MERGED') |
| 420 | self.assertEqual(C.data['status'], 'MERGED') |
| 421 | self.assertEqual(A.reported, 2) |
| 422 | self.assertEqual(B.reported, 2) |
| 423 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 424 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 425 | def test_failed_change_in_middle(self): |
| 426 | "Test a failed change in the middle of the queue" |
| 427 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 428 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 429 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 430 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 431 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 432 | A.addApproval('code-review', 2) |
| 433 | B.addApproval('code-review', 2) |
| 434 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 435 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 436 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 437 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 438 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 439 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 440 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 441 | |
| 442 | self.waitUntilSettled() |
| 443 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 444 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 445 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 446 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 447 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 448 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 449 | self.waitUntilSettled() |
| 450 | |
| 451 | self.assertEqual(len(self.builds), 6) |
| 452 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 453 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 454 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 455 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 456 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 457 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 458 | |
| 459 | self.release(self.builds[2]) |
| 460 | self.waitUntilSettled() |
| 461 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 462 | # project-test1 and project-test2 for A |
| 463 | # project-test2 for B |
| 464 | # project-merge for C (without B) |
| 465 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 466 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 467 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 468 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 469 | self.waitUntilSettled() |
| 470 | |
| 471 | # project-test1 and project-test2 for A |
| 472 | # project-test2 for B |
| 473 | # project-test1 and project-test2 for C |
| 474 | self.assertEqual(len(self.builds), 5) |
| 475 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame^] | 476 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 477 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 478 | builds = items[0].current_build_set.getBuilds() |
| 479 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 480 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 481 | builds = items[1].current_build_set.getBuilds() |
| 482 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 483 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 484 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 485 | builds = items[2].current_build_set.getBuilds() |
| 486 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 487 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 488 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 489 | self.launch_server.hold_jobs_in_build = False |
| 490 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 491 | self.waitUntilSettled() |
| 492 | |
| 493 | self.assertEqual(len(self.builds), 0) |
| 494 | self.assertEqual(len(self.history), 12) |
| 495 | self.assertEqual(A.data['status'], 'MERGED') |
| 496 | self.assertEqual(B.data['status'], 'NEW') |
| 497 | self.assertEqual(C.data['status'], 'MERGED') |
| 498 | self.assertEqual(A.reported, 2) |
| 499 | self.assertEqual(B.reported, 2) |
| 500 | self.assertEqual(C.reported, 2) |
| 501 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 502 | @skip("Disabled for early v3 development") |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 503 | def test_failed_change_at_head_with_queue(self): |
| 504 | "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] | 505 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 506 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 507 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 508 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 509 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 510 | A.addApproval('code-review', 2) |
| 511 | B.addApproval('code-review', 2) |
| 512 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 513 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 514 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 515 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 516 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 517 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 518 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 519 | |
| 520 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 521 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 522 | self.assertEqual(len(self.builds), 0) |
| 523 | self.assertEqual(len(queue), 1) |
| 524 | self.assertEqual(queue[0].name, 'build:project-merge') |
| 525 | self.assertTrue(self.job_has_changes(queue[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 526 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 527 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 528 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 529 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 530 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 531 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 532 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 533 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 534 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 535 | self.assertEqual(len(self.builds), 0) |
| 536 | self.assertEqual(len(queue), 6) |
| 537 | self.assertEqual(queue[0].name, 'build:project-test1') |
| 538 | self.assertEqual(queue[1].name, 'build:project-test2') |
| 539 | self.assertEqual(queue[2].name, 'build:project-test1') |
| 540 | self.assertEqual(queue[3].name, 'build:project-test2') |
| 541 | self.assertEqual(queue[4].name, 'build:project-test1') |
| 542 | self.assertEqual(queue[5].name, 'build:project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 544 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 545 | self.waitUntilSettled() |
| 546 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 547 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 548 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 549 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 550 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 551 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 552 | self.gearman_server.hold_jobs_in_queue = False |
| 553 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 554 | self.waitUntilSettled() |
| 555 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 556 | self.assertEqual(len(self.builds), 0) |
| 557 | self.assertEqual(len(self.history), 11) |
| 558 | self.assertEqual(A.data['status'], 'NEW') |
| 559 | self.assertEqual(B.data['status'], 'MERGED') |
| 560 | self.assertEqual(C.data['status'], 'MERGED') |
| 561 | self.assertEqual(A.reported, 2) |
| 562 | self.assertEqual(B.reported, 2) |
| 563 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 564 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 565 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 566 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 567 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 568 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 569 | A.addApproval('code-review', 2) |
| 570 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 571 | self.waitUntilSettled() |
| 572 | time.sleep(2) |
| 573 | |
| 574 | data = json.loads(self.sched.formatStatusJSON()) |
| 575 | found_job = None |
| 576 | for pipeline in data['pipelines']: |
| 577 | if pipeline['name'] != 'gate': |
| 578 | continue |
| 579 | for queue in pipeline['change_queues']: |
| 580 | for head in queue['heads']: |
| 581 | for item in head: |
| 582 | for job in item['jobs']: |
| 583 | if job['name'] == 'project-merge': |
| 584 | found_job = job |
| 585 | break |
| 586 | |
| 587 | self.assertIsNotNone(found_job) |
| 588 | if iteration == 1: |
| 589 | self.assertIsNotNone(found_job['estimated_time']) |
| 590 | self.assertIsNone(found_job['remaining_time']) |
| 591 | else: |
| 592 | self.assertIsNotNone(found_job['estimated_time']) |
| 593 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 594 | self.assertIsNotNone(found_job['remaining_time']) |
| 595 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 596 | self.launch_server.hold_jobs_in_build = False |
| 597 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 598 | self.waitUntilSettled() |
| 599 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 600 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 601 | def test_time_database(self): |
| 602 | "Test the time database" |
| 603 | |
| 604 | self._test_time_database(1) |
| 605 | self._test_time_database(2) |
| 606 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 607 | @skip("Disabled for early v3 development") |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 608 | def test_two_failed_changes_at_head(self): |
| 609 | "Test that changes are reparented correctly if 2 fail at head" |
| 610 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 611 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 612 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 613 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 614 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 615 | A.addApproval('code-review', 2) |
| 616 | B.addApproval('code-review', 2) |
| 617 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 618 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 619 | self.launch_server.failJob('project-test1', A) |
| 620 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 621 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 622 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 623 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 624 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 625 | self.waitUntilSettled() |
| 626 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 627 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 628 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 629 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 630 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 631 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 632 | self.waitUntilSettled() |
| 633 | |
| 634 | self.assertEqual(len(self.builds), 6) |
| 635 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 636 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 637 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 638 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 639 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 640 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 641 | |
| 642 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 643 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 644 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 645 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 646 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 647 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 648 | |
| 649 | # Fail change B first |
| 650 | self.release(self.builds[2]) |
| 651 | self.waitUntilSettled() |
| 652 | |
| 653 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 654 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 655 | self.waitUntilSettled() |
| 656 | |
| 657 | self.assertEqual(len(self.builds), 5) |
| 658 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 659 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 660 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 661 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 662 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 663 | |
| 664 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 665 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 666 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 667 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 668 | self.assertFalse(self.job_has_changes(self.builds[4], B)) |
| 669 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 670 | |
| 671 | # Finish running all passing jobs for change A |
| 672 | self.release(self.builds[1]) |
| 673 | self.waitUntilSettled() |
| 674 | # Fail and report change A |
| 675 | self.release(self.builds[0]) |
| 676 | self.waitUntilSettled() |
| 677 | |
| 678 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 679 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 680 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 681 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | self.waitUntilSettled() |
| 683 | |
| 684 | self.assertEqual(len(self.builds), 4) |
| 685 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 686 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 687 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 688 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 689 | |
| 690 | self.assertFalse(self.job_has_changes(self.builds[1], A)) |
| 691 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
| 692 | self.assertFalse(self.job_has_changes(self.builds[1], C)) |
| 693 | |
| 694 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 695 | # After A failed and B and C restarted, B should be back in |
| 696 | # C's tests because it has not failed yet. |
| 697 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 698 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 699 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 700 | self.launch_server.hold_jobs_in_build = False |
| 701 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 702 | self.waitUntilSettled() |
| 703 | |
| 704 | self.assertEqual(len(self.builds), 0) |
| 705 | self.assertEqual(len(self.history), 21) |
| 706 | self.assertEqual(A.data['status'], 'NEW') |
| 707 | self.assertEqual(B.data['status'], 'NEW') |
| 708 | self.assertEqual(C.data['status'], 'MERGED') |
| 709 | self.assertEqual(A.reported, 2) |
| 710 | self.assertEqual(B.reported, 2) |
| 711 | self.assertEqual(C.reported, 2) |
| 712 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 713 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 714 | def test_parse_skip_if(self): |
| 715 | job_yaml = """ |
| 716 | jobs: |
| 717 | - name: job_name |
| 718 | skip-if: |
| 719 | - project: ^project_name$ |
| 720 | branch: ^stable/icehouse$ |
| 721 | all-files-match-any: |
| 722 | - ^filename$ |
| 723 | - project: ^project2_name$ |
| 724 | all-files-match-any: |
| 725 | - ^filename2$ |
| 726 | """.strip() |
| 727 | data = yaml.load(job_yaml) |
| 728 | config_job = data.get('jobs')[0] |
| 729 | cm = zuul.change_matcher |
| 730 | expected = cm.MatchAny([ |
| 731 | cm.MatchAll([ |
| 732 | cm.ProjectMatcher('^project_name$'), |
| 733 | cm.BranchMatcher('^stable/icehouse$'), |
| 734 | cm.MatchAllFiles([cm.FileMatcher('^filename$')]), |
| 735 | ]), |
| 736 | cm.MatchAll([ |
| 737 | cm.ProjectMatcher('^project2_name$'), |
| 738 | cm.MatchAllFiles([cm.FileMatcher('^filename2$')]), |
| 739 | ]), |
| 740 | ]) |
| 741 | matcher = self.sched._parseSkipIf(config_job) |
| 742 | self.assertEqual(expected, matcher) |
| 743 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 744 | def test_patch_order(self): |
| 745 | "Test that dependent patches are tested in the right order" |
| 746 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 747 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 748 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 749 | A.addApproval('code-review', 2) |
| 750 | B.addApproval('code-review', 2) |
| 751 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 752 | |
| 753 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 754 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 755 | M2.setMerged() |
| 756 | M1.setMerged() |
| 757 | |
| 758 | # C -> B -> A -> M1 -> M2 |
| 759 | # M2 is here to make sure it is never queried. If it is, it |
| 760 | # means zuul is walking down the entire history of merged |
| 761 | # changes. |
| 762 | |
| 763 | C.setDependsOn(B, 1) |
| 764 | B.setDependsOn(A, 1) |
| 765 | A.setDependsOn(M1, 1) |
| 766 | M1.setDependsOn(M2, 1) |
| 767 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 768 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 769 | |
| 770 | self.waitUntilSettled() |
| 771 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 772 | self.assertEqual(A.data['status'], 'NEW') |
| 773 | self.assertEqual(B.data['status'], 'NEW') |
| 774 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 775 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 776 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 777 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 778 | |
| 779 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 780 | self.assertEqual(M2.queried, 0) |
| 781 | self.assertEqual(A.data['status'], 'MERGED') |
| 782 | self.assertEqual(B.data['status'], 'MERGED') |
| 783 | self.assertEqual(C.data['status'], 'MERGED') |
| 784 | self.assertEqual(A.reported, 2) |
| 785 | self.assertEqual(B.reported, 2) |
| 786 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 787 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 788 | @skip("Disabled for early v3 development") |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 789 | def test_needed_changes_enqueue(self): |
| 790 | "Test that a needed change is enqueued ahead" |
| 791 | # A Given a git tree like this, if we enqueue |
| 792 | # / \ change C, we should walk up and down the tree |
| 793 | # B G and enqueue changes in the order ABCDEFG. |
| 794 | # /|\ This is also the order that you would get if |
| 795 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 796 | # / the ordering is stable across re-enqueue events. |
| 797 | # D |
| 798 | |
| 799 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 800 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 801 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 802 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 803 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 804 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 805 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 806 | B.setDependsOn(A, 1) |
| 807 | C.setDependsOn(B, 1) |
| 808 | D.setDependsOn(C, 1) |
| 809 | E.setDependsOn(B, 1) |
| 810 | F.setDependsOn(B, 1) |
| 811 | G.setDependsOn(A, 1) |
| 812 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 813 | A.addApproval('code-review', 2) |
| 814 | B.addApproval('code-review', 2) |
| 815 | C.addApproval('code-review', 2) |
| 816 | D.addApproval('code-review', 2) |
| 817 | E.addApproval('code-review', 2) |
| 818 | F.addApproval('code-review', 2) |
| 819 | G.addApproval('code-review', 2) |
| 820 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 821 | |
| 822 | self.waitUntilSettled() |
| 823 | |
| 824 | self.assertEqual(A.data['status'], 'NEW') |
| 825 | self.assertEqual(B.data['status'], 'NEW') |
| 826 | self.assertEqual(C.data['status'], 'NEW') |
| 827 | self.assertEqual(D.data['status'], 'NEW') |
| 828 | self.assertEqual(E.data['status'], 'NEW') |
| 829 | self.assertEqual(F.data['status'], 'NEW') |
| 830 | self.assertEqual(G.data['status'], 'NEW') |
| 831 | |
| 832 | # We're about to add approvals to changes without adding the |
| 833 | # triggering events to Zuul, so that we can be sure that it is |
| 834 | # enqueing the changes based on dependencies, not because of |
| 835 | # triggering events. Since it will have the changes cached |
| 836 | # already (without approvals), we need to clear the cache |
| 837 | # first. |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 838 | for connection in self.connections.values(): |
| 839 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 840 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 841 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 842 | A.addApproval('approved', 1) |
| 843 | B.addApproval('approved', 1) |
| 844 | D.addApproval('approved', 1) |
| 845 | E.addApproval('approved', 1) |
| 846 | F.addApproval('approved', 1) |
| 847 | G.addApproval('approved', 1) |
| 848 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 849 | |
| 850 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 851 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 852 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 853 | self.launch_server.hold_jobs_in_build = False |
| 854 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 855 | self.waitUntilSettled() |
| 856 | |
| 857 | self.assertEqual(A.data['status'], 'MERGED') |
| 858 | self.assertEqual(B.data['status'], 'MERGED') |
| 859 | self.assertEqual(C.data['status'], 'MERGED') |
| 860 | self.assertEqual(D.data['status'], 'MERGED') |
| 861 | self.assertEqual(E.data['status'], 'MERGED') |
| 862 | self.assertEqual(F.data['status'], 'MERGED') |
| 863 | self.assertEqual(G.data['status'], 'MERGED') |
| 864 | self.assertEqual(A.reported, 2) |
| 865 | self.assertEqual(B.reported, 2) |
| 866 | self.assertEqual(C.reported, 2) |
| 867 | self.assertEqual(D.reported, 2) |
| 868 | self.assertEqual(E.reported, 2) |
| 869 | self.assertEqual(F.reported, 2) |
| 870 | self.assertEqual(G.reported, 2) |
| 871 | self.assertEqual(self.history[6].changes, |
| 872 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 873 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 874 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 875 | def test_source_cache(self): |
| 876 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 877 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 878 | |
| 879 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 880 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 881 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 882 | A.addApproval('code-review', 2) |
| 883 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 884 | |
| 885 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 886 | M1.setMerged() |
| 887 | |
| 888 | B.setDependsOn(A, 1) |
| 889 | A.setDependsOn(M1, 1) |
| 890 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 891 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 892 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 893 | |
| 894 | self.waitUntilSettled() |
| 895 | |
| 896 | for build in self.builds: |
| 897 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 898 | build.release() |
| 899 | self.waitUntilSettled() |
| 900 | for build in self.builds: |
| 901 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 902 | build.release() |
| 903 | self.waitUntilSettled() |
| 904 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 905 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 906 | self.waitUntilSettled() |
| 907 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 908 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 909 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 910 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 911 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 912 | self.launch_server.hold_jobs_in_build = False |
| 913 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 914 | self.waitUntilSettled() |
| 915 | |
| 916 | self.assertEqual(A.data['status'], 'MERGED') |
| 917 | self.assertEqual(B.data['status'], 'MERGED') |
| 918 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 919 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 920 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 921 | @skip("Disabled for early v3 development") |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 922 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 923 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 924 | # TODO: move to test_gerrit (this is a unit test!) |
| 925 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 926 | source = self.sched.layout.pipelines['gate'].source |
| 927 | a = source._getChange(1, 2) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 928 | mgr = self.sched.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 929 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 930 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 931 | A.addApproval('code-review', 2) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 932 | a = source._getChange(1, 2, refresh=True) |
| 933 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 934 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 935 | A.addApproval('approved', 1) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 936 | a = source._getChange(1, 2, refresh=True) |
| 937 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 938 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 939 | @skip("Disabled for early v3 development") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 940 | def test_build_configuration(self): |
| 941 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 942 | |
| 943 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 944 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 945 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 946 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 947 | A.addApproval('code-review', 2) |
| 948 | B.addApproval('code-review', 2) |
| 949 | C.addApproval('code-review', 2) |
| 950 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 951 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 952 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 953 | self.waitUntilSettled() |
| 954 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 955 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 956 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 957 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 958 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 959 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 960 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 961 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 962 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 963 | self.gearman_server.hold_jobs_in_queue = False |
| 964 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 965 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 966 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 967 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 968 | repo = git.Repo(path) |
| 969 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 970 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 971 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 972 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 973 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 974 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 975 | def test_build_configuration_conflict(self): |
| 976 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 977 | |
| 978 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 979 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 980 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 981 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 982 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 983 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 984 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 985 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 986 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 987 | A.addApproval('code-review', 2) |
| 988 | B.addApproval('code-review', 2) |
| 989 | C.addApproval('code-review', 2) |
| 990 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 991 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 992 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 993 | self.waitUntilSettled() |
| 994 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 995 | self.assertEqual(A.reported, 1) |
| 996 | self.assertEqual(B.reported, 1) |
| 997 | self.assertEqual(C.reported, 1) |
| 998 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 999 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1000 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1001 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1002 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1003 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1004 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1005 | |
| 1006 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 1007 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1008 | self.gearman_server.hold_jobs_in_queue = False |
| 1009 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1010 | self.waitUntilSettled() |
| 1011 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1012 | self.assertEqual(A.data['status'], 'MERGED') |
| 1013 | self.assertEqual(B.data['status'], 'NEW') |
| 1014 | self.assertEqual(C.data['status'], 'MERGED') |
| 1015 | self.assertEqual(A.reported, 2) |
| 1016 | self.assertEqual(B.reported, 2) |
| 1017 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1018 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1019 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1020 | @skip("Disabled for early v3 development") |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1021 | def test_post(self): |
| 1022 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1023 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1024 | e = { |
| 1025 | "type": "ref-updated", |
| 1026 | "submitter": { |
| 1027 | "name": "User Name", |
| 1028 | }, |
| 1029 | "refUpdate": { |
| 1030 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1031 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1032 | "refName": "master", |
| 1033 | "project": "org/project", |
| 1034 | } |
| 1035 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1036 | self.fake_gerrit.addEvent(e) |
| 1037 | self.waitUntilSettled() |
| 1038 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1039 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1040 | self.assertEqual(len(self.history), 1) |
| 1041 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1042 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1043 | @skip("Disabled for early v3 development") |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1044 | def test_post_ignore_deletes(self): |
| 1045 | "Test that deleting refs does not trigger post jobs" |
| 1046 | |
| 1047 | e = { |
| 1048 | "type": "ref-updated", |
| 1049 | "submitter": { |
| 1050 | "name": "User Name", |
| 1051 | }, |
| 1052 | "refUpdate": { |
| 1053 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1054 | "newRev": "0000000000000000000000000000000000000000", |
| 1055 | "refName": "master", |
| 1056 | "project": "org/project", |
| 1057 | } |
| 1058 | } |
| 1059 | self.fake_gerrit.addEvent(e) |
| 1060 | self.waitUntilSettled() |
| 1061 | |
| 1062 | job_names = [x.name for x in self.history] |
| 1063 | self.assertEqual(len(self.history), 0) |
| 1064 | self.assertNotIn('project-post', job_names) |
| 1065 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1066 | @skip("Disabled for early v3 development") |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1067 | def test_post_ignore_deletes_negative(self): |
| 1068 | "Test that deleting refs does trigger post jobs" |
| 1069 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1070 | self.updateConfigLayout( |
| 1071 | 'tests/fixtures/layout-dont-ignore-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1072 | self.sched.reconfigure(self.config) |
| 1073 | |
| 1074 | e = { |
| 1075 | "type": "ref-updated", |
| 1076 | "submitter": { |
| 1077 | "name": "User Name", |
| 1078 | }, |
| 1079 | "refUpdate": { |
| 1080 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1081 | "newRev": "0000000000000000000000000000000000000000", |
| 1082 | "refName": "master", |
| 1083 | "project": "org/project", |
| 1084 | } |
| 1085 | } |
| 1086 | self.fake_gerrit.addEvent(e) |
| 1087 | self.waitUntilSettled() |
| 1088 | |
| 1089 | job_names = [x.name for x in self.history] |
| 1090 | self.assertEqual(len(self.history), 1) |
| 1091 | self.assertIn('project-post', job_names) |
| 1092 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1093 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1094 | def test_build_configuration_branch(self): |
| 1095 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1096 | |
| 1097 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1098 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1099 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1100 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1101 | A.addApproval('code-review', 2) |
| 1102 | B.addApproval('code-review', 2) |
| 1103 | C.addApproval('code-review', 2) |
| 1104 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1105 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1106 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1107 | self.waitUntilSettled() |
| 1108 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1109 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1110 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1111 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1112 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1113 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1114 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1115 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1116 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1117 | self.gearman_server.hold_jobs_in_queue = False |
| 1118 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1119 | self.waitUntilSettled() |
| 1120 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1121 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1122 | repo = git.Repo(path) |
| 1123 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1124 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1125 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1126 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1127 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1128 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1129 | def test_build_configuration_branch_interaction(self): |
| 1130 | "Test that switching between branches works" |
| 1131 | self.test_build_configuration() |
| 1132 | self.test_build_configuration_branch() |
| 1133 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1134 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1135 | repo = git.Repo(path) |
| 1136 | repo.heads.master.commit = repo.commit('init') |
| 1137 | self.test_build_configuration() |
| 1138 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1139 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1140 | def test_build_configuration_multi_branch(self): |
| 1141 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1142 | |
| 1143 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1144 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1145 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1146 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1147 | A.addApproval('code-review', 2) |
| 1148 | B.addApproval('code-review', 2) |
| 1149 | C.addApproval('code-review', 2) |
| 1150 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1151 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1152 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1153 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1154 | queue = self.gearman_server.getQueue() |
| 1155 | job_A = None |
| 1156 | for job in queue: |
| 1157 | if 'project-merge' in job.name: |
| 1158 | job_A = job |
| 1159 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1160 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1161 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1162 | 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] | 1163 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1164 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1165 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1166 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1167 | job_B = None |
| 1168 | for job in queue: |
| 1169 | if 'project-merge' in job.name: |
| 1170 | job_B = job |
| 1171 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1172 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1173 | 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] | 1174 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1175 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1176 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1177 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1178 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1179 | for job in queue: |
| 1180 | if 'project-merge' in job.name: |
| 1181 | job_C = job |
| 1182 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1183 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1184 | 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] | 1185 | 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] | 1186 | self.gearman_server.hold_jobs_in_queue = False |
| 1187 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1188 | self.waitUntilSettled() |
| 1189 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1190 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1191 | repo = git.Repo(path) |
| 1192 | |
| 1193 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1194 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1195 | 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] | 1196 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1197 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1198 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1199 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1200 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 1201 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1202 | |
| 1203 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1204 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1205 | 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] | 1206 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1207 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1208 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1209 | self.assertEqual(repo_shas[0], commit_B) |
| 1210 | |
| 1211 | repo_messages = [c.message.strip() |
| 1212 | for c in repo.iter_commits(ref_A)] |
| 1213 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1214 | repo_messages.reverse() |
| 1215 | correct_messages = ['initial commit', 'A-1'] |
| 1216 | self.assertEqual(repo_messages, correct_messages) |
| 1217 | self.assertEqual(repo_shas[0], commit_A) |
| 1218 | |
| 1219 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1220 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1221 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1222 | @skip("Disabled for early v3 development") |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1223 | def test_one_job_project(self): |
| 1224 | "Test that queueing works with one job" |
| 1225 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1226 | 'master', 'A') |
| 1227 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1228 | 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1229 | A.addApproval('code-review', 2) |
| 1230 | B.addApproval('code-review', 2) |
| 1231 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1232 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1233 | self.waitUntilSettled() |
| 1234 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1235 | self.assertEqual(A.data['status'], 'MERGED') |
| 1236 | self.assertEqual(A.reported, 2) |
| 1237 | self.assertEqual(B.data['status'], 'MERGED') |
| 1238 | self.assertEqual(B.reported, 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1239 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1240 | @skip("Disabled for early v3 development") |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1241 | def test_job_from_templates_launched(self): |
| 1242 | "Test whether a job generated via a template can be launched" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1243 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1244 | A = self.fake_gerrit.addFakeChange( |
| 1245 | 'org/templated-project', 'master', 'A') |
| 1246 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1247 | self.waitUntilSettled() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1248 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1249 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1250 | 'SUCCESS') |
| 1251 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1252 | 'SUCCESS') |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1253 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1254 | @skip("Disabled for early v3 development") |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1255 | def test_layered_templates(self): |
| 1256 | "Test whether a job generated via a template can be launched" |
| 1257 | |
| 1258 | A = self.fake_gerrit.addFakeChange( |
| 1259 | 'org/layered-project', 'master', 'A') |
| 1260 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1261 | self.waitUntilSettled() |
| 1262 | |
| 1263 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1264 | 'SUCCESS') |
| 1265 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1266 | 'SUCCESS') |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 1267 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 1268 | ).result, 'SUCCESS') |
| 1269 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 1270 | ).result, 'SUCCESS') |
James E. Blair | 12a92b1 | 2014-03-26 11:54:53 -0700 | [diff] [blame] | 1271 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 1272 | ).result, 'SUCCESS') |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1273 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 1274 | 'SUCCESS') |
| 1275 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1276 | def test_dependent_changes_dequeue(self): |
| 1277 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1278 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1280 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1281 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1282 | A.addApproval('code-review', 2) |
| 1283 | B.addApproval('code-review', 2) |
| 1284 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1285 | |
| 1286 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1287 | M1.setMerged() |
| 1288 | |
| 1289 | # C -> B -> A -> M1 |
| 1290 | |
| 1291 | C.setDependsOn(B, 1) |
| 1292 | B.setDependsOn(A, 1) |
| 1293 | A.setDependsOn(M1, 1) |
| 1294 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1295 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1296 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1297 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1298 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1299 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1300 | |
| 1301 | self.waitUntilSettled() |
| 1302 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1303 | self.assertEqual(A.data['status'], 'NEW') |
| 1304 | self.assertEqual(A.reported, 2) |
| 1305 | self.assertEqual(B.data['status'], 'NEW') |
| 1306 | self.assertEqual(B.reported, 2) |
| 1307 | self.assertEqual(C.data['status'], 'NEW') |
| 1308 | self.assertEqual(C.reported, 2) |
| 1309 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1310 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1311 | def test_failing_dependent_changes(self): |
| 1312 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1313 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1315 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1316 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1317 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1318 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1319 | A.addApproval('code-review', 2) |
| 1320 | B.addApproval('code-review', 2) |
| 1321 | C.addApproval('code-review', 2) |
| 1322 | D.addApproval('code-review', 2) |
| 1323 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1324 | |
| 1325 | # E, D -> C -> B, A |
| 1326 | |
| 1327 | D.setDependsOn(C, 1) |
| 1328 | C.setDependsOn(B, 1) |
| 1329 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1330 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1331 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1332 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1333 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1334 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1335 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1336 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1337 | |
| 1338 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1339 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1340 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1341 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1342 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1343 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1344 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1345 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1346 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1347 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1348 | self.waitUntilSettled() |
| 1349 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1350 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1351 | for build in self.builds: |
| 1352 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1353 | build.release() |
| 1354 | self.waitUntilSettled() |
| 1355 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1356 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1357 | self.waitUntilSettled() |
| 1358 | |
| 1359 | self.assertEqual(A.data['status'], 'MERGED') |
| 1360 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1361 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1362 | self.assertEqual(B.data['status'], 'NEW') |
| 1363 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1364 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1365 | self.assertEqual(C.data['status'], 'NEW') |
| 1366 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1367 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1368 | self.assertEqual(D.data['status'], 'NEW') |
| 1369 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1370 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1371 | self.assertEqual(E.data['status'], 'MERGED') |
| 1372 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1373 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1374 | self.assertEqual(len(self.history), 18) |
| 1375 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1376 | @skip("Disabled for early v3 development") |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1377 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1378 | "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] | 1379 | # If it's dequeued more than once, we should see extra |
| 1380 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1381 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1382 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1383 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1384 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1385 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1386 | A.addApproval('code-review', 2) |
| 1387 | B.addApproval('code-review', 2) |
| 1388 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1389 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1390 | self.launch_server.failJob('project1-test1', A) |
| 1391 | self.launch_server.failJob('project1-test2', A) |
| 1392 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1393 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1394 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1395 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1396 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1397 | |
| 1398 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1399 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1400 | self.assertEqual(len(self.builds), 1) |
| 1401 | self.assertEqual(self.builds[0].name, 'project1-merge') |
| 1402 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1403 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1404 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1405 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1406 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1407 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1408 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1409 | self.waitUntilSettled() |
| 1410 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1411 | self.assertEqual(len(self.builds), 9) |
| 1412 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 1413 | self.assertEqual(self.builds[1].name, 'project1-test2') |
| 1414 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
| 1415 | self.assertEqual(self.builds[3].name, 'project1-test1') |
| 1416 | self.assertEqual(self.builds[4].name, 'project1-test2') |
| 1417 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
| 1418 | self.assertEqual(self.builds[6].name, 'project1-test1') |
| 1419 | self.assertEqual(self.builds[7].name, 'project1-test2') |
| 1420 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1421 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1422 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1423 | self.waitUntilSettled() |
| 1424 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1425 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1426 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1427 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1428 | self.launch_server.hold_jobs_in_build = False |
| 1429 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1430 | self.waitUntilSettled() |
| 1431 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1432 | self.assertEqual(len(self.builds), 0) |
| 1433 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1434 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1435 | self.assertEqual(A.data['status'], 'NEW') |
| 1436 | self.assertEqual(B.data['status'], 'MERGED') |
| 1437 | self.assertEqual(C.data['status'], 'MERGED') |
| 1438 | self.assertEqual(A.reported, 2) |
| 1439 | self.assertEqual(B.reported, 2) |
| 1440 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1441 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1442 | @skip("Disabled for early v3 development") |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1443 | def test_nonvoting_job(self): |
| 1444 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1445 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1446 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1447 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1448 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1449 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1450 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1451 | |
| 1452 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1453 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1454 | self.assertEqual(A.data['status'], 'MERGED') |
| 1455 | self.assertEqual(A.reported, 2) |
| 1456 | self.assertEqual( |
| 1457 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1458 | 'SUCCESS') |
| 1459 | self.assertEqual( |
| 1460 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1461 | 'SUCCESS') |
| 1462 | self.assertEqual( |
| 1463 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1464 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1465 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1466 | for build in self.builds: |
| 1467 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1468 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1469 | @skip("Disabled for early v3 development") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1470 | def test_check_queue_success(self): |
| 1471 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1472 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1473 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1474 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1475 | |
| 1476 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1477 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1478 | self.assertEqual(A.data['status'], 'NEW') |
| 1479 | self.assertEqual(A.reported, 1) |
| 1480 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1481 | 'SUCCESS') |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1483 | 'SUCCESS') |
| 1484 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1485 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1486 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1487 | @skip("Disabled for early v3 development") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1488 | def test_check_queue_failure(self): |
| 1489 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1490 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1491 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1492 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1493 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1494 | |
| 1495 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1496 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1497 | self.assertEqual(A.data['status'], 'NEW') |
| 1498 | self.assertEqual(A.reported, 1) |
| 1499 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1500 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1501 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1502 | 'SUCCESS') |
| 1503 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1504 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1505 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1506 | @skip("Disabled for early v3 development") |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1507 | def test_dependent_behind_dequeue(self): |
| 1508 | "test that dependent changes behind dequeued changes work" |
| 1509 | # This complicated test is a reproduction of a real life bug |
| 1510 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1511 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1512 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1513 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1514 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1515 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1516 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1517 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1518 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1519 | D.setDependsOn(C, 1) |
| 1520 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1521 | A.addApproval('code-review', 2) |
| 1522 | B.addApproval('code-review', 2) |
| 1523 | C.addApproval('code-review', 2) |
| 1524 | D.addApproval('code-review', 2) |
| 1525 | E.addApproval('code-review', 2) |
| 1526 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1527 | |
| 1528 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1529 | |
| 1530 | # Change object re-use in the gerrit trigger is hidden if |
| 1531 | # changes are added in quick succession; waiting makes it more |
| 1532 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1533 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1534 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1535 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1536 | self.waitUntilSettled() |
| 1537 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1538 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1539 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1540 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1541 | self.waitUntilSettled() |
| 1542 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1543 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1544 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1545 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1546 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1547 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1548 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1549 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1550 | self.waitUntilSettled() |
| 1551 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1552 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1553 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1554 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1555 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1556 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1557 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1558 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1559 | self.waitUntilSettled() |
| 1560 | |
| 1561 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1562 | |
| 1563 | # Grab pointers to the jobs we want to release before |
| 1564 | # releasing any, because list indexes may change as |
| 1565 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1566 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1567 | a.release() |
| 1568 | b.release() |
| 1569 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1570 | self.waitUntilSettled() |
| 1571 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1572 | self.launch_server.hold_jobs_in_build = False |
| 1573 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1574 | self.waitUntilSettled() |
| 1575 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1576 | self.assertEqual(A.data['status'], 'NEW') |
| 1577 | self.assertEqual(B.data['status'], 'MERGED') |
| 1578 | self.assertEqual(C.data['status'], 'MERGED') |
| 1579 | self.assertEqual(D.data['status'], 'MERGED') |
| 1580 | self.assertEqual(E.data['status'], 'MERGED') |
| 1581 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1582 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1583 | self.assertEqual(A.reported, 2) |
| 1584 | self.assertEqual(B.reported, 2) |
| 1585 | self.assertEqual(C.reported, 2) |
| 1586 | self.assertEqual(D.reported, 2) |
| 1587 | self.assertEqual(E.reported, 2) |
| 1588 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1589 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1590 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1591 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1592 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1593 | @skip("Disabled for early v3 development") |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1594 | def test_merger_repack(self): |
| 1595 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1596 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1597 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1598 | A.addApproval('code-review', 2) |
| 1599 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1600 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1601 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1602 | 'SUCCESS') |
| 1603 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1604 | 'SUCCESS') |
| 1605 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1606 | 'SUCCESS') |
| 1607 | self.assertEqual(A.data['status'], 'MERGED') |
| 1608 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1609 | self.assertEmptyQueues() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 1610 | self.worker.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1611 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1612 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1613 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1614 | |
| 1615 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1616 | A.addApproval('code-review', 2) |
| 1617 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1618 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1619 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1620 | 'SUCCESS') |
| 1621 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1622 | 'SUCCESS') |
| 1623 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1624 | 'SUCCESS') |
| 1625 | self.assertEqual(A.data['status'], 'MERGED') |
| 1626 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1627 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1628 | @skip("Disabled for early v3 development") |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1629 | def test_merger_repack_large_change(self): |
| 1630 | "Test that the merger works with large changes after a repack" |
| 1631 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1632 | # This test assumes the repo is already cloned; make sure it is |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1633 | url = self.fake_gerrit.getGitUrl( |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1634 | self.sched.layout.projects['org/project1']) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1635 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1636 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1637 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1638 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1639 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1640 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1641 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1642 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1643 | A.addApproval('code-review', 2) |
| 1644 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1645 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1646 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 1647 | 'SUCCESS') |
| 1648 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 1649 | 'SUCCESS') |
| 1650 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 1651 | 'SUCCESS') |
| 1652 | self.assertEqual(A.data['status'], 'MERGED') |
| 1653 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1654 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1655 | @skip("Disabled for early v3 development") |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1656 | def test_nonexistent_job(self): |
| 1657 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1658 | # Set to the state immediately after a restart |
| 1659 | self.resetGearmanServer() |
| 1660 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1661 | |
| 1662 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1663 | A.addApproval('code-review', 2) |
| 1664 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1665 | # There may be a thread about to report a lost change |
| 1666 | while A.reported < 2: |
| 1667 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1668 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1669 | self.assertFalse(job_names) |
| 1670 | self.assertEqual(A.data['status'], 'NEW') |
| 1671 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1672 | self.assertEmptyQueues() |
| 1673 | |
| 1674 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1675 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1676 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1677 | A.addApproval('code-review', 2) |
| 1678 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1679 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1680 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1681 | 'SUCCESS') |
| 1682 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1683 | 'SUCCESS') |
| 1684 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1685 | 'SUCCESS') |
| 1686 | self.assertEqual(A.data['status'], 'MERGED') |
| 1687 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1688 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1689 | @skip("Disabled for early v3 development") |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1690 | def test_single_nonexistent_post_job(self): |
| 1691 | "Test launching a single post job that doesn't exist" |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1692 | e = { |
| 1693 | "type": "ref-updated", |
| 1694 | "submitter": { |
| 1695 | "name": "User Name", |
| 1696 | }, |
| 1697 | "refUpdate": { |
| 1698 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1699 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1700 | "refName": "master", |
| 1701 | "project": "org/project", |
| 1702 | } |
| 1703 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1704 | # Set to the state immediately after a restart |
| 1705 | self.resetGearmanServer() |
| 1706 | self.launcher.negative_function_cache_ttl = 0 |
| 1707 | |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1708 | self.fake_gerrit.addEvent(e) |
| 1709 | self.waitUntilSettled() |
| 1710 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1711 | self.assertEqual(len(self.history), 0) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1712 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1713 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1714 | def test_new_patchset_dequeues_old(self): |
| 1715 | "Test that a new patchset causes the old to be dequeued" |
| 1716 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1717 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1718 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1719 | M.setMerged() |
| 1720 | |
| 1721 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1722 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1723 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1724 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1725 | A.addApproval('code-review', 2) |
| 1726 | B.addApproval('code-review', 2) |
| 1727 | C.addApproval('code-review', 2) |
| 1728 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1729 | |
| 1730 | C.setDependsOn(B, 1) |
| 1731 | B.setDependsOn(A, 1) |
| 1732 | A.setDependsOn(M, 1) |
| 1733 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1734 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1735 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1736 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1737 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1738 | self.waitUntilSettled() |
| 1739 | |
| 1740 | B.addPatchset() |
| 1741 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1742 | self.waitUntilSettled() |
| 1743 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1744 | self.launch_server.hold_jobs_in_build = False |
| 1745 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1746 | self.waitUntilSettled() |
| 1747 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1748 | self.assertEqual(A.data['status'], 'MERGED') |
| 1749 | self.assertEqual(A.reported, 2) |
| 1750 | self.assertEqual(B.data['status'], 'NEW') |
| 1751 | self.assertEqual(B.reported, 2) |
| 1752 | self.assertEqual(C.data['status'], 'NEW') |
| 1753 | self.assertEqual(C.reported, 2) |
| 1754 | self.assertEqual(D.data['status'], 'MERGED') |
| 1755 | self.assertEqual(D.reported, 2) |
| 1756 | 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] | 1757 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1758 | @skip("Disabled for early v3 development") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1759 | def test_new_patchset_check(self): |
| 1760 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1761 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1762 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1763 | |
| 1764 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1765 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1766 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1767 | |
| 1768 | # Add two git-dependent changes |
| 1769 | B.setDependsOn(A, 1) |
| 1770 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1771 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1772 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1773 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1774 | |
| 1775 | # A live item, and a non-live/live pair |
| 1776 | items = check_pipeline.getAllItems() |
| 1777 | self.assertEqual(len(items), 3) |
| 1778 | |
| 1779 | self.assertEqual(items[0].change.number, '1') |
| 1780 | self.assertEqual(items[0].change.patchset, '1') |
| 1781 | self.assertFalse(items[0].live) |
| 1782 | |
| 1783 | self.assertEqual(items[1].change.number, '2') |
| 1784 | self.assertEqual(items[1].change.patchset, '1') |
| 1785 | self.assertTrue(items[1].live) |
| 1786 | |
| 1787 | self.assertEqual(items[2].change.number, '1') |
| 1788 | self.assertEqual(items[2].change.patchset, '1') |
| 1789 | self.assertTrue(items[2].live) |
| 1790 | |
| 1791 | # Add a new patchset to A |
| 1792 | A.addPatchset() |
| 1793 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1794 | self.waitUntilSettled() |
| 1795 | |
| 1796 | # The live copy of A,1 should be gone, but the non-live and B |
| 1797 | # should continue, and we should have a new A,2 |
| 1798 | items = check_pipeline.getAllItems() |
| 1799 | self.assertEqual(len(items), 3) |
| 1800 | |
| 1801 | self.assertEqual(items[0].change.number, '1') |
| 1802 | self.assertEqual(items[0].change.patchset, '1') |
| 1803 | self.assertFalse(items[0].live) |
| 1804 | |
| 1805 | self.assertEqual(items[1].change.number, '2') |
| 1806 | self.assertEqual(items[1].change.patchset, '1') |
| 1807 | self.assertTrue(items[1].live) |
| 1808 | |
| 1809 | self.assertEqual(items[2].change.number, '1') |
| 1810 | self.assertEqual(items[2].change.patchset, '2') |
| 1811 | self.assertTrue(items[2].live) |
| 1812 | |
| 1813 | # Add a new patchset to B |
| 1814 | B.addPatchset() |
| 1815 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1816 | self.waitUntilSettled() |
| 1817 | |
| 1818 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1819 | # but we should have a new B,2 (still based on A,1) |
| 1820 | items = check_pipeline.getAllItems() |
| 1821 | self.assertEqual(len(items), 3) |
| 1822 | |
| 1823 | self.assertEqual(items[0].change.number, '1') |
| 1824 | self.assertEqual(items[0].change.patchset, '2') |
| 1825 | self.assertTrue(items[0].live) |
| 1826 | |
| 1827 | self.assertEqual(items[1].change.number, '1') |
| 1828 | self.assertEqual(items[1].change.patchset, '1') |
| 1829 | self.assertFalse(items[1].live) |
| 1830 | |
| 1831 | self.assertEqual(items[2].change.number, '2') |
| 1832 | self.assertEqual(items[2].change.patchset, '2') |
| 1833 | self.assertTrue(items[2].live) |
| 1834 | |
| 1835 | self.builds[0].release() |
| 1836 | self.waitUntilSettled() |
| 1837 | self.builds[0].release() |
| 1838 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1839 | self.launch_server.hold_jobs_in_build = False |
| 1840 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1841 | self.waitUntilSettled() |
| 1842 | |
| 1843 | self.assertEqual(A.reported, 1) |
| 1844 | self.assertEqual(B.reported, 1) |
| 1845 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1846 | self.assertEqual(self.history[0].changes, '1,1') |
| 1847 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1848 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1849 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1850 | self.assertEqual(self.history[2].changes, '1,2') |
| 1851 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1852 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1853 | |
| 1854 | def test_abandoned_gate(self): |
| 1855 | "Test that an abandoned change is dequeued from gate" |
| 1856 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1857 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1858 | |
| 1859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1860 | A.addApproval('code-review', 2) |
| 1861 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1862 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1863 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1864 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1865 | |
| 1866 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1867 | self.waitUntilSettled() |
| 1868 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1869 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1870 | self.waitUntilSettled() |
| 1871 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1872 | self.assertBuilds([]) |
| 1873 | self.assertHistory([ |
| 1874 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1875 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1876 | self.assertEqual(A.reported, 1, |
| 1877 | "Abandoned gate change should report only start") |
| 1878 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1879 | @skip("Disabled for early v3 development") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1880 | def test_abandoned_check(self): |
| 1881 | "Test that an abandoned change is dequeued from check" |
| 1882 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1883 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1884 | |
| 1885 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1886 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1887 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1888 | |
| 1889 | # Add two git-dependent changes |
| 1890 | B.setDependsOn(A, 1) |
| 1891 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1892 | self.waitUntilSettled() |
| 1893 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1894 | self.waitUntilSettled() |
| 1895 | # A live item, and a non-live/live pair |
| 1896 | items = check_pipeline.getAllItems() |
| 1897 | self.assertEqual(len(items), 3) |
| 1898 | |
| 1899 | self.assertEqual(items[0].change.number, '1') |
| 1900 | self.assertFalse(items[0].live) |
| 1901 | |
| 1902 | self.assertEqual(items[1].change.number, '2') |
| 1903 | self.assertTrue(items[1].live) |
| 1904 | |
| 1905 | self.assertEqual(items[2].change.number, '1') |
| 1906 | self.assertTrue(items[2].live) |
| 1907 | |
| 1908 | # Abandon A |
| 1909 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1910 | self.waitUntilSettled() |
| 1911 | |
| 1912 | # The live copy of A should be gone, but the non-live and B |
| 1913 | # should continue |
| 1914 | items = check_pipeline.getAllItems() |
| 1915 | self.assertEqual(len(items), 2) |
| 1916 | |
| 1917 | self.assertEqual(items[0].change.number, '1') |
| 1918 | self.assertFalse(items[0].live) |
| 1919 | |
| 1920 | self.assertEqual(items[1].change.number, '2') |
| 1921 | self.assertTrue(items[1].live) |
| 1922 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1923 | self.launch_server.hold_jobs_in_build = False |
| 1924 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1925 | self.waitUntilSettled() |
| 1926 | |
| 1927 | self.assertEqual(len(self.history), 4) |
| 1928 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1929 | 'Build should have been aborted') |
| 1930 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1931 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1932 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1933 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1934 | def test_abandoned_not_timer(self): |
| 1935 | "Test that an abandoned change does not cancel timer jobs" |
| 1936 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1937 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1938 | |
| 1939 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1940 | self.updateConfigLayout( |
| 1941 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1942 | self.sched.reconfigure(self.config) |
| 1943 | self.registerJobs() |
| 1944 | # The pipeline triggers every second, so we should have seen |
| 1945 | # several by now. |
| 1946 | time.sleep(5) |
| 1947 | self.waitUntilSettled() |
| 1948 | # Stop queuing timer triggered jobs so that the assertions |
| 1949 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1950 | self.updateConfigLayout( |
| 1951 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1952 | self.sched.reconfigure(self.config) |
| 1953 | self.registerJobs() |
| 1954 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1955 | |
| 1956 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1957 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1958 | self.waitUntilSettled() |
| 1959 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1960 | |
| 1961 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1962 | self.waitUntilSettled() |
| 1963 | |
| 1964 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1965 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1966 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1967 | self.waitUntilSettled() |
| 1968 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1969 | @skip("Disabled for early v3 development") |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1970 | def test_zuul_url_return(self): |
| 1971 | "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] | 1972 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1973 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1974 | |
| 1975 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1976 | A.addApproval('code-review', 2) |
| 1977 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1978 | self.waitUntilSettled() |
| 1979 | |
| 1980 | self.assertEqual(len(self.builds), 1) |
| 1981 | for build in self.builds: |
| 1982 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1983 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1984 | self.launch_server.hold_jobs_in_build = False |
| 1985 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1986 | self.waitUntilSettled() |
| 1987 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1988 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1989 | def test_new_patchset_dequeues_old_on_head(self): |
| 1990 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1991 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1992 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1993 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1994 | M.setMerged() |
| 1995 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1996 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1997 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1998 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1999 | A.addApproval('code-review', 2) |
| 2000 | B.addApproval('code-review', 2) |
| 2001 | C.addApproval('code-review', 2) |
| 2002 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2003 | |
| 2004 | C.setDependsOn(B, 1) |
| 2005 | B.setDependsOn(A, 1) |
| 2006 | A.setDependsOn(M, 1) |
| 2007 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2008 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2009 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2010 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2011 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2012 | self.waitUntilSettled() |
| 2013 | |
| 2014 | A.addPatchset() |
| 2015 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2016 | self.waitUntilSettled() |
| 2017 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2018 | self.launch_server.hold_jobs_in_build = False |
| 2019 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2020 | self.waitUntilSettled() |
| 2021 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2022 | self.assertEqual(A.data['status'], 'NEW') |
| 2023 | self.assertEqual(A.reported, 2) |
| 2024 | self.assertEqual(B.data['status'], 'NEW') |
| 2025 | self.assertEqual(B.reported, 2) |
| 2026 | self.assertEqual(C.data['status'], 'NEW') |
| 2027 | self.assertEqual(C.reported, 2) |
| 2028 | self.assertEqual(D.data['status'], 'MERGED') |
| 2029 | self.assertEqual(D.reported, 2) |
| 2030 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2031 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2032 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2033 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2034 | "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] | 2035 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2036 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2037 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2038 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2039 | A.addApproval('code-review', 2) |
| 2040 | B.addApproval('code-review', 2) |
| 2041 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2042 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2043 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2044 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2045 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2046 | self.waitUntilSettled() |
| 2047 | |
| 2048 | B.addPatchset() |
| 2049 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2050 | self.waitUntilSettled() |
| 2051 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2052 | self.launch_server.hold_jobs_in_build = False |
| 2053 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2054 | self.waitUntilSettled() |
| 2055 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2056 | self.assertEqual(A.data['status'], 'MERGED') |
| 2057 | self.assertEqual(A.reported, 2) |
| 2058 | self.assertEqual(B.data['status'], 'NEW') |
| 2059 | self.assertEqual(B.reported, 2) |
| 2060 | self.assertEqual(C.data['status'], 'MERGED') |
| 2061 | self.assertEqual(C.reported, 2) |
| 2062 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2063 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2064 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2065 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2066 | "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] | 2067 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2068 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2069 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2070 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2071 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2072 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2073 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2074 | self.waitUntilSettled() |
| 2075 | |
| 2076 | B.addPatchset() |
| 2077 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2078 | self.waitUntilSettled() |
| 2079 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2080 | self.launch_server.hold_jobs_in_build = False |
| 2081 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2082 | self.waitUntilSettled() |
| 2083 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2084 | self.assertEqual(A.data['status'], 'NEW') |
| 2085 | self.assertEqual(A.reported, 1) |
| 2086 | self.assertEqual(B.data['status'], 'NEW') |
| 2087 | self.assertEqual(B.reported, 1) |
| 2088 | self.assertEqual(C.data['status'], 'NEW') |
| 2089 | self.assertEqual(C.reported, 1) |
| 2090 | self.assertEqual(len(self.history), 10) |
| 2091 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2092 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2093 | @skip("Disabled for early v3 development") |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2094 | def test_noop_job(self): |
| 2095 | "Test that the internal noop job works" |
| 2096 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2097 | A.addApproval('code-review', 2) |
| 2098 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2099 | self.waitUntilSettled() |
| 2100 | |
| 2101 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2102 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2103 | self.assertEqual(len(self.history), 0) |
| 2104 | self.assertEqual(A.data['status'], 'MERGED') |
| 2105 | self.assertEqual(A.reported, 2) |
| 2106 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2107 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2108 | def test_no_job_project(self): |
| 2109 | "Test that reports with no jobs don't get sent" |
| 2110 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2111 | 'master', 'A') |
| 2112 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2113 | self.waitUntilSettled() |
| 2114 | |
| 2115 | # Change wasn't reported to |
| 2116 | self.assertEqual(A.reported, False) |
| 2117 | |
| 2118 | # Check queue is empty afterwards |
| 2119 | check_pipeline = self.sched.layout.pipelines['check'] |
| 2120 | items = check_pipeline.getAllItems() |
| 2121 | self.assertEqual(len(items), 0) |
| 2122 | |
| 2123 | self.assertEqual(len(self.history), 0) |
| 2124 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2125 | @skip("Disabled for early v3 development") |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2126 | def test_zuul_refs(self): |
| 2127 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2128 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2129 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2130 | M1.setMerged() |
| 2131 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2132 | M2.setMerged() |
| 2133 | |
| 2134 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2135 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2136 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2137 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2138 | A.addApproval('code-review', 2) |
| 2139 | B.addApproval('code-review', 2) |
| 2140 | C.addApproval('code-review', 2) |
| 2141 | D.addApproval('code-review', 2) |
| 2142 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2143 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2144 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2145 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2146 | |
| 2147 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2148 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2149 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2150 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2151 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2152 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2153 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2154 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2155 | self.waitUntilSettled() |
| 2156 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2157 | a_zref = b_zref = c_zref = d_zref = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2158 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2159 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2160 | a_zref = x.parameters['ZUUL_REF'] |
| 2161 | if x.parameters['ZUUL_CHANGE'] == '4': |
| 2162 | b_zref = x.parameters['ZUUL_REF'] |
| 2163 | if x.parameters['ZUUL_CHANGE'] == '5': |
| 2164 | c_zref = x.parameters['ZUUL_REF'] |
| 2165 | if x.parameters['ZUUL_CHANGE'] == '6': |
| 2166 | d_zref = x.parameters['ZUUL_REF'] |
| 2167 | |
| 2168 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2169 | self.assertIsNotNone(a_zref) |
| 2170 | self.assertIsNotNone(b_zref) |
| 2171 | self.assertIsNotNone(c_zref) |
| 2172 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2173 | |
| 2174 | # And they should all be different |
| 2175 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2176 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2177 | |
| 2178 | # a ref should have a, not b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2179 | self.assertTrue(self.ref_has_change(a_zref, A)) |
| 2180 | self.assertFalse(self.ref_has_change(a_zref, B)) |
| 2181 | self.assertFalse(self.ref_has_change(a_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2182 | |
| 2183 | # b ref should have a and b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2184 | self.assertTrue(self.ref_has_change(b_zref, A)) |
| 2185 | self.assertTrue(self.ref_has_change(b_zref, B)) |
| 2186 | self.assertFalse(self.ref_has_change(b_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2187 | |
| 2188 | # c ref should have a and b in 1, c in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2189 | self.assertTrue(self.ref_has_change(c_zref, A)) |
| 2190 | self.assertTrue(self.ref_has_change(c_zref, B)) |
| 2191 | self.assertTrue(self.ref_has_change(c_zref, C)) |
| 2192 | self.assertFalse(self.ref_has_change(c_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2193 | |
| 2194 | # d ref should have a and b in 1, c and d in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2195 | self.assertTrue(self.ref_has_change(d_zref, A)) |
| 2196 | self.assertTrue(self.ref_has_change(d_zref, B)) |
| 2197 | self.assertTrue(self.ref_has_change(d_zref, C)) |
| 2198 | self.assertTrue(self.ref_has_change(d_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2199 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2200 | self.launch_server.hold_jobs_in_build = False |
| 2201 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2202 | self.waitUntilSettled() |
| 2203 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 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) |
| 2208 | self.assertEqual(C.data['status'], 'MERGED') |
| 2209 | self.assertEqual(C.reported, 2) |
| 2210 | self.assertEqual(D.data['status'], 'MERGED') |
| 2211 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2212 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2213 | @skip("Disabled for early v3 development") |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2214 | def test_rerun_on_error(self): |
| 2215 | "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] | 2216 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2217 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2218 | A.addApproval('code-review', 2) |
| 2219 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2220 | self.waitUntilSettled() |
| 2221 | |
| 2222 | self.builds[0].run_error = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2223 | self.launch_server.hold_jobs_in_build = False |
| 2224 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2225 | self.waitUntilSettled() |
| 2226 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2227 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2228 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2229 | @skip("Disabled for early v3 development") |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2230 | def test_statsd(self): |
| 2231 | "Test each of the statsd methods used in the scheduler" |
| 2232 | import extras |
| 2233 | statsd = extras.try_import('statsd.statsd') |
| 2234 | statsd.incr('test-incr') |
| 2235 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2236 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2237 | self.assertReportedStat('test-incr', '1|c') |
| 2238 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2239 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2240 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2241 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2242 | def test_stuck_job_cleanup(self): |
| 2243 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2244 | # This job won't be registered at startup because it is not in |
| 2245 | # the standard layout, but we need it to already be registerd |
| 2246 | # for when we reconfigure, as that is when Zuul will attempt |
| 2247 | # to run the new job. |
| 2248 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2249 | self.gearman_server.hold_jobs_in_queue = True |
| 2250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2251 | A.addApproval('code-review', 2) |
| 2252 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2253 | self.waitUntilSettled() |
| 2254 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2255 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2256 | self.updateConfigLayout( |
| 2257 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2258 | self.sched.reconfigure(self.config) |
| 2259 | self.waitUntilSettled() |
| 2260 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2261 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2262 | self.waitUntilSettled() |
| 2263 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2264 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2265 | |
| 2266 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2267 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2268 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2269 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2270 | @skip("Disabled for early v3 development") |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2271 | def test_file_head(self): |
| 2272 | # This is a regression test for an observed bug. A change |
| 2273 | # with a file named "HEAD" in the root directory of the repo |
| 2274 | # was processed by a merger. It then was unable to reset the |
| 2275 | # repo because of: |
| 2276 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2277 | # with exit code 128 |
| 2278 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2279 | # and filename |
| 2280 | # Use '--' to separate filenames from revisions' |
| 2281 | |
| 2282 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2283 | A.addPatchset(['HEAD']) |
| 2284 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2285 | |
| 2286 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2287 | self.waitUntilSettled() |
| 2288 | |
| 2289 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2290 | self.waitUntilSettled() |
| 2291 | |
| 2292 | self.assertIn('Build succeeded', A.messages[0]) |
| 2293 | self.assertIn('Build succeeded', B.messages[0]) |
| 2294 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2295 | @skip("Disabled for early v3 development") |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2296 | def test_file_jobs(self): |
| 2297 | "Test that file jobs run only when appropriate" |
| 2298 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2299 | A.addPatchset(['pip-requires']) |
| 2300 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2301 | A.addApproval('code-review', 2) |
| 2302 | B.addApproval('code-review', 2) |
| 2303 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2304 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2305 | self.waitUntilSettled() |
| 2306 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2307 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2308 | if x.name == 'project-testfile'] |
| 2309 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2310 | self.assertEqual(len(testfile_jobs), 1) |
| 2311 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2312 | self.assertEqual(A.data['status'], 'MERGED') |
| 2313 | self.assertEqual(A.reported, 2) |
| 2314 | self.assertEqual(B.data['status'], 'MERGED') |
| 2315 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2316 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2317 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2318 | def _test_skip_if_jobs(self, branch, should_skip): |
| 2319 | "Test that jobs with a skip-if filter run only when appropriate" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2320 | self.updateConfigLayout( |
| 2321 | 'tests/fixtures/layout-skip-if.yaml') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2322 | self.sched.reconfigure(self.config) |
| 2323 | self.registerJobs() |
| 2324 | |
| 2325 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2326 | branch, |
| 2327 | 'test skip-if') |
| 2328 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2329 | self.waitUntilSettled() |
| 2330 | |
| 2331 | tested_change_ids = [x.changes[0] for x in self.history |
| 2332 | if x.name == 'project-test-skip-if'] |
| 2333 | |
| 2334 | if should_skip: |
| 2335 | self.assertEqual([], tested_change_ids) |
| 2336 | else: |
| 2337 | self.assertIn(change.data['number'], tested_change_ids) |
| 2338 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2339 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2340 | def test_skip_if_match_skips_job(self): |
| 2341 | self._test_skip_if_jobs(branch='master', should_skip=True) |
| 2342 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2343 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2344 | def test_skip_if_no_match_runs_job(self): |
| 2345 | self._test_skip_if_jobs(branch='mp', should_skip=False) |
| 2346 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2347 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2348 | def test_test_config(self): |
| 2349 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2350 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2351 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2352 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2353 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2354 | def test_queue_names(self): |
| 2355 | "Test shared change queue names" |
| 2356 | project1 = self.sched.layout.projects['org/project1'] |
| 2357 | project2 = self.sched.layout.projects['org/project2'] |
| 2358 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2359 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2360 | self.assertEqual(q1.name, 'integration') |
| 2361 | self.assertEqual(q2.name, 'integration') |
| 2362 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2363 | self.updateConfigLayout( |
| 2364 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2365 | with testtools.ExpectedException( |
| 2366 | Exception, "More than one name assigned to change queue"): |
| 2367 | self.sched.reconfigure(self.config) |
| 2368 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2369 | @skip("Disabled for early v3 development") |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2370 | def test_queue_precedence(self): |
| 2371 | "Test that queue precedence works" |
| 2372 | |
| 2373 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2374 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2375 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2376 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2377 | A.addApproval('code-review', 2) |
| 2378 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2379 | |
| 2380 | self.waitUntilSettled() |
| 2381 | self.gearman_server.hold_jobs_in_queue = False |
| 2382 | self.gearman_server.release() |
| 2383 | self.waitUntilSettled() |
| 2384 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2385 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2386 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2387 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2388 | self.waitUntilSettled() |
| 2389 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2390 | self.log.debug(self.history) |
| 2391 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2392 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2393 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2394 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2395 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2396 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2397 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2398 | @skip("Disabled for early v3 development") |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2399 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2400 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2401 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2402 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2403 | A.addApproval('code-review', 2) |
| 2404 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2405 | self.waitUntilSettled() |
| 2406 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2407 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2408 | self.waitUntilSettled() |
| 2409 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2410 | port = self.webapp.server.socket.getsockname()[1] |
| 2411 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2412 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2413 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2414 | headers = f.info() |
| 2415 | self.assertIn('Content-Length', headers) |
| 2416 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2417 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2418 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2419 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2420 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2421 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2422 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2423 | data = f.read() |
| 2424 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2425 | self.launch_server.hold_jobs_in_build = False |
| 2426 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2427 | self.waitUntilSettled() |
| 2428 | |
| 2429 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2430 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2431 | for p in data['pipelines']: |
| 2432 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2433 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2434 | self.assertEqual(q['window'], 20) |
| 2435 | else: |
| 2436 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2437 | for head in q['heads']: |
| 2438 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2439 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2440 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2441 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2442 | status_jobs.append(job) |
| 2443 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2444 | self.assertEqual('https://server/job/project-merge/0/', |
| 2445 | status_jobs[0]['url']) |
| 2446 | self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0', |
| 2447 | status_jobs[0]['report_url']) |
| 2448 | |
| 2449 | self.assertEqual('project-test1', status_jobs[1]['name']) |
| 2450 | self.assertEqual('https://server/job/project-test1/1/', |
| 2451 | status_jobs[1]['url']) |
| 2452 | self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1', |
| 2453 | status_jobs[1]['report_url']) |
| 2454 | |
| 2455 | self.assertEqual('project-test2', status_jobs[2]['name']) |
| 2456 | self.assertEqual('https://server/job/project-test2/2/', |
| 2457 | status_jobs[2]['url']) |
| 2458 | self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2', |
| 2459 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2460 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2461 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2462 | def test_merging_queues(self): |
| 2463 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2464 | self.updateConfigLayout( |
| 2465 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2466 | self.sched.reconfigure(self.config) |
| 2467 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2468 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2469 | @skip("Disabled for early v3 development") |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2470 | def test_mutex(self): |
| 2471 | "Test job mutexes" |
| 2472 | self.config.set('zuul', 'layout_config', |
| 2473 | 'tests/fixtures/layout-mutex.yaml') |
| 2474 | self.sched.reconfigure(self.config) |
| 2475 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2476 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2477 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2478 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2479 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2480 | |
| 2481 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2482 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2483 | self.waitUntilSettled() |
| 2484 | self.assertEqual(len(self.builds), 3) |
| 2485 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2486 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2487 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2488 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2489 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2490 | self.waitUntilSettled() |
| 2491 | |
| 2492 | self.assertEqual(len(self.builds), 3) |
| 2493 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2494 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2495 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2496 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2497 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2498 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2499 | self.waitUntilSettled() |
| 2500 | |
| 2501 | self.assertEqual(len(self.builds), 3) |
| 2502 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2503 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2504 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2505 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2506 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2507 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2508 | self.waitUntilSettled() |
| 2509 | |
| 2510 | self.assertEqual(len(self.builds), 3) |
| 2511 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2512 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2513 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2514 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2515 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2516 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2517 | self.waitUntilSettled() |
| 2518 | |
| 2519 | self.assertEqual(len(self.builds), 2) |
| 2520 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2521 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2522 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2523 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2524 | self.launch_server.hold_jobs_in_build = False |
| 2525 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2526 | |
| 2527 | self.waitUntilSettled() |
| 2528 | self.assertEqual(len(self.builds), 0) |
| 2529 | |
| 2530 | self.assertEqual(A.reported, 1) |
| 2531 | self.assertEqual(B.reported, 1) |
| 2532 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2533 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2534 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2535 | def test_node_label(self): |
| 2536 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2537 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2538 | |
| 2539 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2540 | A.addApproval('code-review', 2) |
| 2541 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2542 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2543 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2544 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2545 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2546 | 'debian') |
| 2547 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2548 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2549 | @skip("Disabled for early v3 development") |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2550 | def test_live_reconfiguration(self): |
| 2551 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2552 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2553 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
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 | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2556 | self.waitUntilSettled() |
| 2557 | |
| 2558 | self.sched.reconfigure(self.config) |
| 2559 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2560 | self.launch_server.hold_jobs_in_build = False |
| 2561 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2562 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2563 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2564 | 'SUCCESS') |
| 2565 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2566 | 'SUCCESS') |
| 2567 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2568 | 'SUCCESS') |
| 2569 | self.assertEqual(A.data['status'], 'MERGED') |
| 2570 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2571 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2572 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2573 | def test_live_reconfiguration_merge_conflict(self): |
| 2574 | # A real-world bug: a change in a gate queue has a merge |
| 2575 | # conflict and a job is added to its project while it's |
| 2576 | # sitting in the queue. The job gets added to the change and |
| 2577 | # enqueued and the change gets stuck. |
| 2578 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2579 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2580 | |
| 2581 | # This change is fine. It's here to stop the queue long |
| 2582 | # enough for the next change to be subject to the |
| 2583 | # reconfiguration, as well as to provide a conflict for the |
| 2584 | # next change. This change will succeed and merge. |
| 2585 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2586 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2587 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2588 | |
| 2589 | # This change will be in merge conflict. During the |
| 2590 | # reconfiguration, we will add a job. We want to make sure |
| 2591 | # that doesn't cause it to get stuck. |
| 2592 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2593 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2594 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2595 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2596 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2597 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2598 | |
| 2599 | self.waitUntilSettled() |
| 2600 | |
| 2601 | # No jobs have run yet |
| 2602 | self.assertEqual(A.data['status'], 'NEW') |
| 2603 | self.assertEqual(A.reported, 1) |
| 2604 | self.assertEqual(B.data['status'], 'NEW') |
| 2605 | self.assertEqual(B.reported, 1) |
| 2606 | self.assertEqual(len(self.history), 0) |
| 2607 | |
| 2608 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2609 | self.updateConfigLayout( |
| 2610 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2611 | self.sched.reconfigure(self.config) |
| 2612 | self.waitUntilSettled() |
| 2613 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2614 | self.launch_server.hold_jobs_in_build = False |
| 2615 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2616 | self.waitUntilSettled() |
| 2617 | |
| 2618 | self.assertEqual(A.data['status'], 'MERGED') |
| 2619 | self.assertEqual(A.reported, 2) |
| 2620 | self.assertEqual(B.data['status'], 'NEW') |
| 2621 | self.assertEqual(B.reported, 2) |
| 2622 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2623 | 'SUCCESS') |
| 2624 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2625 | 'SUCCESS') |
| 2626 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2627 | 'SUCCESS') |
| 2628 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2629 | 'SUCCESS') |
| 2630 | self.assertEqual(len(self.history), 4) |
| 2631 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2632 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2633 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2634 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2635 | # that tests a job added to a job tree with a failed root does |
| 2636 | # not run. |
| 2637 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2638 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2639 | |
| 2640 | # This change is fine. It's here to stop the queue long |
| 2641 | # enough for the next change to be subject to the |
| 2642 | # reconfiguration. This change will succeed and merge. |
| 2643 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2644 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2645 | A.addApproval('code-review', 2) |
| 2646 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2647 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2648 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2649 | self.waitUntilSettled() |
| 2650 | |
| 2651 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2652 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2653 | B.addApproval('code-review', 2) |
| 2654 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2655 | self.waitUntilSettled() |
| 2656 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2657 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2658 | self.waitUntilSettled() |
| 2659 | |
| 2660 | # Both -merge jobs have run, but no others. |
| 2661 | self.assertEqual(A.data['status'], 'NEW') |
| 2662 | self.assertEqual(A.reported, 1) |
| 2663 | self.assertEqual(B.data['status'], 'NEW') |
| 2664 | self.assertEqual(B.reported, 1) |
| 2665 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2666 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2667 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2668 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2669 | self.assertEqual(len(self.history), 2) |
| 2670 | |
| 2671 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2672 | self.updateConfigLayout( |
| 2673 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2674 | self.sched.reconfigure(self.config) |
| 2675 | self.waitUntilSettled() |
| 2676 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2677 | self.launch_server.hold_jobs_in_build = False |
| 2678 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2679 | self.waitUntilSettled() |
| 2680 | |
| 2681 | self.assertEqual(A.data['status'], 'MERGED') |
| 2682 | self.assertEqual(A.reported, 2) |
| 2683 | self.assertEqual(B.data['status'], 'NEW') |
| 2684 | self.assertEqual(B.reported, 2) |
| 2685 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2686 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2687 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2688 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2689 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2690 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2691 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2692 | self.assertEqual(len(self.history), 5) |
| 2693 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2694 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2695 | def test_live_reconfiguration_failed_job(self): |
| 2696 | # Test that a change with a removed failing job does not |
| 2697 | # disrupt reconfiguration. If a change has a failed job and |
| 2698 | # that job is removed during a reconfiguration, we observed a |
| 2699 | # bug where the code to re-set build statuses would run on |
| 2700 | # that build and raise an exception because the job no longer |
| 2701 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2702 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2703 | |
| 2704 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2705 | |
| 2706 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2707 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2708 | |
| 2709 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2710 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2711 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2712 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2713 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2714 | self.waitUntilSettled() |
| 2715 | |
| 2716 | self.assertEqual(A.data['status'], 'NEW') |
| 2717 | self.assertEqual(A.reported, 0) |
| 2718 | |
| 2719 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2720 | 'SUCCESS') |
| 2721 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2722 | 'FAILURE') |
| 2723 | self.assertEqual(len(self.history), 2) |
| 2724 | |
| 2725 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2726 | self.updateConfigLayout( |
| 2727 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2728 | self.sched.reconfigure(self.config) |
| 2729 | self.waitUntilSettled() |
| 2730 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2731 | self.launch_server.hold_jobs_in_build = False |
| 2732 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2733 | self.waitUntilSettled() |
| 2734 | |
| 2735 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2736 | 'SUCCESS') |
| 2737 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2738 | 'SUCCESS') |
| 2739 | self.assertEqual(len(self.history), 4) |
| 2740 | |
| 2741 | self.assertEqual(A.data['status'], 'NEW') |
| 2742 | self.assertEqual(A.reported, 1) |
| 2743 | self.assertIn('Build succeeded', A.messages[0]) |
| 2744 | # Ensure the removed job was not included in the report. |
| 2745 | self.assertNotIn('project-test1', A.messages[0]) |
| 2746 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2747 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2748 | def test_live_reconfiguration_shared_queue(self): |
| 2749 | # Test that a change with a failing job which was removed from |
| 2750 | # this project but otherwise still exists in the system does |
| 2751 | # not disrupt reconfiguration. |
| 2752 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2753 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2754 | |
| 2755 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2756 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2757 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2758 | |
| 2759 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2760 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2761 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2762 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2763 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2764 | self.waitUntilSettled() |
| 2765 | |
| 2766 | self.assertEqual(A.data['status'], 'NEW') |
| 2767 | self.assertEqual(A.reported, 0) |
| 2768 | |
| 2769 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2770 | 'SUCCESS') |
| 2771 | self.assertEqual(self.getJobFromHistory( |
| 2772 | 'project1-project2-integration').result, 'FAILURE') |
| 2773 | self.assertEqual(len(self.history), 2) |
| 2774 | |
| 2775 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2776 | self.updateConfigLayout( |
| 2777 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2778 | self.sched.reconfigure(self.config) |
| 2779 | self.waitUntilSettled() |
| 2780 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2781 | self.launch_server.hold_jobs_in_build = False |
| 2782 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2783 | self.waitUntilSettled() |
| 2784 | |
| 2785 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2786 | 'SUCCESS') |
| 2787 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2788 | 'SUCCESS') |
| 2789 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2790 | 'SUCCESS') |
| 2791 | self.assertEqual(self.getJobFromHistory( |
| 2792 | 'project1-project2-integration').result, 'FAILURE') |
| 2793 | self.assertEqual(len(self.history), 4) |
| 2794 | |
| 2795 | self.assertEqual(A.data['status'], 'NEW') |
| 2796 | self.assertEqual(A.reported, 1) |
| 2797 | self.assertIn('Build succeeded', A.messages[0]) |
| 2798 | # Ensure the removed job was not included in the report. |
| 2799 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2800 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2801 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2802 | def test_double_live_reconfiguration_shared_queue(self): |
| 2803 | # This was a real-world regression. A change is added to |
| 2804 | # gate; a reconfigure happens, a second change which depends |
| 2805 | # on the first is added, and a second reconfiguration happens. |
| 2806 | # Ensure that both changes merge. |
| 2807 | |
| 2808 | # A failure may indicate incorrect caching or cleaning up of |
| 2809 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2810 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2811 | |
| 2812 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2813 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2814 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2815 | A.addApproval('code-review', 2) |
| 2816 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2817 | |
| 2818 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2819 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2820 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2821 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2822 | self.waitUntilSettled() |
| 2823 | |
| 2824 | # Reconfigure (with only one change in the pipeline). |
| 2825 | self.sched.reconfigure(self.config) |
| 2826 | self.waitUntilSettled() |
| 2827 | |
| 2828 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2829 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2830 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2831 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2832 | self.waitUntilSettled() |
| 2833 | |
| 2834 | # Reconfigure (with both in the pipeline). |
| 2835 | self.sched.reconfigure(self.config) |
| 2836 | self.waitUntilSettled() |
| 2837 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2838 | self.launch_server.hold_jobs_in_build = False |
| 2839 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2840 | self.waitUntilSettled() |
| 2841 | |
| 2842 | self.assertEqual(len(self.history), 8) |
| 2843 | |
| 2844 | self.assertEqual(A.data['status'], 'MERGED') |
| 2845 | self.assertEqual(A.reported, 2) |
| 2846 | self.assertEqual(B.data['status'], 'MERGED') |
| 2847 | self.assertEqual(B.reported, 2) |
| 2848 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2849 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2850 | def test_live_reconfiguration_del_project(self): |
| 2851 | # Test project deletion from layout |
| 2852 | # while changes are enqueued |
| 2853 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2854 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2855 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2856 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2857 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2858 | |
| 2859 | # A Depends-On: B |
| 2860 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2861 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2862 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2863 | |
| 2864 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2865 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2866 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2867 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2868 | self.waitUntilSettled() |
| 2869 | self.assertEqual(len(self.builds), 5) |
| 2870 | |
| 2871 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2872 | self.updateConfigLayout( |
| 2873 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2874 | self.sched.reconfigure(self.config) |
| 2875 | self.waitUntilSettled() |
| 2876 | |
| 2877 | # Builds for C aborted, builds for A succeed, |
| 2878 | # and have change B applied ahead |
| 2879 | job_c = self.getJobFromHistory('project1-test1') |
| 2880 | self.assertEqual(job_c.changes, '3,1') |
| 2881 | self.assertEqual(job_c.result, 'ABORTED') |
| 2882 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2883 | self.launch_server.hold_jobs_in_build = False |
| 2884 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2885 | self.waitUntilSettled() |
| 2886 | |
| 2887 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2888 | '2,1 1,1') |
| 2889 | |
| 2890 | self.assertEqual(A.data['status'], 'NEW') |
| 2891 | self.assertEqual(B.data['status'], 'NEW') |
| 2892 | self.assertEqual(C.data['status'], 'NEW') |
| 2893 | self.assertEqual(A.reported, 1) |
| 2894 | self.assertEqual(B.reported, 0) |
| 2895 | self.assertEqual(C.reported, 0) |
| 2896 | |
| 2897 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2898 | self.assertIn('Build succeeded', A.messages[0]) |
| 2899 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2900 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2901 | def test_live_reconfiguration_functions(self): |
| 2902 | "Test live reconfiguration with a custom function" |
| 2903 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2904 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2905 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2906 | A.addApproval('code-review', 2) |
| 2907 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2908 | self.waitUntilSettled() |
| 2909 | |
| 2910 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2911 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2912 | 'debian') |
| 2913 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2914 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2915 | self.updateConfigLayout( |
| 2916 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2917 | self.sched.reconfigure(self.config) |
| 2918 | self.worker.build_history = [] |
| 2919 | |
| 2920 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2921 | B.addApproval('code-review', 2) |
| 2922 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2923 | self.waitUntilSettled() |
| 2924 | |
| 2925 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2926 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2927 | 'wheezy') |
| 2928 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2929 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2930 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2931 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2932 | self.updateConfigLayout( |
| 2933 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2934 | self.sched.reconfigure(self.config) |
| 2935 | |
| 2936 | self.init_repo("org/new-project") |
| 2937 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2938 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2939 | A.addApproval('code-review', 2) |
| 2940 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2941 | self.waitUntilSettled() |
| 2942 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2943 | 'SUCCESS') |
| 2944 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2945 | 'SUCCESS') |
| 2946 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2947 | 'SUCCESS') |
| 2948 | self.assertEqual(A.data['status'], 'MERGED') |
| 2949 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2950 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2951 | @skip("Disabled for early v3 development") |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2952 | def test_repo_deleted(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2953 | self.updateConfigLayout( |
| 2954 | 'tests/fixtures/layout-repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2955 | self.sched.reconfigure(self.config) |
| 2956 | |
| 2957 | self.init_repo("org/delete-project") |
| 2958 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2959 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2960 | A.addApproval('code-review', 2) |
| 2961 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2962 | self.waitUntilSettled() |
| 2963 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2964 | 'SUCCESS') |
| 2965 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2966 | 'SUCCESS') |
| 2967 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2968 | 'SUCCESS') |
| 2969 | self.assertEqual(A.data['status'], 'MERGED') |
| 2970 | self.assertEqual(A.reported, 2) |
| 2971 | |
| 2972 | # Delete org/new-project zuul repo. Should be recloned. |
| 2973 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 2974 | |
| 2975 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2976 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2977 | B.addApproval('code-review', 2) |
| 2978 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2979 | self.waitUntilSettled() |
| 2980 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2981 | 'SUCCESS') |
| 2982 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2983 | 'SUCCESS') |
| 2984 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2985 | 'SUCCESS') |
| 2986 | self.assertEqual(B.data['status'], 'MERGED') |
| 2987 | self.assertEqual(B.reported, 2) |
| 2988 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2989 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2990 | def test_tags(self): |
| 2991 | "Test job tags" |
| 2992 | self.config.set('zuul', 'layout_config', |
| 2993 | 'tests/fixtures/layout-tags.yaml') |
| 2994 | self.sched.reconfigure(self.config) |
| 2995 | |
| 2996 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2997 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2998 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2999 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3000 | self.waitUntilSettled() |
| 3001 | |
| 3002 | results = {'project1-merge': 'extratag merge project1', |
| 3003 | 'project2-merge': 'merge'} |
| 3004 | |
| 3005 | for build in self.history: |
| 3006 | self.assertEqual(results.get(build.name, ''), |
| 3007 | build.parameters.get('BUILD_TAGS')) |
| 3008 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3009 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3010 | def test_timer(self): |
| 3011 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3012 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3013 | self.updateConfigLayout( |
| 3014 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3015 | self.sched.reconfigure(self.config) |
| 3016 | self.registerJobs() |
| 3017 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3018 | # The pipeline triggers every second, so we should have seen |
| 3019 | # several by now. |
| 3020 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3021 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3022 | |
| 3023 | self.assertEqual(len(self.builds), 2) |
| 3024 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3025 | port = self.webapp.server.socket.getsockname()[1] |
| 3026 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3027 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 3028 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3029 | data = f.read() |
| 3030 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3031 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3032 | # Stop queuing timer triggered jobs so that the assertions |
| 3033 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3034 | self.updateConfigLayout( |
| 3035 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3036 | self.sched.reconfigure(self.config) |
| 3037 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3038 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3039 | self.waitUntilSettled() |
| 3040 | |
| 3041 | self.assertEqual(self.getJobFromHistory( |
| 3042 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3043 | self.assertEqual(self.getJobFromHistory( |
| 3044 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3045 | |
| 3046 | data = json.loads(data) |
| 3047 | status_jobs = set() |
| 3048 | for p in data['pipelines']: |
| 3049 | for q in p['change_queues']: |
| 3050 | for head in q['heads']: |
| 3051 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 3052 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3053 | for job in change['jobs']: |
| 3054 | status_jobs.add(job['name']) |
| 3055 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 3056 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3057 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3058 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3059 | def test_idle(self): |
| 3060 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3061 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3062 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3063 | for x in range(1, 3): |
| 3064 | # Test that timer triggers periodic jobs even across |
| 3065 | # layout config reloads. |
| 3066 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3067 | self.updateConfigLayout( |
| 3068 | 'tests/fixtures/layout-idle.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 | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3071 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3072 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3073 | # The pipeline triggers every second, so we should have seen |
| 3074 | # several by now. |
| 3075 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3076 | |
| 3077 | # Stop queuing timer triggered jobs so that the assertions |
| 3078 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3079 | self.updateConfigLayout( |
| 3080 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3081 | self.sched.reconfigure(self.config) |
| 3082 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3083 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3084 | |
| 3085 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3086 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3087 | self.waitUntilSettled() |
| 3088 | self.assertEqual(len(self.builds), 0) |
| 3089 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3090 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3091 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3092 | def test_check_smtp_pool(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3093 | self.updateConfigLayout( |
| 3094 | 'tests/fixtures/layout-smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3095 | self.sched.reconfigure(self.config) |
| 3096 | |
| 3097 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3098 | self.waitUntilSettled() |
| 3099 | |
| 3100 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3101 | self.waitUntilSettled() |
| 3102 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3103 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3104 | |
| 3105 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3106 | # work on the knowledge of what the first message should be as |
| 3107 | # it is only configured to go to SMTP. |
| 3108 | |
| 3109 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3110 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3111 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3112 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3113 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3114 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3115 | |
| 3116 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3117 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3118 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3119 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3120 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3121 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3122 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3123 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3124 | def test_timer_smtp(self): |
| 3125 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3126 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3127 | self.updateConfigLayout( |
| 3128 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3129 | self.sched.reconfigure(self.config) |
| 3130 | self.registerJobs() |
| 3131 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3132 | # The pipeline triggers every second, so we should have seen |
| 3133 | # several by now. |
| 3134 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3135 | self.waitUntilSettled() |
| 3136 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3137 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3138 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3139 | self.waitUntilSettled() |
| 3140 | self.assertEqual(len(self.history), 2) |
| 3141 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3142 | self.assertEqual(self.getJobFromHistory( |
| 3143 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3144 | self.assertEqual(self.getJobFromHistory( |
| 3145 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3146 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3147 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3148 | |
| 3149 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3150 | # work on the knowledge of what the first message should be as |
| 3151 | # it is only configured to go to SMTP. |
| 3152 | |
| 3153 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3154 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3155 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3156 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3157 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3158 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3159 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3160 | # Stop queuing timer triggered jobs and let any that may have |
| 3161 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3162 | self.updateConfigLayout( |
| 3163 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3164 | self.sched.reconfigure(self.config) |
| 3165 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3166 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3167 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3168 | self.waitUntilSettled() |
| 3169 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3170 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3171 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3172 | "Test that the RPC client can enqueue a change" |
| 3173 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3174 | A.addApproval('code-review', 2) |
| 3175 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3176 | |
| 3177 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3178 | self.gearman_server.port) |
| 3179 | r = client.enqueue(pipeline='gate', |
| 3180 | project='org/project', |
| 3181 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3182 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3183 | self.waitUntilSettled() |
| 3184 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3185 | 'SUCCESS') |
| 3186 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3187 | 'SUCCESS') |
| 3188 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3189 | 'SUCCESS') |
| 3190 | self.assertEqual(A.data['status'], 'MERGED') |
| 3191 | self.assertEqual(A.reported, 2) |
| 3192 | self.assertEqual(r, True) |
| 3193 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3194 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3195 | def test_client_enqueue_ref(self): |
| 3196 | "Test that the RPC client can enqueue a ref" |
| 3197 | |
| 3198 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3199 | self.gearman_server.port) |
| 3200 | r = client.enqueue_ref( |
| 3201 | pipeline='post', |
| 3202 | project='org/project', |
| 3203 | trigger='gerrit', |
| 3204 | ref='master', |
| 3205 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3206 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3207 | self.waitUntilSettled() |
| 3208 | job_names = [x.name for x in self.history] |
| 3209 | self.assertEqual(len(self.history), 1) |
| 3210 | self.assertIn('project-post', job_names) |
| 3211 | self.assertEqual(r, True) |
| 3212 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3213 | @skip("Disabled for early v3 development") |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3214 | def test_client_enqueue_negative(self): |
| 3215 | "Test that the RPC client returns errors" |
| 3216 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3217 | self.gearman_server.port) |
| 3218 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3219 | "Invalid project"): |
| 3220 | r = client.enqueue(pipeline='gate', |
| 3221 | project='project-does-not-exist', |
| 3222 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3223 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3224 | client.shutdown() |
| 3225 | self.assertEqual(r, False) |
| 3226 | |
| 3227 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3228 | "Invalid pipeline"): |
| 3229 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 3230 | project='org/project', |
| 3231 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3232 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3233 | client.shutdown() |
| 3234 | self.assertEqual(r, False) |
| 3235 | |
| 3236 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3237 | "Invalid trigger"): |
| 3238 | r = client.enqueue(pipeline='gate', |
| 3239 | project='org/project', |
| 3240 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3241 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3242 | client.shutdown() |
| 3243 | self.assertEqual(r, False) |
| 3244 | |
| 3245 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3246 | "Invalid change"): |
| 3247 | r = client.enqueue(pipeline='gate', |
| 3248 | project='org/project', |
| 3249 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3250 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3251 | client.shutdown() |
| 3252 | self.assertEqual(r, False) |
| 3253 | |
| 3254 | self.waitUntilSettled() |
| 3255 | self.assertEqual(len(self.history), 0) |
| 3256 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3258 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3259 | def test_client_promote(self): |
| 3260 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3261 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3262 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3263 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3264 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3265 | A.addApproval('code-review', 2) |
| 3266 | B.addApproval('code-review', 2) |
| 3267 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3268 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3269 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3270 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3271 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3272 | |
| 3273 | self.waitUntilSettled() |
| 3274 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3275 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3276 | enqueue_times = {} |
| 3277 | for item in items: |
| 3278 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3279 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3280 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3281 | self.gearman_server.port) |
| 3282 | r = client.promote(pipeline='gate', |
| 3283 | change_ids=['2,1', '3,1']) |
| 3284 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3285 | # ensure that enqueue times are durable |
| 3286 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3287 | for item in items: |
| 3288 | self.assertEqual( |
| 3289 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3290 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3291 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3292 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3293 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3294 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3295 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3296 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3297 | self.waitUntilSettled() |
| 3298 | |
| 3299 | self.assertEqual(len(self.builds), 6) |
| 3300 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3301 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3302 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3303 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3304 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3305 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3306 | |
| 3307 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3308 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3309 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3310 | |
| 3311 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3312 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3313 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3314 | |
| 3315 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3316 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3317 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3318 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3319 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3320 | self.waitUntilSettled() |
| 3321 | |
| 3322 | self.assertEqual(A.data['status'], 'MERGED') |
| 3323 | self.assertEqual(A.reported, 2) |
| 3324 | self.assertEqual(B.data['status'], 'MERGED') |
| 3325 | self.assertEqual(B.reported, 2) |
| 3326 | self.assertEqual(C.data['status'], 'MERGED') |
| 3327 | self.assertEqual(C.reported, 2) |
| 3328 | |
| 3329 | client.shutdown() |
| 3330 | self.assertEqual(r, True) |
| 3331 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3332 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3333 | def test_client_promote_dependent(self): |
| 3334 | "Test that the RPC client can promote a dependent change" |
| 3335 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3336 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3337 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3339 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3340 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3341 | |
| 3342 | C.setDependsOn(B, 1) |
| 3343 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3344 | A.addApproval('code-review', 2) |
| 3345 | B.addApproval('code-review', 2) |
| 3346 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3347 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3348 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3349 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3350 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3351 | |
| 3352 | self.waitUntilSettled() |
| 3353 | |
| 3354 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3355 | self.gearman_server.port) |
| 3356 | r = client.promote(pipeline='gate', |
| 3357 | change_ids=['3,1']) |
| 3358 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3359 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3360 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3361 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3362 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3363 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3364 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3365 | self.waitUntilSettled() |
| 3366 | |
| 3367 | self.assertEqual(len(self.builds), 6) |
| 3368 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3369 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3370 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3371 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3372 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3373 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3374 | |
| 3375 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3376 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3377 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3378 | |
| 3379 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3380 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3381 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3382 | |
| 3383 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3384 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3385 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3386 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3387 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3388 | self.waitUntilSettled() |
| 3389 | |
| 3390 | self.assertEqual(A.data['status'], 'MERGED') |
| 3391 | self.assertEqual(A.reported, 2) |
| 3392 | self.assertEqual(B.data['status'], 'MERGED') |
| 3393 | self.assertEqual(B.reported, 2) |
| 3394 | self.assertEqual(C.data['status'], 'MERGED') |
| 3395 | self.assertEqual(C.reported, 2) |
| 3396 | |
| 3397 | client.shutdown() |
| 3398 | self.assertEqual(r, True) |
| 3399 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3400 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3401 | def test_client_promote_negative(self): |
| 3402 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3403 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3404 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3405 | A.addApproval('code-review', 2) |
| 3406 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3407 | self.waitUntilSettled() |
| 3408 | |
| 3409 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3410 | self.gearman_server.port) |
| 3411 | |
| 3412 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3413 | r = client.promote(pipeline='nonexistent', |
| 3414 | change_ids=['2,1', '3,1']) |
| 3415 | client.shutdown() |
| 3416 | self.assertEqual(r, False) |
| 3417 | |
| 3418 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3419 | r = client.promote(pipeline='gate', |
| 3420 | change_ids=['4,1']) |
| 3421 | client.shutdown() |
| 3422 | self.assertEqual(r, False) |
| 3423 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3424 | self.launch_server.hold_jobs_in_build = False |
| 3425 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3426 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3427 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3428 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3429 | def test_queue_rate_limiting(self): |
| 3430 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3431 | self.updateConfigLayout( |
| 3432 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3433 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3434 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3435 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3436 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3437 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3438 | |
| 3439 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3440 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3441 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3442 | A.addApproval('code-review', 2) |
| 3443 | B.addApproval('code-review', 2) |
| 3444 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3445 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3446 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3447 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3448 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3449 | self.waitUntilSettled() |
| 3450 | |
| 3451 | # Only A and B will have their merge jobs queued because |
| 3452 | # window is 2. |
| 3453 | self.assertEqual(len(self.builds), 2) |
| 3454 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3455 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3456 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3457 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3458 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3459 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3460 | self.waitUntilSettled() |
| 3461 | |
| 3462 | # Only A and B will have their test jobs queued because |
| 3463 | # window is 2. |
| 3464 | self.assertEqual(len(self.builds), 4) |
| 3465 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3466 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3467 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3468 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3469 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3470 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3471 | self.waitUntilSettled() |
| 3472 | |
| 3473 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3474 | # A failed so window is reduced by 1 to 1. |
| 3475 | self.assertEqual(queue.window, 1) |
| 3476 | self.assertEqual(queue.window_floor, 1) |
| 3477 | self.assertEqual(A.data['status'], 'NEW') |
| 3478 | |
| 3479 | # Gate is reset and only B's merge job is queued because |
| 3480 | # window shrunk to 1. |
| 3481 | self.assertEqual(len(self.builds), 1) |
| 3482 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3483 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3484 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | self.waitUntilSettled() |
| 3486 | |
| 3487 | # Only B's test jobs are queued because window is still 1. |
| 3488 | self.assertEqual(len(self.builds), 2) |
| 3489 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3490 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3491 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3492 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3493 | self.waitUntilSettled() |
| 3494 | |
| 3495 | # B was successfully merged so window is increased to 2. |
| 3496 | self.assertEqual(queue.window, 2) |
| 3497 | self.assertEqual(queue.window_floor, 1) |
| 3498 | self.assertEqual(B.data['status'], 'MERGED') |
| 3499 | |
| 3500 | # Only C is left and its merge job is queued. |
| 3501 | self.assertEqual(len(self.builds), 1) |
| 3502 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3503 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3504 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3505 | self.waitUntilSettled() |
| 3506 | |
| 3507 | # After successful merge job the test jobs for C are queued. |
| 3508 | self.assertEqual(len(self.builds), 2) |
| 3509 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3510 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3511 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3512 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3513 | self.waitUntilSettled() |
| 3514 | |
| 3515 | # C successfully merged so window is bumped to 3. |
| 3516 | self.assertEqual(queue.window, 3) |
| 3517 | self.assertEqual(queue.window_floor, 1) |
| 3518 | self.assertEqual(C.data['status'], 'MERGED') |
| 3519 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3520 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3521 | def test_queue_rate_limiting_dependent(self): |
| 3522 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3523 | self.updateConfigLayout( |
| 3524 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3525 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3526 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3527 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3528 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3529 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3530 | |
| 3531 | B.setDependsOn(A, 1) |
| 3532 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3533 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3534 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3535 | A.addApproval('code-review', 2) |
| 3536 | B.addApproval('code-review', 2) |
| 3537 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3538 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3539 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3540 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3541 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3542 | self.waitUntilSettled() |
| 3543 | |
| 3544 | # Only A and B will have their merge jobs queued because |
| 3545 | # window is 2. |
| 3546 | self.assertEqual(len(self.builds), 2) |
| 3547 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3548 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3549 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3550 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3551 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3552 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3553 | self.waitUntilSettled() |
| 3554 | |
| 3555 | # Only A and B will have their test jobs queued because |
| 3556 | # window is 2. |
| 3557 | self.assertEqual(len(self.builds), 4) |
| 3558 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3559 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3560 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3561 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3562 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3563 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3564 | self.waitUntilSettled() |
| 3565 | |
| 3566 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3567 | # A failed so window is reduced by 1 to 1. |
| 3568 | self.assertEqual(queue.window, 1) |
| 3569 | self.assertEqual(queue.window_floor, 1) |
| 3570 | self.assertEqual(A.data['status'], 'NEW') |
| 3571 | self.assertEqual(B.data['status'], 'NEW') |
| 3572 | |
| 3573 | # Gate is reset and only C's merge job is queued because |
| 3574 | # window shrunk to 1 and A and B were dequeued. |
| 3575 | self.assertEqual(len(self.builds), 1) |
| 3576 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3577 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3578 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3579 | self.waitUntilSettled() |
| 3580 | |
| 3581 | # Only C's test jobs are queued because window is still 1. |
| 3582 | self.assertEqual(len(self.builds), 2) |
| 3583 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3584 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3585 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3586 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3587 | self.waitUntilSettled() |
| 3588 | |
| 3589 | # C was successfully merged so window is increased to 2. |
| 3590 | self.assertEqual(queue.window, 2) |
| 3591 | self.assertEqual(queue.window_floor, 1) |
| 3592 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3593 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3594 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3595 | def test_worker_update_metadata(self): |
| 3596 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3597 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3598 | |
| 3599 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3600 | A.addApproval('code-review', 2) |
| 3601 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3602 | self.waitUntilSettled() |
| 3603 | |
| 3604 | self.assertEqual(len(self.launcher.builds), 1) |
| 3605 | |
| 3606 | self.log.debug('Current builds:') |
| 3607 | self.log.debug(self.launcher.builds) |
| 3608 | |
| 3609 | start = time.time() |
| 3610 | while True: |
| 3611 | if time.time() - start > 10: |
| 3612 | raise Exception("Timeout waiting for gearman server to report " |
| 3613 | + "back to the client") |
| 3614 | build = self.launcher.builds.values()[0] |
| 3615 | if build.worker.name == "My Worker": |
| 3616 | break |
| 3617 | else: |
| 3618 | time.sleep(0) |
| 3619 | |
| 3620 | self.log.debug(build) |
| 3621 | self.assertEqual("My Worker", build.worker.name) |
| 3622 | self.assertEqual("localhost", build.worker.hostname) |
| 3623 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3624 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3625 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3626 | self.assertEqual("v1.1", build.worker.version) |
| 3627 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3628 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3629 | self.launch_server.hold_jobs_in_build = False |
| 3630 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3631 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3632 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3633 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3634 | def test_footer_message(self): |
| 3635 | "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] | 3636 | self.updateConfigLayout( |
| 3637 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3638 | self.sched.reconfigure(self.config) |
| 3639 | self.registerJobs() |
| 3640 | |
| 3641 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3642 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3643 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3644 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3645 | self.waitUntilSettled() |
| 3646 | |
| 3647 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3648 | B.addApproval('code-review', 2) |
| 3649 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3650 | self.waitUntilSettled() |
| 3651 | |
| 3652 | self.assertEqual(2, len(self.smtp_messages)) |
| 3653 | |
| 3654 | failure_body = """\ |
| 3655 | Build failed. For information on how to proceed, see \ |
| 3656 | http://wiki.example.org/Test_Failures |
| 3657 | |
| 3658 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3659 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3660 | |
| 3661 | For CI problems and help debugging, contact ci@example.org""" |
| 3662 | |
| 3663 | success_body = """\ |
| 3664 | Build succeeded. |
| 3665 | |
| 3666 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3667 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3668 | |
| 3669 | For CI problems and help debugging, contact ci@example.org""" |
| 3670 | |
| 3671 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3672 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3673 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3674 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3675 | def test_merge_failure_reporters(self): |
| 3676 | """Check that the config is set up correctly""" |
| 3677 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3678 | self.updateConfigLayout( |
| 3679 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3680 | self.sched.reconfigure(self.config) |
| 3681 | self.registerJobs() |
| 3682 | |
| 3683 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3684 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3685 | "dependencies was unable to be automatically merged with the " |
| 3686 | "current state of its repository. Please rebase the change and " |
| 3687 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3688 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3689 | self.assertEqual( |
| 3690 | "The merge failed! For more information...", |
| 3691 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3692 | |
| 3693 | self.assertEqual( |
| 3694 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3695 | self.assertEqual( |
| 3696 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3697 | |
| 3698 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3699 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3700 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3701 | |
| 3702 | self.assertTrue( |
| 3703 | ( |
| 3704 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3705 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3706 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3707 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3708 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3709 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3710 | ) or ( |
| 3711 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3712 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3713 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3714 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3715 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3716 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3717 | ) |
| 3718 | ) |
| 3719 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3720 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3721 | def test_merge_failure_reports(self): |
| 3722 | """Check that when a change fails to merge the correct message is sent |
| 3723 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3724 | self.updateConfigLayout( |
| 3725 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3726 | self.sched.reconfigure(self.config) |
| 3727 | self.registerJobs() |
| 3728 | |
| 3729 | # Check a test failure isn't reported to SMTP |
| 3730 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3731 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3732 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3733 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3734 | self.waitUntilSettled() |
| 3735 | |
| 3736 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3737 | self.assertEqual(0, len(self.smtp_messages)) |
| 3738 | |
| 3739 | # Check a merge failure is reported to SMTP |
| 3740 | # B should be merged, but C will conflict with B |
| 3741 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3742 | B.addPatchset(['conflict']) |
| 3743 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3744 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3745 | B.addApproval('code-review', 2) |
| 3746 | C.addApproval('code-review', 2) |
| 3747 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3748 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3749 | self.waitUntilSettled() |
| 3750 | |
| 3751 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3752 | self.assertEqual(1, len(self.smtp_messages)) |
| 3753 | self.assertEqual('The merge failed! For more information...', |
| 3754 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3755 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3756 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3757 | def test_default_merge_failure_reports(self): |
| 3758 | """Check that the default merge failure reports are correct.""" |
| 3759 | |
| 3760 | # A should report success, B should report merge failure. |
| 3761 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3762 | A.addPatchset(['conflict']) |
| 3763 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3764 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3765 | A.addApproval('code-review', 2) |
| 3766 | B.addApproval('code-review', 2) |
| 3767 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3768 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3769 | self.waitUntilSettled() |
| 3770 | |
| 3771 | self.assertEqual(3, len(self.history)) # A jobs |
| 3772 | self.assertEqual(A.reported, 2) |
| 3773 | self.assertEqual(B.reported, 2) |
| 3774 | self.assertEqual(A.data['status'], 'MERGED') |
| 3775 | self.assertEqual(B.data['status'], 'NEW') |
| 3776 | self.assertIn('Build succeeded', A.messages[1]) |
| 3777 | self.assertIn('Merge Failed', B.messages[1]) |
| 3778 | self.assertIn('automatically merged', B.messages[1]) |
| 3779 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3780 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3781 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3782 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3783 | def test_swift_instructions(self): |
| 3784 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3785 | self.updateConfigLayout( |
| 3786 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3787 | self.sched.reconfigure(self.config) |
| 3788 | self.registerJobs() |
| 3789 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3790 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3791 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3792 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3793 | A.addApproval('code-review', 2) |
| 3794 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3795 | self.waitUntilSettled() |
| 3796 | |
| 3797 | self.assertEqual( |
| 3798 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3799 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3800 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3801 | self.assertEqual(5, |
| 3802 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3803 | split('\n'))) |
| 3804 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3805 | |
| 3806 | self.assertEqual( |
| 3807 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3808 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3809 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3810 | self.assertEqual(5, |
| 3811 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3812 | split('\n'))) |
| 3813 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3814 | |
| 3815 | self.assertEqual( |
| 3816 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3817 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3818 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3819 | self.assertEqual(5, |
| 3820 | len(self.builds[1]. |
| 3821 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3822 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3823 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3824 | self.launch_server.hold_jobs_in_build = False |
| 3825 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3826 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3827 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3828 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3829 | def test_client_get_running_jobs(self): |
| 3830 | "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] | 3831 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3832 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3833 | A.addApproval('code-review', 2) |
| 3834 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3835 | self.waitUntilSettled() |
| 3836 | |
| 3837 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3838 | self.gearman_server.port) |
| 3839 | |
| 3840 | # Wait for gearman server to send the initial workData back to zuul |
| 3841 | start = time.time() |
| 3842 | while True: |
| 3843 | if time.time() - start > 10: |
| 3844 | raise Exception("Timeout waiting for gearman server to report " |
| 3845 | + "back to the client") |
| 3846 | build = self.launcher.builds.values()[0] |
| 3847 | if build.worker.name == "My Worker": |
| 3848 | break |
| 3849 | else: |
| 3850 | time.sleep(0) |
| 3851 | |
| 3852 | running_items = client.get_running_jobs() |
| 3853 | |
| 3854 | self.assertEqual(1, len(running_items)) |
| 3855 | running_item = running_items[0] |
| 3856 | self.assertEqual([], running_item['failing_reasons']) |
| 3857 | self.assertEqual([], running_item['items_behind']) |
| 3858 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3859 | self.assertEqual(None, running_item['item_ahead']) |
| 3860 | self.assertEqual('org/project', running_item['project']) |
| 3861 | self.assertEqual(None, running_item['remaining_time']) |
| 3862 | self.assertEqual(True, running_item['active']) |
| 3863 | self.assertEqual('1,1', running_item['id']) |
| 3864 | |
| 3865 | self.assertEqual(3, len(running_item['jobs'])) |
| 3866 | for job in running_item['jobs']: |
| 3867 | if job['name'] == 'project-merge': |
| 3868 | self.assertEqual('project-merge', job['name']) |
| 3869 | self.assertEqual('gate', job['pipeline']) |
| 3870 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3871 | self.assertEqual('https://server/job/project-merge/0/', |
| 3872 | job['url']) |
| 3873 | self.assertEqual(7, len(job['worker'])) |
| 3874 | self.assertEqual(False, job['canceled']) |
| 3875 | self.assertEqual(True, job['voting']) |
| 3876 | self.assertEqual(None, job['result']) |
| 3877 | self.assertEqual('gate', job['pipeline']) |
| 3878 | break |
| 3879 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3880 | self.launch_server.hold_jobs_in_build = False |
| 3881 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3882 | self.waitUntilSettled() |
| 3883 | |
| 3884 | running_items = client.get_running_jobs() |
| 3885 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3886 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3887 | @skip("Disabled for early v3 development") |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3888 | def test_nonvoting_pipeline(self): |
| 3889 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3890 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3891 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3892 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3893 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3894 | self.waitUntilSettled() |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3895 | self.assertEqual( |
| 3896 | self.getJobFromHistory('experimental-project-test').result, |
| 3897 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3898 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3899 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3900 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3901 | def test_crd_gate(self): |
| 3902 | "Test cross-repo dependencies" |
| 3903 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3904 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3905 | A.addApproval('code-review', 2) |
| 3906 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3907 | |
| 3908 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3909 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3910 | AM2.setMerged() |
| 3911 | AM1.setMerged() |
| 3912 | |
| 3913 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3914 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3915 | BM2.setMerged() |
| 3916 | BM1.setMerged() |
| 3917 | |
| 3918 | # A -> AM1 -> AM2 |
| 3919 | # B -> BM1 -> BM2 |
| 3920 | # A Depends-On: B |
| 3921 | # M2 is here to make sure it is never queried. If it is, it |
| 3922 | # means zuul is walking down the entire history of merged |
| 3923 | # changes. |
| 3924 | |
| 3925 | B.setDependsOn(BM1, 1) |
| 3926 | BM1.setDependsOn(BM2, 1) |
| 3927 | |
| 3928 | A.setDependsOn(AM1, 1) |
| 3929 | AM1.setDependsOn(AM2, 1) |
| 3930 | |
| 3931 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3932 | A.subject, B.data['id']) |
| 3933 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3934 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3935 | self.waitUntilSettled() |
| 3936 | |
| 3937 | self.assertEqual(A.data['status'], 'NEW') |
| 3938 | self.assertEqual(B.data['status'], 'NEW') |
| 3939 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3940 | for connection in self.connections.values(): |
| 3941 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3942 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3943 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3944 | B.addApproval('approved', 1) |
| 3945 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3946 | self.waitUntilSettled() |
| 3947 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3948 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3949 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3950 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3951 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3952 | self.launch_server.hold_jobs_in_build = False |
| 3953 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3954 | self.waitUntilSettled() |
| 3955 | |
| 3956 | self.assertEqual(AM2.queried, 0) |
| 3957 | self.assertEqual(BM2.queried, 0) |
| 3958 | self.assertEqual(A.data['status'], 'MERGED') |
| 3959 | self.assertEqual(B.data['status'], 'MERGED') |
| 3960 | self.assertEqual(A.reported, 2) |
| 3961 | self.assertEqual(B.reported, 2) |
| 3962 | |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3963 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 3964 | '2,1 1,1') |
| 3965 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3966 | @skip("Disabled for early v3 development") |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3967 | def test_crd_branch(self): |
| 3968 | "Test cross-repo dependencies in multiple branches" |
| 3969 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3970 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3971 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3972 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3973 | A.addApproval('code-review', 2) |
| 3974 | B.addApproval('code-review', 2) |
| 3975 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3976 | |
| 3977 | # A Depends-On: B+C |
| 3978 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3979 | A.subject, B.data['id']) |
| 3980 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3981 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3982 | B.addApproval('approved', 1) |
| 3983 | C.addApproval('approved', 1) |
| 3984 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3985 | self.waitUntilSettled() |
| 3986 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3987 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3988 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3989 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3990 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3991 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3992 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3993 | self.launch_server.hold_jobs_in_build = False |
| 3994 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3995 | self.waitUntilSettled() |
| 3996 | |
| 3997 | self.assertEqual(A.data['status'], 'MERGED') |
| 3998 | self.assertEqual(B.data['status'], 'MERGED') |
| 3999 | self.assertEqual(C.data['status'], 'MERGED') |
| 4000 | self.assertEqual(A.reported, 2) |
| 4001 | self.assertEqual(B.reported, 2) |
| 4002 | self.assertEqual(C.reported, 2) |
| 4003 | |
| 4004 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4005 | '2,1 3,1 1,1') |
| 4006 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4007 | @skip("Disabled for early v3 development") |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4008 | def test_crd_multiline(self): |
| 4009 | "Test multiple depends-on lines in commit" |
| 4010 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4011 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4012 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4013 | A.addApproval('code-review', 2) |
| 4014 | B.addApproval('code-review', 2) |
| 4015 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4016 | |
| 4017 | # A Depends-On: B+C |
| 4018 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 4019 | A.subject, B.data['id'], C.data['id']) |
| 4020 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4021 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4022 | B.addApproval('approved', 1) |
| 4023 | C.addApproval('approved', 1) |
| 4024 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4025 | self.waitUntilSettled() |
| 4026 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4027 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4028 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4029 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4030 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4031 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4032 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4033 | self.launch_server.hold_jobs_in_build = False |
| 4034 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4035 | self.waitUntilSettled() |
| 4036 | |
| 4037 | self.assertEqual(A.data['status'], 'MERGED') |
| 4038 | self.assertEqual(B.data['status'], 'MERGED') |
| 4039 | self.assertEqual(C.data['status'], 'MERGED') |
| 4040 | self.assertEqual(A.reported, 2) |
| 4041 | self.assertEqual(B.reported, 2) |
| 4042 | self.assertEqual(C.reported, 2) |
| 4043 | |
| 4044 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4045 | '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4046 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4047 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4048 | def test_crd_unshared_gate(self): |
| 4049 | "Test cross-repo dependencies in unshared gate queues" |
| 4050 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4051 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4052 | A.addApproval('code-review', 2) |
| 4053 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4054 | |
| 4055 | # A Depends-On: B |
| 4056 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4057 | A.subject, B.data['id']) |
| 4058 | |
| 4059 | # A and B do not share a queue, make sure that A is unable to |
| 4060 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4061 | B.addApproval('approved', 1) |
| 4062 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4063 | self.waitUntilSettled() |
| 4064 | |
| 4065 | self.assertEqual(A.data['status'], 'NEW') |
| 4066 | self.assertEqual(B.data['status'], 'NEW') |
| 4067 | self.assertEqual(A.reported, 0) |
| 4068 | self.assertEqual(B.reported, 0) |
| 4069 | self.assertEqual(len(self.history), 0) |
| 4070 | |
| 4071 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4072 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4073 | self.waitUntilSettled() |
| 4074 | |
| 4075 | self.assertEqual(B.data['status'], 'MERGED') |
| 4076 | self.assertEqual(B.reported, 2) |
| 4077 | |
| 4078 | # Now that B is merged, A should be able to be enqueued and |
| 4079 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4080 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4081 | self.waitUntilSettled() |
| 4082 | |
| 4083 | self.assertEqual(A.data['status'], 'MERGED') |
| 4084 | self.assertEqual(A.reported, 2) |
| 4085 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4086 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4087 | def test_crd_gate_reverse(self): |
| 4088 | "Test reverse cross-repo dependencies" |
| 4089 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4090 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4091 | A.addApproval('code-review', 2) |
| 4092 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4093 | |
| 4094 | # A Depends-On: B |
| 4095 | |
| 4096 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4097 | A.subject, B.data['id']) |
| 4098 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4099 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4100 | self.waitUntilSettled() |
| 4101 | |
| 4102 | self.assertEqual(A.data['status'], 'NEW') |
| 4103 | self.assertEqual(B.data['status'], 'NEW') |
| 4104 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4105 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4106 | A.addApproval('approved', 1) |
| 4107 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4108 | self.waitUntilSettled() |
| 4109 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4110 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4111 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4112 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4113 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4114 | self.launch_server.hold_jobs_in_build = False |
| 4115 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4116 | self.waitUntilSettled() |
| 4117 | |
| 4118 | self.assertEqual(A.data['status'], 'MERGED') |
| 4119 | self.assertEqual(B.data['status'], 'MERGED') |
| 4120 | self.assertEqual(A.reported, 2) |
| 4121 | self.assertEqual(B.reported, 2) |
| 4122 | |
| 4123 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4124 | '2,1 1,1') |
| 4125 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4126 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4127 | def test_crd_cycle(self): |
| 4128 | "Test cross-repo dependency cycles" |
| 4129 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4130 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4131 | A.addApproval('code-review', 2) |
| 4132 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4133 | |
| 4134 | # A -> B -> A (via commit-depends) |
| 4135 | |
| 4136 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4137 | A.subject, B.data['id']) |
| 4138 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4139 | B.subject, A.data['id']) |
| 4140 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4141 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4142 | self.waitUntilSettled() |
| 4143 | |
| 4144 | self.assertEqual(A.reported, 0) |
| 4145 | self.assertEqual(B.reported, 0) |
| 4146 | self.assertEqual(A.data['status'], 'NEW') |
| 4147 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4148 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4149 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4150 | def test_crd_gate_unknown(self): |
| 4151 | "Test unknown projects in dependent pipeline" |
| 4152 | self.init_repo("org/unknown") |
| 4153 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4154 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4155 | A.addApproval('code-review', 2) |
| 4156 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4157 | |
| 4158 | # A Depends-On: B |
| 4159 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4160 | A.subject, B.data['id']) |
| 4161 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4162 | B.addApproval('approved', 1) |
| 4163 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4164 | self.waitUntilSettled() |
| 4165 | |
| 4166 | # Unknown projects cannot share a queue with any other |
| 4167 | # since they don't have common jobs with any other (they have no jobs). |
| 4168 | # Changes which depend on unknown project changes |
| 4169 | # should not be processed in dependent pipeline |
| 4170 | self.assertEqual(A.data['status'], 'NEW') |
| 4171 | self.assertEqual(B.data['status'], 'NEW') |
| 4172 | self.assertEqual(A.reported, 0) |
| 4173 | self.assertEqual(B.reported, 0) |
| 4174 | self.assertEqual(len(self.history), 0) |
| 4175 | |
| 4176 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4177 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4178 | B.setMerged() |
| 4179 | self.waitUntilSettled() |
| 4180 | self.assertEqual(len(self.history), 0) |
| 4181 | |
| 4182 | # Now that B is merged, A should be able to be enqueued and |
| 4183 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4184 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4185 | self.waitUntilSettled() |
| 4186 | |
| 4187 | self.assertEqual(A.data['status'], 'MERGED') |
| 4188 | self.assertEqual(A.reported, 2) |
| 4189 | self.assertEqual(B.data['status'], 'MERGED') |
| 4190 | self.assertEqual(B.reported, 0) |
| 4191 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4192 | @skip("Disabled for early v3 development") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4193 | def test_crd_check(self): |
| 4194 | "Test cross-repo dependencies in independent pipelines" |
| 4195 | |
| 4196 | self.gearman_server.hold_jobs_in_queue = True |
| 4197 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4198 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4199 | |
| 4200 | # A Depends-On: B |
| 4201 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4202 | A.subject, B.data['id']) |
| 4203 | |
| 4204 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4205 | self.waitUntilSettled() |
| 4206 | |
| 4207 | queue = self.gearman_server.getQueue() |
| 4208 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4209 | self.gearman_server.hold_jobs_in_queue = False |
| 4210 | self.gearman_server.release() |
| 4211 | self.waitUntilSettled() |
| 4212 | |
| 4213 | path = os.path.join(self.git_root, "org/project1") |
| 4214 | repo = git.Repo(path) |
| 4215 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4216 | repo_messages.reverse() |
| 4217 | correct_messages = ['initial commit', 'A-1'] |
| 4218 | self.assertEqual(repo_messages, correct_messages) |
| 4219 | |
| 4220 | path = os.path.join(self.git_root, "org/project2") |
| 4221 | repo = git.Repo(path) |
| 4222 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4223 | repo_messages.reverse() |
| 4224 | correct_messages = ['initial commit', 'B-1'] |
| 4225 | self.assertEqual(repo_messages, correct_messages) |
| 4226 | |
| 4227 | self.assertEqual(A.data['status'], 'NEW') |
| 4228 | self.assertEqual(B.data['status'], 'NEW') |
| 4229 | self.assertEqual(A.reported, 1) |
| 4230 | self.assertEqual(B.reported, 0) |
| 4231 | |
| 4232 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 4233 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4234 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4235 | @skip("Disabled for early v3 development") |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4236 | def test_crd_check_git_depends(self): |
| 4237 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4238 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4239 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4240 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4241 | |
| 4242 | # Add two git-dependent changes and make sure they both report |
| 4243 | # success. |
| 4244 | B.setDependsOn(A, 1) |
| 4245 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4246 | self.waitUntilSettled() |
| 4247 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4248 | self.waitUntilSettled() |
| 4249 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4250 | self.orderedRelease() |
| 4251 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4252 | self.waitUntilSettled() |
| 4253 | |
| 4254 | self.assertEqual(A.data['status'], 'NEW') |
| 4255 | self.assertEqual(B.data['status'], 'NEW') |
| 4256 | self.assertEqual(A.reported, 1) |
| 4257 | self.assertEqual(B.reported, 1) |
| 4258 | |
| 4259 | self.assertEqual(self.history[0].changes, '1,1') |
| 4260 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
| 4261 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 4262 | |
| 4263 | self.assertIn('Build succeeded', A.messages[0]) |
| 4264 | self.assertIn('Build succeeded', B.messages[0]) |
| 4265 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4266 | @skip("Disabled for early v3 development") |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4267 | def test_crd_check_duplicate(self): |
| 4268 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4269 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4270 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4271 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4272 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4273 | |
| 4274 | # Add two git-dependent changes... |
| 4275 | B.setDependsOn(A, 1) |
| 4276 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4277 | self.waitUntilSettled() |
| 4278 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4279 | |
| 4280 | # ...make sure the live one is not duplicated... |
| 4281 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4282 | self.waitUntilSettled() |
| 4283 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4284 | |
| 4285 | # ...but the non-live one is able to be. |
| 4286 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4287 | self.waitUntilSettled() |
| 4288 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4289 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4290 | # Release jobs in order to avoid races with change A jobs |
| 4291 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4292 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4293 | self.launch_server.hold_jobs_in_build = False |
| 4294 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4295 | self.waitUntilSettled() |
| 4296 | |
| 4297 | self.assertEqual(A.data['status'], 'NEW') |
| 4298 | self.assertEqual(B.data['status'], 'NEW') |
| 4299 | self.assertEqual(A.reported, 1) |
| 4300 | self.assertEqual(B.reported, 1) |
| 4301 | |
| 4302 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4303 | self.assertEqual(self.history[1].changes, '1,1') |
| 4304 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 4305 | |
| 4306 | self.assertIn('Build succeeded', A.messages[0]) |
| 4307 | self.assertIn('Build succeeded', B.messages[0]) |
| 4308 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4309 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4310 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4311 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4312 | |
| 4313 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4314 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4315 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4316 | |
| 4317 | # A Depends-On: B |
| 4318 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4319 | A.subject, B.data['id']) |
| 4320 | |
| 4321 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4322 | self.waitUntilSettled() |
| 4323 | |
| 4324 | self.sched.reconfigure(self.config) |
| 4325 | |
| 4326 | # Make sure the items still share a change queue, and the |
| 4327 | # first one is not live. |
| 4328 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1) |
| 4329 | queue = self.sched.layout.pipelines['check'].queues[0] |
| 4330 | first_item = queue.queue[0] |
| 4331 | for item in queue.queue: |
| 4332 | self.assertEqual(item.queue, first_item.queue) |
| 4333 | self.assertFalse(first_item.live) |
| 4334 | self.assertTrue(queue.queue[1].live) |
| 4335 | |
| 4336 | self.gearman_server.hold_jobs_in_queue = False |
| 4337 | self.gearman_server.release() |
| 4338 | self.waitUntilSettled() |
| 4339 | |
| 4340 | self.assertEqual(A.data['status'], 'NEW') |
| 4341 | self.assertEqual(B.data['status'], 'NEW') |
| 4342 | self.assertEqual(A.reported, 1) |
| 4343 | self.assertEqual(B.reported, 0) |
| 4344 | |
| 4345 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 4346 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4347 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4348 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4349 | def test_crd_check_reconfiguration(self): |
| 4350 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4351 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4352 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4353 | def test_crd_undefined_project(self): |
| 4354 | """Test that undefined projects in dependencies are handled for |
| 4355 | independent pipelines""" |
| 4356 | # It's a hack for fake gerrit, |
| 4357 | # as it implies repo creation upon the creation of any change |
| 4358 | self.init_repo("org/unknown") |
| 4359 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4360 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4361 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4362 | def test_crd_check_ignore_dependencies(self): |
| 4363 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4364 | self.updateConfigLayout( |
| 4365 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4366 | self.sched.reconfigure(self.config) |
| 4367 | self.registerJobs() |
| 4368 | |
| 4369 | self.gearman_server.hold_jobs_in_queue = True |
| 4370 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4371 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4372 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4373 | |
| 4374 | # A Depends-On: B |
| 4375 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4376 | A.subject, B.data['id']) |
| 4377 | # C git-depends on B |
| 4378 | C.setDependsOn(B, 1) |
| 4379 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4380 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4381 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4382 | self.waitUntilSettled() |
| 4383 | |
| 4384 | # Make sure none of the items share a change queue, and all |
| 4385 | # are live. |
| 4386 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4387 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4388 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4389 | for item in check_pipeline.getAllItems(): |
| 4390 | self.assertTrue(item.live) |
| 4391 | |
| 4392 | self.gearman_server.hold_jobs_in_queue = False |
| 4393 | self.gearman_server.release() |
| 4394 | self.waitUntilSettled() |
| 4395 | |
| 4396 | self.assertEqual(A.data['status'], 'NEW') |
| 4397 | self.assertEqual(B.data['status'], 'NEW') |
| 4398 | self.assertEqual(C.data['status'], 'NEW') |
| 4399 | self.assertEqual(A.reported, 1) |
| 4400 | self.assertEqual(B.reported, 1) |
| 4401 | self.assertEqual(C.reported, 1) |
| 4402 | |
| 4403 | # Each job should have tested exactly one change |
| 4404 | for job in self.history: |
| 4405 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4406 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4407 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4408 | def test_crd_check_transitive(self): |
| 4409 | "Test transitive cross-repo dependencies" |
| 4410 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4411 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4412 | # and C,2 (not C,1 which would indicate stale data in the |
| 4413 | # cache for B). |
| 4414 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4415 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4416 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4417 | |
| 4418 | # A Depends-On: B |
| 4419 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4420 | A.subject, B.data['id']) |
| 4421 | |
| 4422 | # B Depends-On: C |
| 4423 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4424 | B.subject, C.data['id']) |
| 4425 | |
| 4426 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4427 | self.waitUntilSettled() |
| 4428 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4429 | |
| 4430 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4431 | self.waitUntilSettled() |
| 4432 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4433 | |
| 4434 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4435 | self.waitUntilSettled() |
| 4436 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4437 | |
| 4438 | C.addPatchset() |
| 4439 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4440 | self.waitUntilSettled() |
| 4441 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4442 | |
| 4443 | A.addPatchset() |
| 4444 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4445 | self.waitUntilSettled() |
| 4446 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4447 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4448 | @skip("Disabled for early v3 development") |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4449 | def test_crd_check_unknown(self): |
| 4450 | "Test unknown projects in independent pipeline" |
| 4451 | self.init_repo("org/unknown") |
| 4452 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4453 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4454 | # A Depends-On: B |
| 4455 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4456 | A.subject, B.data['id']) |
| 4457 | |
| 4458 | # Make sure zuul has seen an event on B. |
| 4459 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4460 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4461 | self.waitUntilSettled() |
| 4462 | |
| 4463 | self.assertEqual(A.data['status'], 'NEW') |
| 4464 | self.assertEqual(A.reported, 1) |
| 4465 | self.assertEqual(B.data['status'], 'NEW') |
| 4466 | self.assertEqual(B.reported, 0) |
| 4467 | |
Joshua Hesketh | efeeb6d | 2016-09-20 14:42:37 +0200 | [diff] [blame] | 4468 | @skip("Disabled for early v3 development") |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4469 | def test_crd_cycle_join(self): |
| 4470 | "Test an updated change creates a cycle" |
| 4471 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4472 | |
| 4473 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4474 | self.waitUntilSettled() |
| 4475 | |
| 4476 | # Create B->A |
| 4477 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4478 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4479 | B.subject, A.data['id']) |
| 4480 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4481 | self.waitUntilSettled() |
| 4482 | |
| 4483 | # Update A to add A->B (a cycle). |
| 4484 | A.addPatchset() |
| 4485 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4486 | A.subject, B.data['id']) |
| 4487 | # Normally we would submit the patchset-created event for |
| 4488 | # processing here, however, we have no way of noting whether |
| 4489 | # the dependency cycle detection correctly raised an |
| 4490 | # exception, so instead, we reach into the source driver and |
| 4491 | # call the method that would ultimately be called by the event |
| 4492 | # processing. |
| 4493 | |
| 4494 | source = self.sched.layout.pipelines['gate'].source |
| 4495 | with testtools.ExpectedException( |
| 4496 | Exception, "Dependency cycle detected"): |
| 4497 | source._getChange(u'1', u'2', True) |
| 4498 | self.log.debug("Got expected dependency cycle exception") |
| 4499 | |
| 4500 | # Now if we update B to remove the depends-on, everything |
| 4501 | # should be okay. B; A->B |
| 4502 | |
| 4503 | B.addPatchset() |
| 4504 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
| 4505 | source._getChange(u'1', u'2', True) |
| 4506 | source._getChange(u'2', u'2', True) |
| 4507 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4508 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4509 | def test_disable_at(self): |
| 4510 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4511 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4512 | self.updateConfigLayout( |
| 4513 | 'tests/fixtures/layout-disable-at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4514 | self.sched.reconfigure(self.config) |
| 4515 | |
| 4516 | self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at) |
| 4517 | self.assertEqual( |
| 4518 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4519 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4520 | |
| 4521 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4522 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4523 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4524 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4525 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4526 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4527 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4528 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4529 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4530 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4531 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4532 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4533 | self.launch_server.failJob('project-test1', A) |
| 4534 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4535 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4536 | self.launch_server.failJob('project-test1', D) |
| 4537 | self.launch_server.failJob('project-test1', E) |
| 4538 | self.launch_server.failJob('project-test1', F) |
| 4539 | self.launch_server.failJob('project-test1', G) |
| 4540 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4541 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4542 | self.launch_server.failJob('project-test1', J) |
| 4543 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4544 | |
| 4545 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4546 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4547 | self.waitUntilSettled() |
| 4548 | |
| 4549 | self.assertEqual( |
| 4550 | 2, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4551 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4552 | |
| 4553 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4554 | self.waitUntilSettled() |
| 4555 | |
| 4556 | self.assertEqual( |
| 4557 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4558 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4559 | |
| 4560 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4561 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4562 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4563 | self.waitUntilSettled() |
| 4564 | |
| 4565 | # We should be disabled now |
| 4566 | self.assertEqual( |
| 4567 | 3, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4568 | self.assertTrue(self.sched.layout.pipelines['check']._disabled) |
| 4569 | |
| 4570 | # We need to wait between each of these patches to make sure the |
| 4571 | # smtp messages come back in an expected order |
| 4572 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4573 | self.waitUntilSettled() |
| 4574 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4575 | self.waitUntilSettled() |
| 4576 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4577 | self.waitUntilSettled() |
| 4578 | |
| 4579 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4580 | # leaving a message on each change |
| 4581 | self.assertEqual(1, len(A.messages)) |
| 4582 | self.assertIn('Build failed.', A.messages[0]) |
| 4583 | self.assertEqual(1, len(B.messages)) |
| 4584 | self.assertIn('Build failed.', B.messages[0]) |
| 4585 | self.assertEqual(1, len(C.messages)) |
| 4586 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4587 | self.assertEqual(1, len(D.messages)) |
| 4588 | self.assertIn('Build failed.', D.messages[0]) |
| 4589 | self.assertEqual(1, len(E.messages)) |
| 4590 | self.assertIn('Build failed.', E.messages[0]) |
| 4591 | self.assertEqual(1, len(F.messages)) |
| 4592 | self.assertIn('Build failed.', F.messages[0]) |
| 4593 | |
| 4594 | # The last 3 (GHI) would have only reported via smtp. |
| 4595 | self.assertEqual(3, len(self.smtp_messages)) |
| 4596 | self.assertEqual(0, len(G.messages)) |
| 4597 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
| 4598 | self.assertIn('/7/1/check', self.smtp_messages[0]['body']) |
| 4599 | self.assertEqual(0, len(H.messages)) |
| 4600 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
| 4601 | self.assertIn('/8/1/check', self.smtp_messages[1]['body']) |
| 4602 | self.assertEqual(0, len(I.messages)) |
| 4603 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
| 4604 | self.assertIn('/9/1/check', self.smtp_messages[2]['body']) |
| 4605 | |
| 4606 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4607 | # comes out of disabled |
| 4608 | self.sched.reconfigure(self.config) |
| 4609 | |
| 4610 | self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at) |
| 4611 | self.assertEqual( |
| 4612 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4613 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4614 | |
| 4615 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4616 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4617 | self.waitUntilSettled() |
| 4618 | |
| 4619 | self.assertEqual( |
| 4620 | 2, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4621 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4622 | |
| 4623 | # J and K went back to gerrit |
| 4624 | self.assertEqual(1, len(J.messages)) |
| 4625 | self.assertIn('Build failed.', J.messages[0]) |
| 4626 | self.assertEqual(1, len(K.messages)) |
| 4627 | self.assertIn('Build failed.', K.messages[0]) |
| 4628 | # No more messages reported via smtp |
| 4629 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4630 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4631 | @skip("Disabled for early v3 development") |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4632 | def test_success_pattern(self): |
| 4633 | "Ensure bad build params are ignored" |
| 4634 | |
| 4635 | # Use SMTP reporter to grab the result message easier |
| 4636 | self.init_repo("org/docs") |
| 4637 | self.config.set('zuul', 'layout_config', |
| 4638 | 'tests/fixtures/layout-success-pattern.yaml') |
| 4639 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4640 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4641 | self.registerJobs() |
| 4642 | |
| 4643 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4644 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4645 | self.waitUntilSettled() |
| 4646 | |
| 4647 | # Grab build id |
| 4648 | self.assertEqual(len(self.builds), 1) |
| 4649 | uuid = self.builds[0].unique[:7] |
| 4650 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4651 | self.launch_server.hold_jobs_in_build = False |
| 4652 | self.launch_server.release() |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4653 | self.waitUntilSettled() |
| 4654 | |
| 4655 | self.assertEqual(len(self.smtp_messages), 1) |
| 4656 | body = self.smtp_messages[0]['body'].splitlines() |
| 4657 | self.assertEqual('Build succeeded.', body[0]) |
| 4658 | |
| 4659 | self.assertIn( |
| 4660 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4661 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4662 | body[2]) |
| 4663 | self.assertIn( |
| 4664 | '- docs-draft-test2 https://server/job/docs-draft-test2/1/', |
| 4665 | body[3]) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4666 | |
| 4667 | |
| 4668 | class TestDuplicatePipeline(ZuulTestCase): |
| 4669 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4670 | |
| 4671 | def test_duplicate_pipelines(self): |
| 4672 | "Test that a change matching multiple pipelines works" |
| 4673 | |
| 4674 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4675 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4676 | self.waitUntilSettled() |
| 4677 | |
| 4678 | self.assertHistory([ |
| 4679 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4680 | pipeline='dup1'), |
| 4681 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4682 | pipeline='dup2'), |
| 4683 | ]) |
| 4684 | |
| 4685 | self.assertEqual(len(A.messages), 2) |
| 4686 | |
| 4687 | self.assertIn('dup1', A.messages[0]) |
| 4688 | self.assertNotIn('dup2', A.messages[0]) |
| 4689 | self.assertIn('project-test1', A.messages[0]) |
| 4690 | |
| 4691 | self.assertIn('dup2', A.messages[1]) |
| 4692 | self.assertNotIn('dup1', A.messages[1]) |
| 4693 | self.assertIn('project-test1', A.messages[1]) |