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