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