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