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 | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 28 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 29 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
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, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 40 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 41 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 42 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 44 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 45 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 46 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 47 | def test_jobs_executed(self): |
| 48 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 49 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 50 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 51 | A.addApproval('code-review', 2) |
| 52 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 53 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 54 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 55 | 'SUCCESS') |
| 56 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(A.data['status'], 'MERGED') |
| 61 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 62 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 63 | 'image1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 64 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 65 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 66 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 67 | # Per-driver |
| 68 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 69 | # Per-driver per-connection |
| 70 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 71 | value='1|c') |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 72 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 73 | value='1|g') |
| 74 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 75 | kind='ms') |
| 76 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 77 | value='1|c') |
| 78 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 79 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 80 | value='1|c') |
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.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 83 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 84 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 85 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 86 | for build in self.builds: |
| 87 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 88 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 89 | def test_initial_pipeline_gauges(self): |
| 90 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 91 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 92 | value='0|g') |
| 93 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 94 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 95 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 96 | def test_job_branch(self): |
| 97 | "Test the correct variant of a job runs on a branch" |
| 98 | self.create_branch('org/project', 'stable') |
| 99 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 100 | A.addApproval('code-review', 2) |
| 101 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 102 | self.waitUntilSettled() |
| 103 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 104 | 'SUCCESS') |
| 105 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 106 | 'SUCCESS') |
| 107 | self.assertEqual(A.data['status'], 'MERGED') |
| 108 | self.assertEqual(A.reported, 2, |
| 109 | "A should report start and success") |
| 110 | self.assertIn('gate', A.messages[1], |
| 111 | "A should transit gate") |
| 112 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 113 | 'image2') |
| 114 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 115 | def test_parallel_changes(self): |
| 116 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 117 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 118 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 119 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 120 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 121 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 122 | A.addApproval('code-review', 2) |
| 123 | B.addApproval('code-review', 2) |
| 124 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 125 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 126 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 127 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 128 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 129 | |
| 130 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 131 | self.assertEqual(len(self.builds), 1) |
| 132 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 133 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 134 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 135 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 136 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 137 | self.assertEqual(len(self.builds), 3) |
| 138 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 139 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 140 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 141 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 142 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 143 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 144 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 145 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 146 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 147 | self.assertEqual(len(self.builds), 5) |
| 148 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 149 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 150 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 151 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 152 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 153 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 154 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 155 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 158 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 159 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 161 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 162 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(len(self.builds), 6) |
| 164 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 169 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 173 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 174 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 175 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 177 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 179 | self.executor_server.hold_jobs_in_build = False |
| 180 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 183 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 184 | self.assertEqual(len(self.history), 9) |
| 185 | self.assertEqual(A.data['status'], 'MERGED') |
| 186 | self.assertEqual(B.data['status'], 'MERGED') |
| 187 | self.assertEqual(C.data['status'], 'MERGED') |
| 188 | self.assertEqual(A.reported, 2) |
| 189 | self.assertEqual(B.reported, 2) |
| 190 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 191 | |
| 192 | def test_failed_changes(self): |
| 193 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 194 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 195 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 196 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 197 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 198 | A.addApproval('code-review', 2) |
| 199 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 200 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 201 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 202 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 203 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 204 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 205 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 206 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 207 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 208 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 209 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 210 | # A/project-merge is complete |
| 211 | self.assertBuilds([ |
| 212 | dict(name='project-test1', changes='1,1'), |
| 213 | dict(name='project-test2', changes='1,1'), |
| 214 | dict(name='project-merge', changes='1,1 2,1'), |
| 215 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 216 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 217 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 218 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 219 | # A/project-merge is complete |
| 220 | # B/project-merge is complete |
| 221 | self.assertBuilds([ |
| 222 | dict(name='project-test1', changes='1,1'), |
| 223 | dict(name='project-test2', changes='1,1'), |
| 224 | dict(name='project-test1', changes='1,1 2,1'), |
| 225 | dict(name='project-test2', changes='1,1 2,1'), |
| 226 | ]) |
| 227 | |
| 228 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 229 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 230 | self.builds[0].release() |
| 231 | self.waitUntilSettled() |
| 232 | |
| 233 | self.orderedRelease() |
| 234 | self.assertHistory([ |
| 235 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 236 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 237 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 238 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 239 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 240 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 241 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 242 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 243 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 244 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 245 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 246 | self.assertEqual(A.data['status'], 'NEW') |
| 247 | self.assertEqual(B.data['status'], 'MERGED') |
| 248 | self.assertEqual(A.reported, 2) |
| 249 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 250 | |
| 251 | def test_independent_queues(self): |
| 252 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 253 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 254 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 255 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 256 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 257 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 258 | A.addApproval('code-review', 2) |
| 259 | B.addApproval('code-review', 2) |
| 260 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 261 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 262 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 263 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 264 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 265 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 266 | self.waitUntilSettled() |
| 267 | |
| 268 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 269 | self.waitUntilSettled() |
| 270 | |
| 271 | # 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] | 272 | self.assertBuilds([ |
| 273 | dict(name='project-merge', changes='1,1'), |
| 274 | dict(name='project-merge', changes='2,1'), |
| 275 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 276 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 277 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 278 | self.builds[0].release() |
| 279 | self.waitUntilSettled() |
| 280 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 281 | self.waitUntilSettled() |
| 282 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 283 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 284 | self.waitUntilSettled() |
| 285 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 286 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 287 | self.assertBuilds([ |
| 288 | dict(name='project-test1', changes='1,1'), |
| 289 | dict(name='project-test2', changes='1,1'), |
| 290 | dict(name='project-test1', changes='2,1'), |
| 291 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 292 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 293 | dict(name='project-test1', changes='2,1 3,1'), |
| 294 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 295 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 296 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 297 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 298 | self.orderedRelease() |
| 299 | self.assertHistory([ |
| 300 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 301 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 302 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 303 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 304 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 305 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 306 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 307 | dict( |
| 308 | name='project1-project2-integration', |
| 309 | result='SUCCESS', |
| 310 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 311 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 312 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 313 | dict(name='project1-project2-integration', |
| 314 | result='SUCCESS', |
| 315 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 316 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 317 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 318 | self.assertEqual(A.data['status'], 'MERGED') |
| 319 | self.assertEqual(B.data['status'], 'MERGED') |
| 320 | self.assertEqual(C.data['status'], 'MERGED') |
| 321 | self.assertEqual(A.reported, 2) |
| 322 | self.assertEqual(B.reported, 2) |
| 323 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 324 | |
| 325 | def test_failed_change_at_head(self): |
| 326 | "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] | 327 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 328 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 329 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 330 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 331 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 332 | A.addApproval('code-review', 2) |
| 333 | B.addApproval('code-review', 2) |
| 334 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 335 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 336 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 338 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 339 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 340 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 341 | |
| 342 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 344 | self.assertBuilds([ |
| 345 | dict(name='project-merge', changes='1,1'), |
| 346 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 348 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 349 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 350 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 351 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 352 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | self.waitUntilSettled() |
| 354 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 355 | self.assertBuilds([ |
| 356 | dict(name='project-test1', changes='1,1'), |
| 357 | dict(name='project-test2', changes='1,1'), |
| 358 | dict(name='project-test1', changes='1,1 2,1'), |
| 359 | dict(name='project-test2', changes='1,1 2,1'), |
| 360 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 361 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 362 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 363 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 364 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 365 | self.waitUntilSettled() |
| 366 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 367 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 368 | self.assertBuilds([ |
| 369 | dict(name='project-test2', changes='1,1'), |
| 370 | dict(name='project-merge', changes='2,1'), |
| 371 | ]) |
| 372 | # Unordered history comparison because the aborts can finish |
| 373 | # in any order. |
| 374 | self.assertHistory([ |
| 375 | dict(name='project-merge', result='SUCCESS', |
| 376 | changes='1,1'), |
| 377 | dict(name='project-merge', result='SUCCESS', |
| 378 | changes='1,1 2,1'), |
| 379 | dict(name='project-merge', result='SUCCESS', |
| 380 | changes='1,1 2,1 3,1'), |
| 381 | dict(name='project-test1', result='FAILURE', |
| 382 | changes='1,1'), |
| 383 | dict(name='project-test1', result='ABORTED', |
| 384 | changes='1,1 2,1'), |
| 385 | dict(name='project-test2', result='ABORTED', |
| 386 | changes='1,1 2,1'), |
| 387 | dict(name='project-test1', result='ABORTED', |
| 388 | changes='1,1 2,1 3,1'), |
| 389 | dict(name='project-test2', result='ABORTED', |
| 390 | changes='1,1 2,1 3,1'), |
| 391 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 392 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 393 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 394 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 395 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 396 | self.waitUntilSettled() |
| 397 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 398 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 399 | self.assertBuilds([]) |
| 400 | self.assertHistory([ |
| 401 | dict(name='project-merge', result='SUCCESS', |
| 402 | changes='1,1'), |
| 403 | dict(name='project-merge', result='SUCCESS', |
| 404 | changes='1,1 2,1'), |
| 405 | dict(name='project-merge', result='SUCCESS', |
| 406 | changes='1,1 2,1 3,1'), |
| 407 | dict(name='project-test1', result='FAILURE', |
| 408 | changes='1,1'), |
| 409 | dict(name='project-test1', result='ABORTED', |
| 410 | changes='1,1 2,1'), |
| 411 | dict(name='project-test2', result='ABORTED', |
| 412 | changes='1,1 2,1'), |
| 413 | dict(name='project-test1', result='ABORTED', |
| 414 | changes='1,1 2,1 3,1'), |
| 415 | dict(name='project-test2', result='ABORTED', |
| 416 | changes='1,1 2,1 3,1'), |
| 417 | dict(name='project-merge', result='SUCCESS', |
| 418 | changes='2,1'), |
| 419 | dict(name='project-merge', result='SUCCESS', |
| 420 | changes='2,1 3,1'), |
| 421 | dict(name='project-test2', result='SUCCESS', |
| 422 | changes='1,1'), |
| 423 | dict(name='project-test1', result='SUCCESS', |
| 424 | changes='2,1'), |
| 425 | dict(name='project-test2', result='SUCCESS', |
| 426 | changes='2,1'), |
| 427 | dict(name='project-test1', result='SUCCESS', |
| 428 | changes='2,1 3,1'), |
| 429 | dict(name='project-test2', result='SUCCESS', |
| 430 | changes='2,1 3,1'), |
| 431 | ], ordered=False) |
| 432 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 433 | self.assertEqual(A.data['status'], 'NEW') |
| 434 | self.assertEqual(B.data['status'], 'MERGED') |
| 435 | self.assertEqual(C.data['status'], 'MERGED') |
| 436 | self.assertEqual(A.reported, 2) |
| 437 | self.assertEqual(B.reported, 2) |
| 438 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 439 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 440 | def test_failed_change_in_middle(self): |
| 441 | "Test a failed change in the middle of the queue" |
| 442 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 443 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 444 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 445 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 446 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 447 | A.addApproval('code-review', 2) |
| 448 | B.addApproval('code-review', 2) |
| 449 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 451 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 452 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 453 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 454 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 455 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 456 | |
| 457 | self.waitUntilSettled() |
| 458 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 459 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 460 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 461 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 462 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 463 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 464 | self.waitUntilSettled() |
| 465 | |
| 466 | self.assertEqual(len(self.builds), 6) |
| 467 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 468 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 469 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 470 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 471 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 472 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 473 | |
| 474 | self.release(self.builds[2]) |
| 475 | self.waitUntilSettled() |
| 476 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 477 | # project-test1 and project-test2 for A |
| 478 | # project-test2 for B |
| 479 | # project-merge for C (without B) |
| 480 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 481 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 482 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 483 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 484 | self.waitUntilSettled() |
| 485 | |
| 486 | # project-test1 and project-test2 for A |
| 487 | # project-test2 for B |
| 488 | # project-test1 and project-test2 for C |
| 489 | self.assertEqual(len(self.builds), 5) |
| 490 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 491 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 492 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 493 | builds = items[0].current_build_set.getBuilds() |
| 494 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 495 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 496 | builds = items[1].current_build_set.getBuilds() |
| 497 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 498 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 499 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 500 | builds = items[2].current_build_set.getBuilds() |
| 501 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 502 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 503 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 504 | self.executor_server.hold_jobs_in_build = False |
| 505 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 506 | self.waitUntilSettled() |
| 507 | |
| 508 | self.assertEqual(len(self.builds), 0) |
| 509 | self.assertEqual(len(self.history), 12) |
| 510 | self.assertEqual(A.data['status'], 'MERGED') |
| 511 | self.assertEqual(B.data['status'], 'NEW') |
| 512 | self.assertEqual(C.data['status'], 'MERGED') |
| 513 | self.assertEqual(A.reported, 2) |
| 514 | self.assertEqual(B.reported, 2) |
| 515 | self.assertEqual(C.reported, 2) |
| 516 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 517 | def test_failed_change_at_head_with_queue(self): |
| 518 | "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] | 519 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 520 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 521 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 522 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 523 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 524 | A.addApproval('code-review', 2) |
| 525 | B.addApproval('code-review', 2) |
| 526 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 528 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 529 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 530 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 531 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 532 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 533 | |
| 534 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 535 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 536 | self.assertEqual(len(self.builds), 0) |
| 537 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 538 | self.assertEqual(queue[0].name, b'executor:execute') |
| 539 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 540 | self.assertEqual(job_args['job'], 'project-merge') |
| 541 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 542 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 543 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 544 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 545 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 546 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 547 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 548 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 549 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 550 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 551 | self.assertEqual(len(self.builds), 0) |
| 552 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 553 | |
| 554 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 555 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 556 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 557 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 558 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 559 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 560 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 561 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 562 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 563 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 564 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 565 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 566 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 567 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 568 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 569 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 570 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 571 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 573 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | self.waitUntilSettled() |
| 575 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 576 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 577 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 578 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 579 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 580 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 581 | self.gearman_server.hold_jobs_in_queue = False |
| 582 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 583 | self.waitUntilSettled() |
| 584 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 585 | self.assertEqual(len(self.builds), 0) |
| 586 | self.assertEqual(len(self.history), 11) |
| 587 | self.assertEqual(A.data['status'], 'NEW') |
| 588 | self.assertEqual(B.data['status'], 'MERGED') |
| 589 | self.assertEqual(C.data['status'], 'MERGED') |
| 590 | self.assertEqual(A.reported, 2) |
| 591 | self.assertEqual(B.reported, 2) |
| 592 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 593 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 594 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 595 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 596 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 597 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 598 | A.addApproval('code-review', 2) |
| 599 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 600 | self.waitUntilSettled() |
| 601 | time.sleep(2) |
| 602 | |
| 603 | data = json.loads(self.sched.formatStatusJSON()) |
| 604 | found_job = None |
| 605 | for pipeline in data['pipelines']: |
| 606 | if pipeline['name'] != 'gate': |
| 607 | continue |
| 608 | for queue in pipeline['change_queues']: |
| 609 | for head in queue['heads']: |
| 610 | for item in head: |
| 611 | for job in item['jobs']: |
| 612 | if job['name'] == 'project-merge': |
| 613 | found_job = job |
| 614 | break |
| 615 | |
| 616 | self.assertIsNotNone(found_job) |
| 617 | if iteration == 1: |
| 618 | self.assertIsNotNone(found_job['estimated_time']) |
| 619 | self.assertIsNone(found_job['remaining_time']) |
| 620 | else: |
| 621 | self.assertIsNotNone(found_job['estimated_time']) |
| 622 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 623 | self.assertIsNotNone(found_job['remaining_time']) |
| 624 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 625 | self.executor_server.hold_jobs_in_build = False |
| 626 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 627 | self.waitUntilSettled() |
| 628 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 629 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 630 | def test_time_database(self): |
| 631 | "Test the time database" |
| 632 | |
| 633 | self._test_time_database(1) |
| 634 | self._test_time_database(2) |
| 635 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 636 | def test_two_failed_changes_at_head(self): |
| 637 | "Test that changes are reparented correctly if 2 fail at head" |
| 638 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 639 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 640 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 641 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 642 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 643 | A.addApproval('code-review', 2) |
| 644 | B.addApproval('code-review', 2) |
| 645 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 646 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 647 | self.executor_server.failJob('project-test1', A) |
| 648 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 649 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 650 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 651 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 652 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 653 | self.waitUntilSettled() |
| 654 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 655 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 656 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 657 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 658 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 659 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 660 | self.waitUntilSettled() |
| 661 | |
| 662 | self.assertEqual(len(self.builds), 6) |
| 663 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 664 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 665 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 666 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 667 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 668 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 669 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 670 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 671 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 672 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 673 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 674 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 675 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 676 | |
| 677 | # Fail change B first |
| 678 | self.release(self.builds[2]) |
| 679 | self.waitUntilSettled() |
| 680 | |
| 681 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 682 | self.executor_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), 5) |
| 686 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 687 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 688 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 689 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 690 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 691 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 692 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 693 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 694 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 695 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 696 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 697 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 698 | |
| 699 | # Finish running all passing jobs for change A |
| 700 | self.release(self.builds[1]) |
| 701 | self.waitUntilSettled() |
| 702 | # Fail and report change A |
| 703 | self.release(self.builds[0]) |
| 704 | self.waitUntilSettled() |
| 705 | |
| 706 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 707 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 708 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 709 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 710 | self.waitUntilSettled() |
| 711 | |
| 712 | self.assertEqual(len(self.builds), 4) |
| 713 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 714 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 715 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 716 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 717 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 718 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 719 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 720 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 721 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 722 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 723 | # After A failed and B and C restarted, B should be back in |
| 724 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 725 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 726 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 727 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 728 | self.executor_server.hold_jobs_in_build = False |
| 729 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 730 | self.waitUntilSettled() |
| 731 | |
| 732 | self.assertEqual(len(self.builds), 0) |
| 733 | self.assertEqual(len(self.history), 21) |
| 734 | self.assertEqual(A.data['status'], 'NEW') |
| 735 | self.assertEqual(B.data['status'], 'NEW') |
| 736 | self.assertEqual(C.data['status'], 'MERGED') |
| 737 | self.assertEqual(A.reported, 2) |
| 738 | self.assertEqual(B.reported, 2) |
| 739 | self.assertEqual(C.reported, 2) |
| 740 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 741 | def test_patch_order(self): |
| 742 | "Test that dependent patches are tested in the right order" |
| 743 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 744 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 745 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 746 | A.addApproval('code-review', 2) |
| 747 | B.addApproval('code-review', 2) |
| 748 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 749 | |
| 750 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 751 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 752 | M2.setMerged() |
| 753 | M1.setMerged() |
| 754 | |
| 755 | # C -> B -> A -> M1 -> M2 |
| 756 | # M2 is here to make sure it is never queried. If it is, it |
| 757 | # means zuul is walking down the entire history of merged |
| 758 | # changes. |
| 759 | |
| 760 | C.setDependsOn(B, 1) |
| 761 | B.setDependsOn(A, 1) |
| 762 | A.setDependsOn(M1, 1) |
| 763 | M1.setDependsOn(M2, 1) |
| 764 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 765 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 766 | |
| 767 | self.waitUntilSettled() |
| 768 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 769 | self.assertEqual(A.data['status'], 'NEW') |
| 770 | self.assertEqual(B.data['status'], 'NEW') |
| 771 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 772 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 773 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 774 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 775 | |
| 776 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 777 | self.assertEqual(M2.queried, 0) |
| 778 | self.assertEqual(A.data['status'], 'MERGED') |
| 779 | self.assertEqual(B.data['status'], 'MERGED') |
| 780 | self.assertEqual(C.data['status'], 'MERGED') |
| 781 | self.assertEqual(A.reported, 2) |
| 782 | self.assertEqual(B.reported, 2) |
| 783 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 784 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 785 | def test_needed_changes_enqueue(self): |
| 786 | "Test that a needed change is enqueued ahead" |
| 787 | # A Given a git tree like this, if we enqueue |
| 788 | # / \ change C, we should walk up and down the tree |
| 789 | # B G and enqueue changes in the order ABCDEFG. |
| 790 | # /|\ This is also the order that you would get if |
| 791 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 792 | # / the ordering is stable across re-enqueue events. |
| 793 | # D |
| 794 | |
| 795 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 796 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 797 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 798 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 799 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 800 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 801 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 802 | B.setDependsOn(A, 1) |
| 803 | C.setDependsOn(B, 1) |
| 804 | D.setDependsOn(C, 1) |
| 805 | E.setDependsOn(B, 1) |
| 806 | F.setDependsOn(B, 1) |
| 807 | G.setDependsOn(A, 1) |
| 808 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 809 | A.addApproval('code-review', 2) |
| 810 | B.addApproval('code-review', 2) |
| 811 | C.addApproval('code-review', 2) |
| 812 | D.addApproval('code-review', 2) |
| 813 | E.addApproval('code-review', 2) |
| 814 | F.addApproval('code-review', 2) |
| 815 | G.addApproval('code-review', 2) |
| 816 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 817 | |
| 818 | self.waitUntilSettled() |
| 819 | |
| 820 | self.assertEqual(A.data['status'], 'NEW') |
| 821 | self.assertEqual(B.data['status'], 'NEW') |
| 822 | self.assertEqual(C.data['status'], 'NEW') |
| 823 | self.assertEqual(D.data['status'], 'NEW') |
| 824 | self.assertEqual(E.data['status'], 'NEW') |
| 825 | self.assertEqual(F.data['status'], 'NEW') |
| 826 | self.assertEqual(G.data['status'], 'NEW') |
| 827 | |
| 828 | # We're about to add approvals to changes without adding the |
| 829 | # triggering events to Zuul, so that we can be sure that it is |
| 830 | # enqueing the changes based on dependencies, not because of |
| 831 | # triggering events. Since it will have the changes cached |
| 832 | # already (without approvals), we need to clear the cache |
| 833 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 834 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 835 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 836 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 837 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 838 | A.addApproval('approved', 1) |
| 839 | B.addApproval('approved', 1) |
| 840 | D.addApproval('approved', 1) |
| 841 | E.addApproval('approved', 1) |
| 842 | F.addApproval('approved', 1) |
| 843 | G.addApproval('approved', 1) |
| 844 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 845 | |
| 846 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 847 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 848 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 849 | self.executor_server.hold_jobs_in_build = False |
| 850 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 851 | self.waitUntilSettled() |
| 852 | |
| 853 | self.assertEqual(A.data['status'], 'MERGED') |
| 854 | self.assertEqual(B.data['status'], 'MERGED') |
| 855 | self.assertEqual(C.data['status'], 'MERGED') |
| 856 | self.assertEqual(D.data['status'], 'MERGED') |
| 857 | self.assertEqual(E.data['status'], 'MERGED') |
| 858 | self.assertEqual(F.data['status'], 'MERGED') |
| 859 | self.assertEqual(G.data['status'], 'MERGED') |
| 860 | self.assertEqual(A.reported, 2) |
| 861 | self.assertEqual(B.reported, 2) |
| 862 | self.assertEqual(C.reported, 2) |
| 863 | self.assertEqual(D.reported, 2) |
| 864 | self.assertEqual(E.reported, 2) |
| 865 | self.assertEqual(F.reported, 2) |
| 866 | self.assertEqual(G.reported, 2) |
| 867 | self.assertEqual(self.history[6].changes, |
| 868 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 869 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 870 | def test_source_cache(self): |
| 871 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 872 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 873 | |
| 874 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 875 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 876 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 877 | A.addApproval('code-review', 2) |
| 878 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 879 | |
| 880 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 881 | M1.setMerged() |
| 882 | |
| 883 | B.setDependsOn(A, 1) |
| 884 | A.setDependsOn(M1, 1) |
| 885 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 886 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 887 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 888 | |
| 889 | self.waitUntilSettled() |
| 890 | |
| 891 | for build in self.builds: |
| 892 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 893 | build.release() |
| 894 | self.waitUntilSettled() |
| 895 | for build in self.builds: |
| 896 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 897 | build.release() |
| 898 | self.waitUntilSettled() |
| 899 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 900 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 901 | self.waitUntilSettled() |
| 902 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 903 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 904 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 905 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 906 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 907 | self.executor_server.hold_jobs_in_build = False |
| 908 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 909 | self.waitUntilSettled() |
| 910 | |
| 911 | self.assertEqual(A.data['status'], 'MERGED') |
| 912 | self.assertEqual(B.data['status'], 'MERGED') |
| 913 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 914 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 915 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 916 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 917 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 918 | # TODO: move to test_gerrit (this is a unit test!) |
| 919 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 920 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 921 | (trusted, project) = tenant.getProject('org/project') |
| 922 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 923 | |
| 924 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 925 | # it easier for users to create events for testing. |
| 926 | event = zuul.model.TriggerEvent() |
| 927 | event.trigger_name = 'gerrit' |
| 928 | event.change_number = '1' |
| 929 | event.patch_number = '2' |
| 930 | |
| 931 | a = source.getChange(event) |
| 932 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 933 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 934 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 935 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 936 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 937 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 938 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 939 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 940 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 941 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 942 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 943 | def test_project_merge_conflict(self): |
| 944 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 945 | |
| 946 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 947 | A = self.fake_gerrit.addFakeChange('org/project', |
| 948 | 'master', 'A', |
| 949 | files={'conflict': 'foo'}) |
| 950 | B = self.fake_gerrit.addFakeChange('org/project', |
| 951 | 'master', 'B', |
| 952 | files={'conflict': 'bar'}) |
| 953 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 954 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 955 | A.addApproval('code-review', 2) |
| 956 | B.addApproval('code-review', 2) |
| 957 | C.addApproval('code-review', 2) |
| 958 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 959 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 960 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 961 | self.waitUntilSettled() |
| 962 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 963 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 964 | self.assertEqual(C.reported, 1) |
| 965 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 966 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 967 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 968 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 969 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 970 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 971 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 972 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 973 | self.gearman_server.hold_jobs_in_queue = False |
| 974 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 975 | self.waitUntilSettled() |
| 976 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 977 | self.assertEqual(A.data['status'], 'MERGED') |
| 978 | self.assertEqual(B.data['status'], 'NEW') |
| 979 | self.assertEqual(C.data['status'], 'MERGED') |
| 980 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 981 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 982 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 983 | |
| 984 | self.assertHistory([ |
| 985 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 986 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 987 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 988 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 989 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 990 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 991 | ], ordered=False) |
| 992 | |
| 993 | def test_delayed_merge_conflict(self): |
| 994 | "Test that delayed check merge conflicts are handled properly" |
| 995 | |
| 996 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 997 | # the executor sucesfully merges a change based on an old |
| 998 | # repo state (frozen by the scheduler) which would otherwise |
| 999 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1000 | self.gearman_server.hold_jobs_in_queue = True |
| 1001 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1002 | 'master', 'A', |
| 1003 | files={'conflict': 'foo'}) |
| 1004 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1005 | 'master', 'B', |
| 1006 | files={'conflict': 'bar'}) |
| 1007 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1008 | 'master', 'C') |
| 1009 | C.setDependsOn(B, 1) |
| 1010 | |
| 1011 | # A enters the gate queue; B and C enter the check queue |
| 1012 | A.addApproval('code-review', 2) |
| 1013 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1014 | self.waitUntilSettled() |
| 1015 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1016 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1017 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1018 | self.waitUntilSettled() |
| 1019 | |
| 1020 | self.assertEqual(A.reported, 1) |
| 1021 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1022 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1023 | |
| 1024 | # A merges while B and C are queued in check |
| 1025 | # Release A project-merge |
| 1026 | queue = self.gearman_server.getQueue() |
| 1027 | self.release(queue[0]) |
| 1028 | self.waitUntilSettled() |
| 1029 | |
| 1030 | # Release A project-test* |
| 1031 | # gate has higher precedence, so A's test jobs are added in |
| 1032 | # front of the merge jobs for B and C |
| 1033 | queue = self.gearman_server.getQueue() |
| 1034 | self.release(queue[0]) |
| 1035 | self.release(queue[1]) |
| 1036 | self.waitUntilSettled() |
| 1037 | |
| 1038 | self.assertEqual(A.data['status'], 'MERGED') |
| 1039 | self.assertEqual(B.data['status'], 'NEW') |
| 1040 | self.assertEqual(C.data['status'], 'NEW') |
| 1041 | self.assertEqual(A.reported, 2) |
| 1042 | self.assertEqual(B.reported, 0) |
| 1043 | self.assertEqual(C.reported, 0) |
| 1044 | self.assertHistory([ |
| 1045 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1046 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1047 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1048 | ], ordered=False) |
| 1049 | |
| 1050 | # B and C report merge conflicts |
| 1051 | # Release B project-merge |
| 1052 | queue = self.gearman_server.getQueue() |
| 1053 | self.release(queue[0]) |
| 1054 | self.waitUntilSettled() |
| 1055 | |
| 1056 | # Release C |
| 1057 | self.gearman_server.hold_jobs_in_queue = False |
| 1058 | self.gearman_server.release() |
| 1059 | self.waitUntilSettled() |
| 1060 | |
| 1061 | self.assertEqual(A.data['status'], 'MERGED') |
| 1062 | self.assertEqual(B.data['status'], 'NEW') |
| 1063 | self.assertEqual(C.data['status'], 'NEW') |
| 1064 | self.assertEqual(A.reported, 2) |
| 1065 | self.assertEqual(B.reported, 1) |
| 1066 | self.assertEqual(C.reported, 1) |
| 1067 | |
| 1068 | self.assertHistory([ |
| 1069 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1070 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1072 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1073 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1074 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1075 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1076 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1077 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1078 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1079 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1080 | def test_post(self): |
| 1081 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1082 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1083 | e = { |
| 1084 | "type": "ref-updated", |
| 1085 | "submitter": { |
| 1086 | "name": "User Name", |
| 1087 | }, |
| 1088 | "refUpdate": { |
| 1089 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1090 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1091 | "refName": "master", |
| 1092 | "project": "org/project", |
| 1093 | } |
| 1094 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1095 | self.fake_gerrit.addEvent(e) |
| 1096 | self.waitUntilSettled() |
| 1097 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1098 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1099 | self.assertEqual(len(self.history), 1) |
| 1100 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1101 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1102 | def test_post_ignore_deletes(self): |
| 1103 | "Test that deleting refs does not trigger post jobs" |
| 1104 | |
| 1105 | e = { |
| 1106 | "type": "ref-updated", |
| 1107 | "submitter": { |
| 1108 | "name": "User Name", |
| 1109 | }, |
| 1110 | "refUpdate": { |
| 1111 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1112 | "newRev": "0000000000000000000000000000000000000000", |
| 1113 | "refName": "master", |
| 1114 | "project": "org/project", |
| 1115 | } |
| 1116 | } |
| 1117 | self.fake_gerrit.addEvent(e) |
| 1118 | self.waitUntilSettled() |
| 1119 | |
| 1120 | job_names = [x.name for x in self.history] |
| 1121 | self.assertEqual(len(self.history), 0) |
| 1122 | self.assertNotIn('project-post', job_names) |
| 1123 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1124 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1125 | def test_post_ignore_deletes_negative(self): |
| 1126 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1127 | e = { |
| 1128 | "type": "ref-updated", |
| 1129 | "submitter": { |
| 1130 | "name": "User Name", |
| 1131 | }, |
| 1132 | "refUpdate": { |
| 1133 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1134 | "newRev": "0000000000000000000000000000000000000000", |
| 1135 | "refName": "master", |
| 1136 | "project": "org/project", |
| 1137 | } |
| 1138 | } |
| 1139 | self.fake_gerrit.addEvent(e) |
| 1140 | self.waitUntilSettled() |
| 1141 | |
| 1142 | job_names = [x.name for x in self.history] |
| 1143 | self.assertEqual(len(self.history), 1) |
| 1144 | self.assertIn('project-post', job_names) |
| 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_branch_interaction(self): |
| 1148 | "Test that switching between branches works" |
| 1149 | self.test_build_configuration() |
| 1150 | self.test_build_configuration_branch() |
| 1151 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1152 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1153 | repo = git.Repo(path) |
| 1154 | repo.heads.master.commit = repo.commit('init') |
| 1155 | self.test_build_configuration() |
| 1156 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1157 | def test_dependent_changes_dequeue(self): |
| 1158 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1159 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1160 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1161 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1162 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1163 | A.addApproval('code-review', 2) |
| 1164 | B.addApproval('code-review', 2) |
| 1165 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1166 | |
| 1167 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1168 | M1.setMerged() |
| 1169 | |
| 1170 | # C -> B -> A -> M1 |
| 1171 | |
| 1172 | C.setDependsOn(B, 1) |
| 1173 | B.setDependsOn(A, 1) |
| 1174 | A.setDependsOn(M1, 1) |
| 1175 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1176 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1177 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1178 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1179 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1180 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1181 | |
| 1182 | self.waitUntilSettled() |
| 1183 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1184 | self.assertEqual(A.data['status'], 'NEW') |
| 1185 | self.assertEqual(A.reported, 2) |
| 1186 | self.assertEqual(B.data['status'], 'NEW') |
| 1187 | self.assertEqual(B.reported, 2) |
| 1188 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1189 | self.assertIn('This change depends on a change that failed to merge.', |
| 1190 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1191 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1192 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1193 | def test_failing_dependent_changes(self): |
| 1194 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1195 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1196 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1197 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1198 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1199 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1200 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1201 | A.addApproval('code-review', 2) |
| 1202 | B.addApproval('code-review', 2) |
| 1203 | C.addApproval('code-review', 2) |
| 1204 | D.addApproval('code-review', 2) |
| 1205 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1206 | |
| 1207 | # E, D -> C -> B, A |
| 1208 | |
| 1209 | D.setDependsOn(C, 1) |
| 1210 | C.setDependsOn(B, 1) |
| 1211 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1212 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1213 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1214 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1215 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1216 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1217 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1218 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1219 | |
| 1220 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1221 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1222 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1223 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1224 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1225 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1226 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1227 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1228 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1229 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1230 | self.waitUntilSettled() |
| 1231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1232 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1233 | for build in self.builds: |
| 1234 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1235 | build.release() |
| 1236 | self.waitUntilSettled() |
| 1237 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1238 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1239 | self.waitUntilSettled() |
| 1240 | |
| 1241 | self.assertEqual(A.data['status'], 'MERGED') |
| 1242 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1243 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1244 | self.assertEqual(B.data['status'], 'NEW') |
| 1245 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1246 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1247 | self.assertEqual(C.data['status'], 'NEW') |
| 1248 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1249 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1250 | self.assertEqual(D.data['status'], 'NEW') |
| 1251 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1252 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1253 | self.assertEqual(E.data['status'], 'MERGED') |
| 1254 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1255 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1256 | self.assertEqual(len(self.history), 18) |
| 1257 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1258 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1259 | "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] | 1260 | # If it's dequeued more than once, we should see extra |
| 1261 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1262 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1263 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1264 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1265 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1266 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1267 | A.addApproval('code-review', 2) |
| 1268 | B.addApproval('code-review', 2) |
| 1269 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1270 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1271 | self.executor_server.failJob('project-test1', A) |
| 1272 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1273 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1274 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1275 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1276 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1277 | |
| 1278 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1279 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1280 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1281 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1282 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1283 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1284 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1285 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1286 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1287 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1288 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1289 | self.waitUntilSettled() |
| 1290 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1291 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1292 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1293 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1294 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1295 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1296 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1297 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1298 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1299 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1300 | self.waitUntilSettled() |
| 1301 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1302 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1303 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1304 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1305 | self.executor_server.hold_jobs_in_build = False |
| 1306 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1307 | self.waitUntilSettled() |
| 1308 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1309 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1310 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1311 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1312 | self.assertEqual(A.data['status'], 'NEW') |
| 1313 | self.assertEqual(B.data['status'], 'MERGED') |
| 1314 | self.assertEqual(C.data['status'], 'MERGED') |
| 1315 | self.assertEqual(A.reported, 2) |
| 1316 | self.assertEqual(B.reported, 2) |
| 1317 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1318 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1319 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1320 | def test_nonvoting_job(self): |
| 1321 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1322 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1323 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1324 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1325 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1326 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1327 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1328 | |
| 1329 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1330 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1331 | self.assertEqual(A.data['status'], 'MERGED') |
| 1332 | self.assertEqual(A.reported, 2) |
| 1333 | self.assertEqual( |
| 1334 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1335 | 'SUCCESS') |
| 1336 | self.assertEqual( |
| 1337 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1338 | 'SUCCESS') |
| 1339 | self.assertEqual( |
| 1340 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1341 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1342 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1343 | for build in self.builds: |
| 1344 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1345 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1346 | def test_check_queue_success(self): |
| 1347 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1348 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1349 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1350 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1351 | |
| 1352 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1353 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1354 | self.assertEqual(A.data['status'], 'NEW') |
| 1355 | self.assertEqual(A.reported, 1) |
| 1356 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1357 | 'SUCCESS') |
| 1358 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1359 | 'SUCCESS') |
| 1360 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1361 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1362 | |
| 1363 | def test_check_queue_failure(self): |
| 1364 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1365 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1367 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1368 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1369 | |
| 1370 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1371 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1372 | self.assertEqual(A.data['status'], 'NEW') |
| 1373 | self.assertEqual(A.reported, 1) |
| 1374 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1375 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1376 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1377 | 'SUCCESS') |
| 1378 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1379 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1380 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1381 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1382 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1383 | # This particular test does a large amount of merges and needs a little |
| 1384 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1385 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1386 | "test that dependent changes behind dequeued changes work" |
| 1387 | # This complicated test is a reproduction of a real life bug |
| 1388 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1389 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1390 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1391 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1392 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1393 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1394 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1395 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1396 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1397 | D.setDependsOn(C, 1) |
| 1398 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1399 | A.addApproval('code-review', 2) |
| 1400 | B.addApproval('code-review', 2) |
| 1401 | C.addApproval('code-review', 2) |
| 1402 | D.addApproval('code-review', 2) |
| 1403 | E.addApproval('code-review', 2) |
| 1404 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1405 | |
| 1406 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1407 | |
| 1408 | # Change object re-use in the gerrit trigger is hidden if |
| 1409 | # changes are added in quick succession; waiting makes it more |
| 1410 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1411 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1412 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1413 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1414 | self.waitUntilSettled() |
| 1415 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1416 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1417 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1418 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
| 1420 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1421 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1422 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1423 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1424 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1425 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1426 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1427 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1428 | self.waitUntilSettled() |
| 1429 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1430 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1431 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1432 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1433 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1434 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1435 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1436 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1437 | self.waitUntilSettled() |
| 1438 | |
| 1439 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1440 | |
| 1441 | # Grab pointers to the jobs we want to release before |
| 1442 | # releasing any, because list indexes may change as |
| 1443 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1444 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1445 | a.release() |
| 1446 | b.release() |
| 1447 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1448 | self.waitUntilSettled() |
| 1449 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1450 | self.executor_server.hold_jobs_in_build = False |
| 1451 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1452 | self.waitUntilSettled() |
| 1453 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1454 | self.assertEqual(A.data['status'], 'NEW') |
| 1455 | self.assertEqual(B.data['status'], 'MERGED') |
| 1456 | self.assertEqual(C.data['status'], 'MERGED') |
| 1457 | self.assertEqual(D.data['status'], 'MERGED') |
| 1458 | self.assertEqual(E.data['status'], 'MERGED') |
| 1459 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1460 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1461 | self.assertEqual(A.reported, 2) |
| 1462 | self.assertEqual(B.reported, 2) |
| 1463 | self.assertEqual(C.reported, 2) |
| 1464 | self.assertEqual(D.reported, 2) |
| 1465 | self.assertEqual(E.reported, 2) |
| 1466 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1467 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1468 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1469 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1470 | |
| 1471 | def test_merger_repack(self): |
| 1472 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1473 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1474 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1475 | A.addApproval('code-review', 2) |
| 1476 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1477 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1478 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1479 | 'SUCCESS') |
| 1480 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1481 | 'SUCCESS') |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1483 | 'SUCCESS') |
| 1484 | self.assertEqual(A.data['status'], 'MERGED') |
| 1485 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1486 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1487 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1488 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1489 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1490 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1491 | if os.path.exists(path): |
| 1492 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1493 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1494 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1495 | if os.path.exists(path): |
| 1496 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1497 | |
| 1498 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1499 | A.addApproval('code-review', 2) |
| 1500 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1501 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1502 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1503 | 'SUCCESS') |
| 1504 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1505 | 'SUCCESS') |
| 1506 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1507 | 'SUCCESS') |
| 1508 | self.assertEqual(A.data['status'], 'MERGED') |
| 1509 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1510 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1511 | def test_merger_repack_large_change(self): |
| 1512 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1513 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1514 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1515 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1516 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1517 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1518 | self.executor_server.merger._addProject('review.example.com', |
| 1519 | 'org/project', url) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1520 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1521 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1522 | # TODOv3(jeblair): add hostname to upstream root |
| 1523 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1524 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1525 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1526 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1527 | if os.path.exists(path): |
| 1528 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1529 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1530 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1531 | if os.path.exists(path): |
| 1532 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1533 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1534 | A.addApproval('code-review', 2) |
| 1535 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1536 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1537 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1538 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1539 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1540 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1541 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1542 | 'SUCCESS') |
| 1543 | self.assertEqual(A.data['status'], 'MERGED') |
| 1544 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1545 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1546 | def test_new_patchset_dequeues_old(self): |
| 1547 | "Test that a new patchset causes the old to be dequeued" |
| 1548 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1549 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1550 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1551 | M.setMerged() |
| 1552 | |
| 1553 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1554 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1555 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1556 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1557 | A.addApproval('code-review', 2) |
| 1558 | B.addApproval('code-review', 2) |
| 1559 | C.addApproval('code-review', 2) |
| 1560 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1561 | |
| 1562 | C.setDependsOn(B, 1) |
| 1563 | B.setDependsOn(A, 1) |
| 1564 | A.setDependsOn(M, 1) |
| 1565 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1566 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1567 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1568 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1569 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1570 | self.waitUntilSettled() |
| 1571 | |
| 1572 | B.addPatchset() |
| 1573 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1574 | self.waitUntilSettled() |
| 1575 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1576 | self.executor_server.hold_jobs_in_build = False |
| 1577 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1578 | self.waitUntilSettled() |
| 1579 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1580 | self.assertEqual(A.data['status'], 'MERGED') |
| 1581 | self.assertEqual(A.reported, 2) |
| 1582 | self.assertEqual(B.data['status'], 'NEW') |
| 1583 | self.assertEqual(B.reported, 2) |
| 1584 | self.assertEqual(C.data['status'], 'NEW') |
| 1585 | self.assertEqual(C.reported, 2) |
| 1586 | self.assertEqual(D.data['status'], 'MERGED') |
| 1587 | self.assertEqual(D.reported, 2) |
| 1588 | 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] | 1589 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1590 | def test_new_patchset_check(self): |
| 1591 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1592 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1593 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1594 | |
| 1595 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1596 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1597 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1598 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1599 | |
| 1600 | # Add two git-dependent changes |
| 1601 | B.setDependsOn(A, 1) |
| 1602 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1603 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1604 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1605 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1606 | |
| 1607 | # A live item, and a non-live/live pair |
| 1608 | items = check_pipeline.getAllItems() |
| 1609 | self.assertEqual(len(items), 3) |
| 1610 | |
| 1611 | self.assertEqual(items[0].change.number, '1') |
| 1612 | self.assertEqual(items[0].change.patchset, '1') |
| 1613 | self.assertFalse(items[0].live) |
| 1614 | |
| 1615 | self.assertEqual(items[1].change.number, '2') |
| 1616 | self.assertEqual(items[1].change.patchset, '1') |
| 1617 | self.assertTrue(items[1].live) |
| 1618 | |
| 1619 | self.assertEqual(items[2].change.number, '1') |
| 1620 | self.assertEqual(items[2].change.patchset, '1') |
| 1621 | self.assertTrue(items[2].live) |
| 1622 | |
| 1623 | # Add a new patchset to A |
| 1624 | A.addPatchset() |
| 1625 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1626 | self.waitUntilSettled() |
| 1627 | |
| 1628 | # The live copy of A,1 should be gone, but the non-live and B |
| 1629 | # should continue, and we should have a new A,2 |
| 1630 | items = check_pipeline.getAllItems() |
| 1631 | self.assertEqual(len(items), 3) |
| 1632 | |
| 1633 | self.assertEqual(items[0].change.number, '1') |
| 1634 | self.assertEqual(items[0].change.patchset, '1') |
| 1635 | self.assertFalse(items[0].live) |
| 1636 | |
| 1637 | self.assertEqual(items[1].change.number, '2') |
| 1638 | self.assertEqual(items[1].change.patchset, '1') |
| 1639 | self.assertTrue(items[1].live) |
| 1640 | |
| 1641 | self.assertEqual(items[2].change.number, '1') |
| 1642 | self.assertEqual(items[2].change.patchset, '2') |
| 1643 | self.assertTrue(items[2].live) |
| 1644 | |
| 1645 | # Add a new patchset to B |
| 1646 | B.addPatchset() |
| 1647 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1648 | self.waitUntilSettled() |
| 1649 | |
| 1650 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1651 | # but we should have a new B,2 (still based on A,1) |
| 1652 | items = check_pipeline.getAllItems() |
| 1653 | self.assertEqual(len(items), 3) |
| 1654 | |
| 1655 | self.assertEqual(items[0].change.number, '1') |
| 1656 | self.assertEqual(items[0].change.patchset, '2') |
| 1657 | self.assertTrue(items[0].live) |
| 1658 | |
| 1659 | self.assertEqual(items[1].change.number, '1') |
| 1660 | self.assertEqual(items[1].change.patchset, '1') |
| 1661 | self.assertFalse(items[1].live) |
| 1662 | |
| 1663 | self.assertEqual(items[2].change.number, '2') |
| 1664 | self.assertEqual(items[2].change.patchset, '2') |
| 1665 | self.assertTrue(items[2].live) |
| 1666 | |
| 1667 | self.builds[0].release() |
| 1668 | self.waitUntilSettled() |
| 1669 | self.builds[0].release() |
| 1670 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1671 | self.executor_server.hold_jobs_in_build = False |
| 1672 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1673 | self.waitUntilSettled() |
| 1674 | |
| 1675 | self.assertEqual(A.reported, 1) |
| 1676 | self.assertEqual(B.reported, 1) |
| 1677 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1678 | self.assertEqual(self.history[0].changes, '1,1') |
| 1679 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1680 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1681 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1682 | self.assertEqual(self.history[2].changes, '1,2') |
| 1683 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1684 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1685 | |
| 1686 | def test_abandoned_gate(self): |
| 1687 | "Test that an abandoned change is dequeued from gate" |
| 1688 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1689 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1690 | |
| 1691 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1692 | A.addApproval('code-review', 2) |
| 1693 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1694 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1695 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1696 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1697 | |
| 1698 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1699 | self.waitUntilSettled() |
| 1700 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1701 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1702 | self.waitUntilSettled() |
| 1703 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1704 | self.assertBuilds([]) |
| 1705 | self.assertHistory([ |
| 1706 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1707 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1708 | self.assertEqual(A.reported, 1, |
| 1709 | "Abandoned gate change should report only start") |
| 1710 | |
| 1711 | def test_abandoned_check(self): |
| 1712 | "Test that an abandoned change is dequeued from check" |
| 1713 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1714 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1715 | |
| 1716 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1717 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1718 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1719 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1720 | |
| 1721 | # Add two git-dependent changes |
| 1722 | B.setDependsOn(A, 1) |
| 1723 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1724 | self.waitUntilSettled() |
| 1725 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1726 | self.waitUntilSettled() |
| 1727 | # A live item, and a non-live/live pair |
| 1728 | items = check_pipeline.getAllItems() |
| 1729 | self.assertEqual(len(items), 3) |
| 1730 | |
| 1731 | self.assertEqual(items[0].change.number, '1') |
| 1732 | self.assertFalse(items[0].live) |
| 1733 | |
| 1734 | self.assertEqual(items[1].change.number, '2') |
| 1735 | self.assertTrue(items[1].live) |
| 1736 | |
| 1737 | self.assertEqual(items[2].change.number, '1') |
| 1738 | self.assertTrue(items[2].live) |
| 1739 | |
| 1740 | # Abandon A |
| 1741 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1742 | self.waitUntilSettled() |
| 1743 | |
| 1744 | # The live copy of A should be gone, but the non-live and B |
| 1745 | # should continue |
| 1746 | items = check_pipeline.getAllItems() |
| 1747 | self.assertEqual(len(items), 2) |
| 1748 | |
| 1749 | self.assertEqual(items[0].change.number, '1') |
| 1750 | self.assertFalse(items[0].live) |
| 1751 | |
| 1752 | self.assertEqual(items[1].change.number, '2') |
| 1753 | self.assertTrue(items[1].live) |
| 1754 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1755 | self.executor_server.hold_jobs_in_build = False |
| 1756 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1757 | self.waitUntilSettled() |
| 1758 | |
| 1759 | self.assertEqual(len(self.history), 4) |
| 1760 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1761 | 'Build should have been aborted') |
| 1762 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1763 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1764 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1765 | def test_abandoned_not_timer(self): |
| 1766 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1767 | # This test can not use simple_layout because it must start |
| 1768 | # with a configuration which does not include a |
| 1769 | # timer-triggered job so that we have an opportunity to set |
| 1770 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1771 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1772 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1773 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1774 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1775 | # The pipeline triggers every second, so we should have seen |
| 1776 | # several by now. |
| 1777 | time.sleep(5) |
| 1778 | self.waitUntilSettled() |
| 1779 | # Stop queuing timer triggered jobs so that the assertions |
| 1780 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1781 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1782 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1783 | self.sched.reconfigure(self.config) |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1784 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1785 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1786 | |
| 1787 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1788 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1789 | self.waitUntilSettled() |
| 1790 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1791 | |
| 1792 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1793 | self.waitUntilSettled() |
| 1794 | |
| 1795 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1797 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1798 | self.waitUntilSettled() |
| 1799 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1800 | def test_zuul_url_return(self): |
| 1801 | "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] | 1802 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1803 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1804 | |
| 1805 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1806 | A.addApproval('code-review', 2) |
| 1807 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1808 | self.waitUntilSettled() |
| 1809 | |
| 1810 | self.assertEqual(len(self.builds), 1) |
| 1811 | for build in self.builds: |
| 1812 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1813 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1814 | self.executor_server.hold_jobs_in_build = False |
| 1815 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1816 | self.waitUntilSettled() |
| 1817 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1818 | def test_new_patchset_dequeues_old_on_head(self): |
| 1819 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1820 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1821 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1822 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1823 | M.setMerged() |
| 1824 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1825 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1826 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1827 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1828 | A.addApproval('code-review', 2) |
| 1829 | B.addApproval('code-review', 2) |
| 1830 | C.addApproval('code-review', 2) |
| 1831 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1832 | |
| 1833 | C.setDependsOn(B, 1) |
| 1834 | B.setDependsOn(A, 1) |
| 1835 | A.setDependsOn(M, 1) |
| 1836 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1837 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1838 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1839 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1840 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1841 | self.waitUntilSettled() |
| 1842 | |
| 1843 | A.addPatchset() |
| 1844 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1845 | self.waitUntilSettled() |
| 1846 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1847 | self.executor_server.hold_jobs_in_build = False |
| 1848 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1849 | self.waitUntilSettled() |
| 1850 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1851 | self.assertEqual(A.data['status'], 'NEW') |
| 1852 | self.assertEqual(A.reported, 2) |
| 1853 | self.assertEqual(B.data['status'], 'NEW') |
| 1854 | self.assertEqual(B.reported, 2) |
| 1855 | self.assertEqual(C.data['status'], 'NEW') |
| 1856 | self.assertEqual(C.reported, 2) |
| 1857 | self.assertEqual(D.data['status'], 'MERGED') |
| 1858 | self.assertEqual(D.reported, 2) |
| 1859 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1860 | |
| 1861 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1862 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1863 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1864 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1865 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1866 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1867 | A.addApproval('code-review', 2) |
| 1868 | B.addApproval('code-review', 2) |
| 1869 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1870 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1871 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1872 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1873 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1874 | self.waitUntilSettled() |
| 1875 | |
| 1876 | B.addPatchset() |
| 1877 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1878 | self.waitUntilSettled() |
| 1879 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1880 | self.executor_server.hold_jobs_in_build = False |
| 1881 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1882 | self.waitUntilSettled() |
| 1883 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1884 | self.assertEqual(A.data['status'], 'MERGED') |
| 1885 | self.assertEqual(A.reported, 2) |
| 1886 | self.assertEqual(B.data['status'], 'NEW') |
| 1887 | self.assertEqual(B.reported, 2) |
| 1888 | self.assertEqual(C.data['status'], 'MERGED') |
| 1889 | self.assertEqual(C.reported, 2) |
| 1890 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1891 | |
| 1892 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1893 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1894 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1895 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1896 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1897 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1898 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1899 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1900 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1901 | self.waitUntilSettled() |
| 1902 | |
| 1903 | B.addPatchset() |
| 1904 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1905 | self.waitUntilSettled() |
| 1906 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1907 | self.executor_server.hold_jobs_in_build = False |
| 1908 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1909 | self.waitUntilSettled() |
| 1910 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1911 | self.assertEqual(A.data['status'], 'NEW') |
| 1912 | self.assertEqual(A.reported, 1) |
| 1913 | self.assertEqual(B.data['status'], 'NEW') |
| 1914 | self.assertEqual(B.reported, 1) |
| 1915 | self.assertEqual(C.data['status'], 'NEW') |
| 1916 | self.assertEqual(C.reported, 1) |
| 1917 | self.assertEqual(len(self.history), 10) |
| 1918 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1919 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1920 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1921 | def test_noop_job(self): |
| 1922 | "Test that the internal noop job works" |
| 1923 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1924 | A.addApproval('code-review', 2) |
| 1925 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1926 | self.waitUntilSettled() |
| 1927 | |
| 1928 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1929 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1930 | self.assertEqual(len(self.history), 0) |
| 1931 | self.assertEqual(A.data['status'], 'MERGED') |
| 1932 | self.assertEqual(A.reported, 2) |
| 1933 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 1934 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1935 | def test_no_job_project(self): |
| 1936 | "Test that reports with no jobs don't get sent" |
| 1937 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1938 | 'master', 'A') |
| 1939 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1940 | self.waitUntilSettled() |
| 1941 | |
| 1942 | # Change wasn't reported to |
| 1943 | self.assertEqual(A.reported, False) |
| 1944 | |
| 1945 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1946 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1947 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1948 | items = check_pipeline.getAllItems() |
| 1949 | self.assertEqual(len(items), 0) |
| 1950 | |
| 1951 | self.assertEqual(len(self.history), 0) |
| 1952 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1953 | def test_zuul_refs(self): |
| 1954 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1955 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1956 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1957 | M1.setMerged() |
| 1958 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1959 | M2.setMerged() |
| 1960 | |
| 1961 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1962 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1963 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1964 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1965 | A.addApproval('code-review', 2) |
| 1966 | B.addApproval('code-review', 2) |
| 1967 | C.addApproval('code-review', 2) |
| 1968 | D.addApproval('code-review', 2) |
| 1969 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1970 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1971 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1972 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1973 | |
| 1974 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1975 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1976 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1977 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1978 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1979 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1980 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1981 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1982 | self.waitUntilSettled() |
| 1983 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1984 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1985 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1986 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1987 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1988 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1989 | a_build = x |
| 1990 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1991 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1992 | b_build = x |
| 1993 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1994 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1995 | c_build = x |
| 1996 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1997 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1998 | d_build = x |
| 1999 | if a_build and b_build and c_build and d_build: |
| 2000 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2001 | |
| 2002 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2003 | self.assertIsNotNone(a_zref) |
| 2004 | self.assertIsNotNone(b_zref) |
| 2005 | self.assertIsNotNone(c_zref) |
| 2006 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2007 | |
| 2008 | # And they should all be different |
| 2009 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2010 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2011 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2012 | # should have a, not b, and should not be in project2 |
| 2013 | self.assertTrue(a_build.hasChanges(A)) |
| 2014 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2015 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2016 | # should have a and b, and should not be in project2 |
| 2017 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2018 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2019 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2020 | # should have a and b in 1, c in 2 |
| 2021 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2022 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2023 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2024 | # should have a and b in 1, c and d in 2 |
| 2025 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2026 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2027 | self.executor_server.hold_jobs_in_build = False |
| 2028 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2029 | self.waitUntilSettled() |
| 2030 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2031 | self.assertEqual(A.data['status'], 'MERGED') |
| 2032 | self.assertEqual(A.reported, 2) |
| 2033 | self.assertEqual(B.data['status'], 'MERGED') |
| 2034 | self.assertEqual(B.reported, 2) |
| 2035 | self.assertEqual(C.data['status'], 'MERGED') |
| 2036 | self.assertEqual(C.reported, 2) |
| 2037 | self.assertEqual(D.data['status'], 'MERGED') |
| 2038 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2039 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2040 | def test_rerun_on_error(self): |
| 2041 | "Test that if a worker fails to run a job, it is run again" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2042 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2043 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2044 | A.addApproval('code-review', 2) |
| 2045 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2046 | self.waitUntilSettled() |
| 2047 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2048 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2049 | self.executor_server.hold_jobs_in_build = False |
| 2050 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2051 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2052 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2053 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2054 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2055 | def test_statsd(self): |
| 2056 | "Test each of the statsd methods used in the scheduler" |
| 2057 | import extras |
| 2058 | statsd = extras.try_import('statsd.statsd') |
| 2059 | statsd.incr('test-incr') |
| 2060 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2061 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2062 | self.assertReportedStat('test-incr', '1|c') |
| 2063 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2064 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2065 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2066 | def test_stuck_job_cleanup(self): |
| 2067 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2068 | |
| 2069 | # We want to hold the project-merge job that the fake change enqueues |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2070 | self.gearman_server.hold_jobs_in_queue = True |
| 2071 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2072 | A.addApproval('code-review', 2) |
| 2073 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2074 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2075 | # The assertion is that we have one job in the queue, project-merge |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2076 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2077 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2078 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2079 | self.sched.reconfigure(self.config) |
| 2080 | self.waitUntilSettled() |
| 2081 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2082 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2083 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2084 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2085 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2086 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2087 | |
| 2088 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2089 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2090 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2091 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2092 | def test_file_head(self): |
| 2093 | # This is a regression test for an observed bug. A change |
| 2094 | # with a file named "HEAD" in the root directory of the repo |
| 2095 | # was processed by a merger. It then was unable to reset the |
| 2096 | # repo because of: |
| 2097 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2098 | # with exit code 128 |
| 2099 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2100 | # and filename |
| 2101 | # Use '--' to separate filenames from revisions' |
| 2102 | |
| 2103 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2104 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2105 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2106 | |
| 2107 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2108 | self.waitUntilSettled() |
| 2109 | |
| 2110 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2111 | self.waitUntilSettled() |
| 2112 | |
| 2113 | self.assertIn('Build succeeded', A.messages[0]) |
| 2114 | self.assertIn('Build succeeded', B.messages[0]) |
| 2115 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2116 | def test_file_jobs(self): |
| 2117 | "Test that file jobs run only when appropriate" |
| 2118 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2119 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2120 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2121 | A.addApproval('code-review', 2) |
| 2122 | B.addApproval('code-review', 2) |
| 2123 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2124 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2125 | self.waitUntilSettled() |
| 2126 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2127 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2128 | if x.name == 'project-testfile'] |
| 2129 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2130 | self.assertEqual(len(testfile_jobs), 1) |
| 2131 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2132 | self.assertEqual(A.data['status'], 'MERGED') |
| 2133 | self.assertEqual(A.reported, 2) |
| 2134 | self.assertEqual(B.data['status'], 'MERGED') |
| 2135 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2136 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2137 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2138 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2139 | if should_skip: |
| 2140 | files = {'ignoreme': 'ignored\n'} |
| 2141 | else: |
| 2142 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2143 | |
| 2144 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2145 | 'master', |
| 2146 | 'test irrelevant-files', |
| 2147 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2148 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2149 | self.waitUntilSettled() |
| 2150 | |
| 2151 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2152 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2153 | |
| 2154 | if should_skip: |
| 2155 | self.assertEqual([], tested_change_ids) |
| 2156 | else: |
| 2157 | self.assertIn(change.data['number'], tested_change_ids) |
| 2158 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2159 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2160 | def test_irrelevant_files_match_skips_job(self): |
| 2161 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2162 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2163 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2164 | def test_irrelevant_files_no_match_runs_job(self): |
| 2165 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2166 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2167 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2168 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2169 | files = {'ignoreme': 'ignored\n'} |
| 2170 | |
| 2171 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2172 | 'master', |
| 2173 | 'test irrelevant-files', |
| 2174 | files=files) |
| 2175 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2176 | self.waitUntilSettled() |
| 2177 | |
| 2178 | run_jobs = set([build.name for build in self.history]) |
| 2179 | |
| 2180 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2181 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2182 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2183 | def test_queue_names(self): |
| 2184 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2185 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2186 | (trusted, project1) = tenant.getProject('org/project1') |
| 2187 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2188 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2189 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2190 | self.assertEqual(q1.name, 'integrated') |
| 2191 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2192 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2193 | def test_queue_precedence(self): |
| 2194 | "Test that queue precedence works" |
| 2195 | |
| 2196 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2197 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2198 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2199 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2200 | A.addApproval('code-review', 2) |
| 2201 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2202 | |
| 2203 | self.waitUntilSettled() |
| 2204 | self.gearman_server.hold_jobs_in_queue = False |
| 2205 | self.gearman_server.release() |
| 2206 | self.waitUntilSettled() |
| 2207 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2208 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2209 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2210 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2211 | self.waitUntilSettled() |
| 2212 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2213 | self.log.debug(self.history) |
| 2214 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2215 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2216 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2217 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2218 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2219 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2220 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2221 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2222 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2223 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2224 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2225 | A.addApproval('code-review', 2) |
| 2226 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2227 | self.waitUntilSettled() |
| 2228 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2229 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2230 | self.waitUntilSettled() |
| 2231 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2232 | port = self.webapp.server.socket.getsockname()[1] |
| 2233 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2234 | req = urllib.request.Request( |
| 2235 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2236 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2237 | headers = f.info() |
| 2238 | self.assertIn('Content-Length', headers) |
| 2239 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2240 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2241 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2242 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2243 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2244 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2245 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2246 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2247 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2248 | self.executor_server.hold_jobs_in_build = False |
| 2249 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2250 | self.waitUntilSettled() |
| 2251 | |
| 2252 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2253 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2254 | for p in data['pipelines']: |
| 2255 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2256 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2257 | self.assertEqual(q['window'], 20) |
| 2258 | else: |
| 2259 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2260 | for head in q['heads']: |
| 2261 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2262 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2263 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2264 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2265 | status_jobs.append(job) |
| 2266 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2267 | self.assertEqual('https://server/job/project-merge/0/', |
| 2268 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2269 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2270 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2271 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2272 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2273 | status_jobs[1]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2274 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2275 | status_jobs[1]['report_url']) |
| 2276 | |
| 2277 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2278 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2279 | status_jobs[2]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2280 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2281 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2282 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2283 | def test_live_reconfiguration(self): |
| 2284 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2285 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2286 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2287 | A.addApproval('code-review', 2) |
| 2288 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2289 | self.waitUntilSettled() |
| 2290 | |
| 2291 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2292 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2293 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2294 | self.executor_server.hold_jobs_in_build = False |
| 2295 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2296 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2297 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2298 | 'SUCCESS') |
| 2299 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2300 | 'SUCCESS') |
| 2301 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2302 | 'SUCCESS') |
| 2303 | self.assertEqual(A.data['status'], 'MERGED') |
| 2304 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2305 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2306 | def test_live_reconfiguration_merge_conflict(self): |
| 2307 | # A real-world bug: a change in a gate queue has a merge |
| 2308 | # conflict and a job is added to its project while it's |
| 2309 | # sitting in the queue. The job gets added to the change and |
| 2310 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2311 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2312 | |
| 2313 | # This change is fine. It's here to stop the queue long |
| 2314 | # enough for the next change to be subject to the |
| 2315 | # reconfiguration, as well as to provide a conflict for the |
| 2316 | # next change. This change will succeed and merge. |
| 2317 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2318 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2319 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2320 | |
| 2321 | # This change will be in merge conflict. During the |
| 2322 | # reconfiguration, we will add a job. We want to make sure |
| 2323 | # that doesn't cause it to get stuck. |
| 2324 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2325 | B.addPatchset({'conflict': 'B'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2326 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2327 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2328 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2329 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2330 | |
| 2331 | self.waitUntilSettled() |
| 2332 | |
| 2333 | # No jobs have run yet |
| 2334 | self.assertEqual(A.data['status'], 'NEW') |
| 2335 | self.assertEqual(A.reported, 1) |
| 2336 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2337 | self.assertEqual(len(self.history), 0) |
| 2338 | |
| 2339 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2340 | self.commitConfigUpdate('common-config', |
| 2341 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2342 | self.sched.reconfigure(self.config) |
| 2343 | self.waitUntilSettled() |
| 2344 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2345 | self.executor_server.hold_jobs_in_build = False |
| 2346 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2347 | self.waitUntilSettled() |
| 2348 | |
| 2349 | self.assertEqual(A.data['status'], 'MERGED') |
| 2350 | self.assertEqual(A.reported, 2) |
| 2351 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2352 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2353 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2354 | 'SUCCESS') |
| 2355 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2356 | 'SUCCESS') |
| 2357 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2358 | 'SUCCESS') |
| 2359 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2360 | 'SUCCESS') |
| 2361 | self.assertEqual(len(self.history), 4) |
| 2362 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2363 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2364 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2365 | # that tests a job added to a job tree with a failed root does |
| 2366 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2367 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2368 | |
| 2369 | # This change is fine. It's here to stop the queue long |
| 2370 | # enough for the next change to be subject to the |
| 2371 | # reconfiguration. This change will succeed and merge. |
| 2372 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2373 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2374 | A.addApproval('code-review', 2) |
| 2375 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2376 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2377 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2378 | self.waitUntilSettled() |
| 2379 | |
| 2380 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2381 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2382 | B.addApproval('code-review', 2) |
| 2383 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2384 | self.waitUntilSettled() |
| 2385 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2386 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2387 | self.waitUntilSettled() |
| 2388 | |
| 2389 | # Both -merge jobs have run, but no others. |
| 2390 | self.assertEqual(A.data['status'], 'NEW') |
| 2391 | self.assertEqual(A.reported, 1) |
| 2392 | self.assertEqual(B.data['status'], 'NEW') |
| 2393 | self.assertEqual(B.reported, 1) |
| 2394 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2395 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2396 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2397 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2398 | self.assertEqual(len(self.history), 2) |
| 2399 | |
| 2400 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2401 | self.commitConfigUpdate('common-config', |
| 2402 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2403 | self.sched.reconfigure(self.config) |
| 2404 | self.waitUntilSettled() |
| 2405 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2406 | self.executor_server.hold_jobs_in_build = False |
| 2407 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2408 | self.waitUntilSettled() |
| 2409 | |
| 2410 | self.assertEqual(A.data['status'], 'MERGED') |
| 2411 | self.assertEqual(A.reported, 2) |
| 2412 | self.assertEqual(B.data['status'], 'NEW') |
| 2413 | self.assertEqual(B.reported, 2) |
| 2414 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2415 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2416 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2417 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2418 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2419 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2420 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2421 | self.assertEqual(len(self.history), 5) |
| 2422 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2423 | def test_live_reconfiguration_failed_job(self): |
| 2424 | # Test that a change with a removed failing job does not |
| 2425 | # disrupt reconfiguration. If a change has a failed job and |
| 2426 | # that job is removed during a reconfiguration, we observed a |
| 2427 | # bug where the code to re-set build statuses would run on |
| 2428 | # that build and raise an exception because the job no longer |
| 2429 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2430 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2431 | |
| 2432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2433 | |
| 2434 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2435 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2436 | |
| 2437 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2438 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2439 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2440 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2441 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2442 | self.waitUntilSettled() |
| 2443 | |
| 2444 | self.assertEqual(A.data['status'], 'NEW') |
| 2445 | self.assertEqual(A.reported, 0) |
| 2446 | |
| 2447 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2448 | 'SUCCESS') |
| 2449 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2450 | 'FAILURE') |
| 2451 | self.assertEqual(len(self.history), 2) |
| 2452 | |
| 2453 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2454 | self.commitConfigUpdate('common-config', |
| 2455 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2456 | self.sched.reconfigure(self.config) |
| 2457 | self.waitUntilSettled() |
| 2458 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2459 | self.executor_server.hold_jobs_in_build = False |
| 2460 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2461 | self.waitUntilSettled() |
| 2462 | |
| 2463 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2464 | 'SUCCESS') |
| 2465 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2466 | 'SUCCESS') |
| 2467 | self.assertEqual(len(self.history), 4) |
| 2468 | |
| 2469 | self.assertEqual(A.data['status'], 'NEW') |
| 2470 | self.assertEqual(A.reported, 1) |
| 2471 | self.assertIn('Build succeeded', A.messages[0]) |
| 2472 | # Ensure the removed job was not included in the report. |
| 2473 | self.assertNotIn('project-test1', A.messages[0]) |
| 2474 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2475 | def test_live_reconfiguration_shared_queue(self): |
| 2476 | # Test that a change with a failing job which was removed from |
| 2477 | # this project but otherwise still exists in the system does |
| 2478 | # not disrupt reconfiguration. |
| 2479 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2480 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2481 | |
| 2482 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2483 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2484 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2485 | |
| 2486 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2487 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2488 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2489 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2490 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2491 | self.waitUntilSettled() |
| 2492 | |
| 2493 | self.assertEqual(A.data['status'], 'NEW') |
| 2494 | self.assertEqual(A.reported, 0) |
| 2495 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2496 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2497 | 'SUCCESS') |
| 2498 | self.assertEqual(self.getJobFromHistory( |
| 2499 | 'project1-project2-integration').result, 'FAILURE') |
| 2500 | self.assertEqual(len(self.history), 2) |
| 2501 | |
| 2502 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2503 | self.commitConfigUpdate( |
| 2504 | 'common-config', |
| 2505 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2506 | self.sched.reconfigure(self.config) |
| 2507 | self.waitUntilSettled() |
| 2508 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2509 | self.executor_server.hold_jobs_in_build = False |
| 2510 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2511 | self.waitUntilSettled() |
| 2512 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2513 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2514 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2515 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2516 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2517 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2518 | 'SUCCESS') |
| 2519 | self.assertEqual(self.getJobFromHistory( |
| 2520 | 'project1-project2-integration').result, 'FAILURE') |
| 2521 | self.assertEqual(len(self.history), 4) |
| 2522 | |
| 2523 | self.assertEqual(A.data['status'], 'NEW') |
| 2524 | self.assertEqual(A.reported, 1) |
| 2525 | self.assertIn('Build succeeded', A.messages[0]) |
| 2526 | # Ensure the removed job was not included in the report. |
| 2527 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2528 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2529 | def test_double_live_reconfiguration_shared_queue(self): |
| 2530 | # This was a real-world regression. A change is added to |
| 2531 | # gate; a reconfigure happens, a second change which depends |
| 2532 | # on the first is added, and a second reconfiguration happens. |
| 2533 | # Ensure that both changes merge. |
| 2534 | |
| 2535 | # A failure may indicate incorrect caching or cleaning up of |
| 2536 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2537 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2538 | |
| 2539 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2540 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2541 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2542 | A.addApproval('code-review', 2) |
| 2543 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2544 | |
| 2545 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2546 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2547 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2548 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2549 | self.waitUntilSettled() |
| 2550 | |
| 2551 | # Reconfigure (with only one change in the pipeline). |
| 2552 | self.sched.reconfigure(self.config) |
| 2553 | self.waitUntilSettled() |
| 2554 | |
| 2555 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2556 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2557 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2558 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2559 | self.waitUntilSettled() |
| 2560 | |
| 2561 | # Reconfigure (with both in the pipeline). |
| 2562 | self.sched.reconfigure(self.config) |
| 2563 | self.waitUntilSettled() |
| 2564 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2565 | self.executor_server.hold_jobs_in_build = False |
| 2566 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2567 | self.waitUntilSettled() |
| 2568 | |
| 2569 | self.assertEqual(len(self.history), 8) |
| 2570 | |
| 2571 | self.assertEqual(A.data['status'], 'MERGED') |
| 2572 | self.assertEqual(A.reported, 2) |
| 2573 | self.assertEqual(B.data['status'], 'MERGED') |
| 2574 | self.assertEqual(B.reported, 2) |
| 2575 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2576 | def test_live_reconfiguration_del_project(self): |
| 2577 | # Test project deletion from layout |
| 2578 | # while changes are enqueued |
| 2579 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2580 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2582 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2583 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2584 | |
| 2585 | # A Depends-On: B |
| 2586 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2587 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2588 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2589 | |
| 2590 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2591 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2592 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2593 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2594 | self.waitUntilSettled() |
| 2595 | self.assertEqual(len(self.builds), 5) |
| 2596 | |
| 2597 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2598 | self.commitConfigUpdate( |
| 2599 | 'common-config', |
| 2600 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2601 | self.sched.reconfigure(self.config) |
| 2602 | self.waitUntilSettled() |
| 2603 | |
| 2604 | # Builds for C aborted, builds for A succeed, |
| 2605 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2606 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2607 | self.assertEqual(job_c.changes, '3,1') |
| 2608 | self.assertEqual(job_c.result, 'ABORTED') |
| 2609 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2610 | self.executor_server.hold_jobs_in_build = False |
| 2611 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2612 | self.waitUntilSettled() |
| 2613 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2614 | self.assertEqual( |
| 2615 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2616 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2617 | |
| 2618 | self.assertEqual(A.data['status'], 'NEW') |
| 2619 | self.assertEqual(B.data['status'], 'NEW') |
| 2620 | self.assertEqual(C.data['status'], 'NEW') |
| 2621 | self.assertEqual(A.reported, 1) |
| 2622 | self.assertEqual(B.reported, 0) |
| 2623 | self.assertEqual(C.reported, 0) |
| 2624 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2625 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2626 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2627 | self.assertIn('Build succeeded', A.messages[0]) |
| 2628 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2629 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2630 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2631 | self.updateConfigLayout( |
| 2632 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2633 | self.sched.reconfigure(self.config) |
| 2634 | |
| 2635 | self.init_repo("org/new-project") |
| 2636 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2637 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2638 | A.addApproval('code-review', 2) |
| 2639 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2640 | self.waitUntilSettled() |
| 2641 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2642 | 'SUCCESS') |
| 2643 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2644 | 'SUCCESS') |
| 2645 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2646 | 'SUCCESS') |
| 2647 | self.assertEqual(A.data['status'], 'MERGED') |
| 2648 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2649 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2650 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2651 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2652 | self.init_repo("org/delete-project") |
| 2653 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2654 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2655 | A.addApproval('code-review', 2) |
| 2656 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2657 | self.waitUntilSettled() |
| 2658 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2659 | 'SUCCESS') |
| 2660 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2661 | 'SUCCESS') |
| 2662 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2663 | 'SUCCESS') |
| 2664 | self.assertEqual(A.data['status'], 'MERGED') |
| 2665 | self.assertEqual(A.reported, 2) |
| 2666 | |
| 2667 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2668 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2669 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2670 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2671 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2672 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2673 | |
| 2674 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2675 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2676 | B.addApproval('code-review', 2) |
| 2677 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2678 | self.waitUntilSettled() |
| 2679 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2680 | 'SUCCESS') |
| 2681 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2682 | 'SUCCESS') |
| 2683 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2684 | 'SUCCESS') |
| 2685 | self.assertEqual(B.data['status'], 'MERGED') |
| 2686 | self.assertEqual(B.reported, 2) |
| 2687 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2688 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2689 | def test_tags(self): |
| 2690 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2691 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2692 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2693 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2694 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2695 | self.waitUntilSettled() |
| 2696 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2697 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2698 | |
| 2699 | results = {self.getJobFromHistory('merge', |
| 2700 | project='org/project1').uuid: 'extratag merge', |
| 2701 | self.getJobFromHistory('merge', |
| 2702 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2703 | |
| 2704 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2705 | self.assertEqual(results.get(build.uuid, ''), |
| 2706 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2707 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2708 | def test_timer(self): |
| 2709 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2710 | # This test can not use simple_layout because it must start |
| 2711 | # with a configuration which does not include a |
| 2712 | # timer-triggered job so that we have an opportunity to set |
| 2713 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2714 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2715 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2716 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2717 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2718 | # The pipeline triggers every second, so we should have seen |
| 2719 | # several by now. |
| 2720 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2721 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2722 | |
| 2723 | self.assertEqual(len(self.builds), 2) |
| 2724 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2725 | port = self.webapp.server.socket.getsockname()[1] |
| 2726 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2727 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2728 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2729 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2730 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2731 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2732 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2733 | # Stop queuing timer triggered jobs so that the assertions |
| 2734 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2735 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2736 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2737 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2738 | self.waitUntilSettled() |
| 2739 | |
| 2740 | self.assertEqual(self.getJobFromHistory( |
| 2741 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2742 | self.assertEqual(self.getJobFromHistory( |
| 2743 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2744 | |
| 2745 | data = json.loads(data) |
| 2746 | status_jobs = set() |
| 2747 | for p in data['pipelines']: |
| 2748 | for q in p['change_queues']: |
| 2749 | for head in q['heads']: |
| 2750 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2751 | for job in change['jobs']: |
| 2752 | status_jobs.add(job['name']) |
| 2753 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2754 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2755 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2756 | def test_idle(self): |
| 2757 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2758 | # This test can not use simple_layout because it must start |
| 2759 | # with a configuration which does not include a |
| 2760 | # timer-triggered job so that we have an opportunity to set |
| 2761 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2762 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2763 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2764 | for x in range(1, 3): |
| 2765 | # Test that timer triggers periodic jobs even across |
| 2766 | # layout config reloads. |
| 2767 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2768 | self.commitConfigUpdate('common-config', |
| 2769 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2770 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2771 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2772 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2773 | # The pipeline triggers every second, so we should have seen |
| 2774 | # several by now. |
| 2775 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2776 | |
| 2777 | # Stop queuing timer triggered jobs so that the assertions |
| 2778 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2779 | self.commitConfigUpdate('common-config', |
| 2780 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2781 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2782 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2783 | self.assertEqual(len(self.builds), 2, |
| 2784 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2785 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2786 | self.waitUntilSettled() |
| 2787 | self.assertEqual(len(self.builds), 0) |
| 2788 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2789 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2790 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2791 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2792 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2793 | self.waitUntilSettled() |
| 2794 | |
| 2795 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2796 | self.waitUntilSettled() |
| 2797 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2798 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2799 | |
| 2800 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2801 | # work on the knowledge of what the first message should be as |
| 2802 | # it is only configured to go to SMTP. |
| 2803 | |
| 2804 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2805 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2806 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2807 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2808 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2809 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2810 | |
| 2811 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2812 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2813 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2814 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2815 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2816 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2817 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2818 | def test_timer_smtp(self): |
| 2819 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2820 | # This test can not use simple_layout because it must start |
| 2821 | # with a configuration which does not include a |
| 2822 | # timer-triggered job so that we have an opportunity to set |
| 2823 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2824 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2825 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2826 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2827 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2828 | # The pipeline triggers every second, so we should have seen |
| 2829 | # several by now. |
| 2830 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2831 | self.waitUntilSettled() |
| 2832 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2833 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2834 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2835 | self.waitUntilSettled() |
| 2836 | self.assertEqual(len(self.history), 2) |
| 2837 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2838 | self.assertEqual(self.getJobFromHistory( |
| 2839 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2840 | self.assertEqual(self.getJobFromHistory( |
| 2841 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2842 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2843 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2844 | |
| 2845 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2846 | # work on the knowledge of what the first message should be as |
| 2847 | # it is only configured to go to SMTP. |
| 2848 | |
| 2849 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2850 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2851 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2852 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2853 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2854 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2855 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2856 | # Stop queuing timer triggered jobs and let any that may have |
| 2857 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2858 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2859 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2860 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2861 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2862 | self.waitUntilSettled() |
| 2863 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 2864 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 2865 | def test_timer_sshkey(self): |
| 2866 | "Test that a periodic job can setup SSH key authentication" |
| 2867 | self.worker.hold_jobs_in_build = True |
| 2868 | self.config.set('zuul', 'layout_config', |
| 2869 | 'tests/fixtures/layout-timer.yaml') |
| 2870 | self.sched.reconfigure(self.config) |
| 2871 | self.registerJobs() |
| 2872 | |
| 2873 | # The pipeline triggers every second, so we should have seen |
| 2874 | # several by now. |
| 2875 | time.sleep(5) |
| 2876 | self.waitUntilSettled() |
| 2877 | |
| 2878 | self.assertEqual(len(self.builds), 2) |
| 2879 | |
| 2880 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 2881 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 2882 | with open(ssh_wrapper) as f: |
| 2883 | ssh_wrapper_content = f.read() |
| 2884 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 2885 | # In the unit tests Merger runs in the same process, |
| 2886 | # so we see its' environment variables |
| 2887 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 2888 | |
| 2889 | self.worker.release('.*') |
| 2890 | self.waitUntilSettled() |
| 2891 | self.assertEqual(len(self.history), 2) |
| 2892 | |
| 2893 | self.assertEqual(self.getJobFromHistory( |
| 2894 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2895 | self.assertEqual(self.getJobFromHistory( |
| 2896 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2897 | |
| 2898 | # Stop queuing timer triggered jobs and let any that may have |
| 2899 | # queued through so that end of test assertions pass. |
| 2900 | self.config.set('zuul', 'layout_config', |
| 2901 | 'tests/fixtures/layout-no-timer.yaml') |
| 2902 | self.sched.reconfigure(self.config) |
| 2903 | self.registerJobs() |
| 2904 | self.waitUntilSettled() |
| 2905 | self.worker.release('.*') |
| 2906 | self.waitUntilSettled() |
| 2907 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2908 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2909 | "Test that the RPC client can enqueue a change" |
| 2910 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2911 | A.addApproval('code-review', 2) |
| 2912 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2913 | |
| 2914 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2915 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2916 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2917 | r = client.enqueue(tenant='tenant-one', |
| 2918 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2919 | project='org/project', |
| 2920 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2921 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2922 | self.waitUntilSettled() |
| 2923 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2924 | 'SUCCESS') |
| 2925 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2926 | 'SUCCESS') |
| 2927 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2928 | 'SUCCESS') |
| 2929 | self.assertEqual(A.data['status'], 'MERGED') |
| 2930 | self.assertEqual(A.reported, 2) |
| 2931 | self.assertEqual(r, True) |
| 2932 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2933 | def test_client_enqueue_ref(self): |
| 2934 | "Test that the RPC client can enqueue a ref" |
| 2935 | |
| 2936 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2937 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2938 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2939 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2940 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2941 | pipeline='post', |
| 2942 | project='org/project', |
| 2943 | trigger='gerrit', |
| 2944 | ref='master', |
| 2945 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2946 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2947 | self.waitUntilSettled() |
| 2948 | job_names = [x.name for x in self.history] |
| 2949 | self.assertEqual(len(self.history), 1) |
| 2950 | self.assertIn('project-post', job_names) |
| 2951 | self.assertEqual(r, True) |
| 2952 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2953 | def test_client_enqueue_negative(self): |
| 2954 | "Test that the RPC client returns errors" |
| 2955 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2956 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2957 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2958 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2959 | "Invalid tenant"): |
| 2960 | r = client.enqueue(tenant='tenant-foo', |
| 2961 | pipeline='gate', |
| 2962 | project='org/project', |
| 2963 | trigger='gerrit', |
| 2964 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2965 | self.assertEqual(r, False) |
| 2966 | |
| 2967 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2968 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2969 | r = client.enqueue(tenant='tenant-one', |
| 2970 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2971 | project='project-does-not-exist', |
| 2972 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2973 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2974 | self.assertEqual(r, False) |
| 2975 | |
| 2976 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2977 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2978 | r = client.enqueue(tenant='tenant-one', |
| 2979 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2980 | project='org/project', |
| 2981 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2982 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2983 | self.assertEqual(r, False) |
| 2984 | |
| 2985 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2986 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2987 | r = client.enqueue(tenant='tenant-one', |
| 2988 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2989 | project='org/project', |
| 2990 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2991 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2992 | self.assertEqual(r, False) |
| 2993 | |
| 2994 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2995 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2996 | r = client.enqueue(tenant='tenant-one', |
| 2997 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2998 | project='org/project', |
| 2999 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3000 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3001 | self.assertEqual(r, False) |
| 3002 | |
| 3003 | self.waitUntilSettled() |
| 3004 | self.assertEqual(len(self.history), 0) |
| 3005 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3006 | |
| 3007 | def test_client_promote(self): |
| 3008 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3009 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3010 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3011 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3012 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3013 | A.addApproval('code-review', 2) |
| 3014 | B.addApproval('code-review', 2) |
| 3015 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3016 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3017 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3018 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3019 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3020 | |
| 3021 | self.waitUntilSettled() |
| 3022 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3023 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3024 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3025 | enqueue_times = {} |
| 3026 | for item in items: |
| 3027 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3028 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3029 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3030 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3031 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3032 | r = client.promote(tenant='tenant-one', |
| 3033 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3034 | change_ids=['2,1', '3,1']) |
| 3035 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3036 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3037 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3038 | for item in items: |
| 3039 | self.assertEqual( |
| 3040 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3041 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3042 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3043 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3044 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3045 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3046 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3047 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3048 | self.waitUntilSettled() |
| 3049 | |
| 3050 | self.assertEqual(len(self.builds), 6) |
| 3051 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3052 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3053 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3054 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3055 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3056 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3057 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3058 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3059 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3060 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3061 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3062 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3063 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3064 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3065 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3066 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3067 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3068 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3069 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3070 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3071 | self.waitUntilSettled() |
| 3072 | |
| 3073 | self.assertEqual(A.data['status'], 'MERGED') |
| 3074 | self.assertEqual(A.reported, 2) |
| 3075 | self.assertEqual(B.data['status'], 'MERGED') |
| 3076 | self.assertEqual(B.reported, 2) |
| 3077 | self.assertEqual(C.data['status'], 'MERGED') |
| 3078 | self.assertEqual(C.reported, 2) |
| 3079 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3080 | self.assertEqual(r, True) |
| 3081 | |
| 3082 | def test_client_promote_dependent(self): |
| 3083 | "Test that the RPC client can promote a dependent change" |
| 3084 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3085 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3086 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3088 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3089 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3090 | |
| 3091 | C.setDependsOn(B, 1) |
| 3092 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3093 | A.addApproval('code-review', 2) |
| 3094 | B.addApproval('code-review', 2) |
| 3095 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3096 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3097 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3098 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3099 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3100 | |
| 3101 | self.waitUntilSettled() |
| 3102 | |
| 3103 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3104 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3105 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3106 | r = client.promote(tenant='tenant-one', |
| 3107 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3108 | change_ids=['3,1']) |
| 3109 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3110 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3111 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3112 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3113 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3114 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3115 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3116 | self.waitUntilSettled() |
| 3117 | |
| 3118 | self.assertEqual(len(self.builds), 6) |
| 3119 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3120 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3121 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3122 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3123 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3124 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3125 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3126 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3127 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3128 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3129 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3130 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3131 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3132 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3133 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3134 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3135 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3136 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3137 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3138 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3139 | self.waitUntilSettled() |
| 3140 | |
| 3141 | self.assertEqual(A.data['status'], 'MERGED') |
| 3142 | self.assertEqual(A.reported, 2) |
| 3143 | self.assertEqual(B.data['status'], 'MERGED') |
| 3144 | self.assertEqual(B.reported, 2) |
| 3145 | self.assertEqual(C.data['status'], 'MERGED') |
| 3146 | self.assertEqual(C.reported, 2) |
| 3147 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3148 | self.assertEqual(r, True) |
| 3149 | |
| 3150 | def test_client_promote_negative(self): |
| 3151 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3152 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3153 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3154 | A.addApproval('code-review', 2) |
| 3155 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3156 | self.waitUntilSettled() |
| 3157 | |
| 3158 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3159 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3160 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3161 | |
| 3162 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3163 | r = client.promote(tenant='tenant-one', |
| 3164 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3166 | self.assertEqual(r, False) |
| 3167 | |
| 3168 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3169 | r = client.promote(tenant='tenant-one', |
| 3170 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3171 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3172 | self.assertEqual(r, False) |
| 3173 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3174 | self.executor_server.hold_jobs_in_build = False |
| 3175 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3176 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3177 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3178 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3179 | def test_queue_rate_limiting(self): |
| 3180 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3181 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3182 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3183 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3184 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3185 | |
| 3186 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3187 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3188 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3189 | A.addApproval('code-review', 2) |
| 3190 | B.addApproval('code-review', 2) |
| 3191 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3192 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3193 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3194 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3195 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3196 | self.waitUntilSettled() |
| 3197 | |
| 3198 | # Only A and B will have their merge jobs queued because |
| 3199 | # window is 2. |
| 3200 | self.assertEqual(len(self.builds), 2) |
| 3201 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3202 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3203 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3204 | # Release the merge jobs one at a time. |
| 3205 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3206 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3207 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3208 | self.waitUntilSettled() |
| 3209 | |
| 3210 | # Only A and B will have their test jobs queued because |
| 3211 | # window is 2. |
| 3212 | self.assertEqual(len(self.builds), 4) |
| 3213 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3214 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3215 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3216 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3217 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3218 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3219 | self.waitUntilSettled() |
| 3220 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3221 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3222 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3223 | # A failed so window is reduced by 1 to 1. |
| 3224 | self.assertEqual(queue.window, 1) |
| 3225 | self.assertEqual(queue.window_floor, 1) |
| 3226 | self.assertEqual(A.data['status'], 'NEW') |
| 3227 | |
| 3228 | # Gate is reset and only B's merge job is queued because |
| 3229 | # window shrunk to 1. |
| 3230 | self.assertEqual(len(self.builds), 1) |
| 3231 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3232 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3233 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3234 | self.waitUntilSettled() |
| 3235 | |
| 3236 | # Only B's test jobs are queued because window is still 1. |
| 3237 | self.assertEqual(len(self.builds), 2) |
| 3238 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3239 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3240 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3241 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3242 | self.waitUntilSettled() |
| 3243 | |
| 3244 | # B was successfully merged so window is increased to 2. |
| 3245 | self.assertEqual(queue.window, 2) |
| 3246 | self.assertEqual(queue.window_floor, 1) |
| 3247 | self.assertEqual(B.data['status'], 'MERGED') |
| 3248 | |
| 3249 | # Only C is left and its merge job is queued. |
| 3250 | self.assertEqual(len(self.builds), 1) |
| 3251 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3252 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3253 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3254 | self.waitUntilSettled() |
| 3255 | |
| 3256 | # After successful merge job the test jobs for C are queued. |
| 3257 | self.assertEqual(len(self.builds), 2) |
| 3258 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3259 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3260 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3261 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3262 | self.waitUntilSettled() |
| 3263 | |
| 3264 | # C successfully merged so window is bumped to 3. |
| 3265 | self.assertEqual(queue.window, 3) |
| 3266 | self.assertEqual(queue.window_floor, 1) |
| 3267 | self.assertEqual(C.data['status'], 'MERGED') |
| 3268 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3269 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3270 | def test_queue_rate_limiting_dependent(self): |
| 3271 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3272 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3273 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3274 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3275 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3276 | |
| 3277 | B.setDependsOn(A, 1) |
| 3278 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3279 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3280 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3281 | A.addApproval('code-review', 2) |
| 3282 | B.addApproval('code-review', 2) |
| 3283 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3284 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3285 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3286 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3287 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3288 | self.waitUntilSettled() |
| 3289 | |
| 3290 | # Only A and B will have their merge jobs queued because |
| 3291 | # window is 2. |
| 3292 | self.assertEqual(len(self.builds), 2) |
| 3293 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3294 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3295 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3296 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3297 | |
| 3298 | # Only A and B will have their test jobs queued because |
| 3299 | # window is 2. |
| 3300 | self.assertEqual(len(self.builds), 4) |
| 3301 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3302 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3303 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3304 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3305 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3306 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3307 | self.waitUntilSettled() |
| 3308 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3309 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3310 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3311 | # A failed so window is reduced by 1 to 1. |
| 3312 | self.assertEqual(queue.window, 1) |
| 3313 | self.assertEqual(queue.window_floor, 1) |
| 3314 | self.assertEqual(A.data['status'], 'NEW') |
| 3315 | self.assertEqual(B.data['status'], 'NEW') |
| 3316 | |
| 3317 | # Gate is reset and only C's merge job is queued because |
| 3318 | # window shrunk to 1 and A and B were dequeued. |
| 3319 | self.assertEqual(len(self.builds), 1) |
| 3320 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3321 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3322 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3323 | |
| 3324 | # Only C's test jobs are queued because window is still 1. |
| 3325 | self.assertEqual(len(self.builds), 2) |
| 3326 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3327 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3328 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3329 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3330 | self.waitUntilSettled() |
| 3331 | |
| 3332 | # C was successfully merged so window is increased to 2. |
| 3333 | self.assertEqual(queue.window, 2) |
| 3334 | self.assertEqual(queue.window_floor, 1) |
| 3335 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3336 | |
| 3337 | def test_worker_update_metadata(self): |
| 3338 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3339 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3340 | |
| 3341 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3342 | A.addApproval('code-review', 2) |
| 3343 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3344 | self.waitUntilSettled() |
| 3345 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3346 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3347 | |
| 3348 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3349 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3350 | |
| 3351 | start = time.time() |
| 3352 | while True: |
| 3353 | if time.time() - start > 10: |
| 3354 | raise Exception("Timeout waiting for gearman server to report " |
| 3355 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3356 | build = list(self.executor_client.builds.values())[0] |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3357 | if build.worker.name == "My Worker": |
| 3358 | break |
| 3359 | else: |
| 3360 | time.sleep(0) |
| 3361 | |
| 3362 | self.log.debug(build) |
| 3363 | self.assertEqual("My Worker", build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3364 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3365 | self.executor_server.hold_jobs_in_build = False |
| 3366 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3367 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3368 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3369 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3370 | def test_footer_message(self): |
| 3371 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3372 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3373 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3374 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3375 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3376 | self.waitUntilSettled() |
| 3377 | |
| 3378 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3379 | B.addApproval('code-review', 2) |
| 3380 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3381 | self.waitUntilSettled() |
| 3382 | |
| 3383 | self.assertEqual(2, len(self.smtp_messages)) |
| 3384 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3385 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3386 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3387 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3388 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3389 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3390 | For CI problems and help debugging, contact ci@example.org""" |
| 3391 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3392 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3393 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3394 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3395 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3396 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3397 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3398 | def test_unmanaged_project_start_message(self): |
| 3399 | "Test start reporting is not done for unmanaged projects." |
| 3400 | self.init_repo("org/project", tag='init') |
| 3401 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3402 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3403 | self.waitUntilSettled() |
| 3404 | |
| 3405 | self.assertEqual(0, len(A.messages)) |
| 3406 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3407 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3408 | def test_merge_failure_reporters(self): |
| 3409 | """Check that the config is set up correctly""" |
| 3410 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3411 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3412 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3413 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3414 | "dependencies was unable to be automatically merged with the " |
| 3415 | "current state of its repository. Please rebase the change and " |
| 3416 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3417 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3418 | self.assertEqual( |
| 3419 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3420 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3421 | |
| 3422 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3423 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3424 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3425 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3426 | |
| 3427 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3428 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3429 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3430 | |
| 3431 | self.assertTrue( |
| 3432 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3433 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3434 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3435 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3436 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3437 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3438 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3439 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3440 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3441 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3442 | gerritreporter.GerritReporter) and |
| 3443 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3444 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame^] | 3445 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3446 | ) |
| 3447 | ) |
| 3448 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3449 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3450 | def test_merge_failure_reports(self): |
| 3451 | """Check that when a change fails to merge the correct message is sent |
| 3452 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3453 | self.updateConfigLayout( |
| 3454 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3455 | self.sched.reconfigure(self.config) |
| 3456 | self.registerJobs() |
| 3457 | |
| 3458 | # Check a test failure isn't reported to SMTP |
| 3459 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3460 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3461 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3462 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3463 | self.waitUntilSettled() |
| 3464 | |
| 3465 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3466 | self.assertEqual(0, len(self.smtp_messages)) |
| 3467 | |
| 3468 | # Check a merge failure is reported to SMTP |
| 3469 | # B should be merged, but C will conflict with B |
| 3470 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3471 | B.addPatchset(['conflict']) |
| 3472 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3473 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3474 | B.addApproval('code-review', 2) |
| 3475 | C.addApproval('code-review', 2) |
| 3476 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3477 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3478 | self.waitUntilSettled() |
| 3479 | |
| 3480 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3481 | self.assertEqual(1, len(self.smtp_messages)) |
| 3482 | self.assertEqual('The merge failed! For more information...', |
| 3483 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3484 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3485 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3486 | def test_default_merge_failure_reports(self): |
| 3487 | """Check that the default merge failure reports are correct.""" |
| 3488 | |
| 3489 | # A should report success, B should report merge failure. |
| 3490 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3491 | A.addPatchset(['conflict']) |
| 3492 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3493 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3494 | A.addApproval('code-review', 2) |
| 3495 | B.addApproval('code-review', 2) |
| 3496 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3497 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3498 | self.waitUntilSettled() |
| 3499 | |
| 3500 | self.assertEqual(3, len(self.history)) # A jobs |
| 3501 | self.assertEqual(A.reported, 2) |
| 3502 | self.assertEqual(B.reported, 2) |
| 3503 | self.assertEqual(A.data['status'], 'MERGED') |
| 3504 | self.assertEqual(B.data['status'], 'NEW') |
| 3505 | self.assertIn('Build succeeded', A.messages[1]) |
| 3506 | self.assertIn('Merge Failed', B.messages[1]) |
| 3507 | self.assertIn('automatically merged', B.messages[1]) |
| 3508 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3509 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3510 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3511 | def test_client_get_running_jobs(self): |
| 3512 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3513 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3514 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3515 | A.addApproval('code-review', 2) |
| 3516 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3517 | self.waitUntilSettled() |
| 3518 | |
| 3519 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3520 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3521 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3522 | |
| 3523 | # Wait for gearman server to send the initial workData back to zuul |
| 3524 | start = time.time() |
| 3525 | while True: |
| 3526 | if time.time() - start > 10: |
| 3527 | raise Exception("Timeout waiting for gearman server to report " |
| 3528 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3529 | build = list(self.executor_client.builds.values())[0] |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3530 | if build.worker.name == "My Worker": |
| 3531 | break |
| 3532 | else: |
| 3533 | time.sleep(0) |
| 3534 | |
| 3535 | running_items = client.get_running_jobs() |
| 3536 | |
| 3537 | self.assertEqual(1, len(running_items)) |
| 3538 | running_item = running_items[0] |
| 3539 | self.assertEqual([], running_item['failing_reasons']) |
| 3540 | self.assertEqual([], running_item['items_behind']) |
| 3541 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3542 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3543 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3544 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3545 | self.assertEqual(True, running_item['active']) |
| 3546 | self.assertEqual('1,1', running_item['id']) |
| 3547 | |
| 3548 | self.assertEqual(3, len(running_item['jobs'])) |
| 3549 | for job in running_item['jobs']: |
| 3550 | if job['name'] == 'project-merge': |
| 3551 | self.assertEqual('project-merge', job['name']) |
| 3552 | self.assertEqual('gate', job['pipeline']) |
| 3553 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3554 | self.assertEqual('https://server/job/project-merge/0/', |
| 3555 | job['url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3556 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3557 | self.assertEqual(False, job['canceled']) |
| 3558 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3559 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3560 | self.assertEqual('gate', job['pipeline']) |
| 3561 | break |
| 3562 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3563 | self.executor_server.hold_jobs_in_build = False |
| 3564 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3565 | self.waitUntilSettled() |
| 3566 | |
| 3567 | running_items = client.get_running_jobs() |
| 3568 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3569 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3570 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3571 | def test_nonvoting_pipeline(self): |
| 3572 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3573 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3574 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3575 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3576 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3577 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3578 | |
| 3579 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3580 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3581 | self.assertEqual( |
| 3582 | self.getJobFromHistory('experimental-project-test').result, |
| 3583 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3584 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3585 | |
| 3586 | def test_crd_gate(self): |
| 3587 | "Test cross-repo dependencies" |
| 3588 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3589 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3590 | A.addApproval('code-review', 2) |
| 3591 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3592 | |
| 3593 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3594 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3595 | AM2.setMerged() |
| 3596 | AM1.setMerged() |
| 3597 | |
| 3598 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3599 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3600 | BM2.setMerged() |
| 3601 | BM1.setMerged() |
| 3602 | |
| 3603 | # A -> AM1 -> AM2 |
| 3604 | # B -> BM1 -> BM2 |
| 3605 | # A Depends-On: B |
| 3606 | # M2 is here to make sure it is never queried. If it is, it |
| 3607 | # means zuul is walking down the entire history of merged |
| 3608 | # changes. |
| 3609 | |
| 3610 | B.setDependsOn(BM1, 1) |
| 3611 | BM1.setDependsOn(BM2, 1) |
| 3612 | |
| 3613 | A.setDependsOn(AM1, 1) |
| 3614 | AM1.setDependsOn(AM2, 1) |
| 3615 | |
| 3616 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3617 | A.subject, B.data['id']) |
| 3618 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3619 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3620 | self.waitUntilSettled() |
| 3621 | |
| 3622 | self.assertEqual(A.data['status'], 'NEW') |
| 3623 | self.assertEqual(B.data['status'], 'NEW') |
| 3624 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3625 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3626 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3627 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3628 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3629 | B.addApproval('approved', 1) |
| 3630 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3631 | self.waitUntilSettled() |
| 3632 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3633 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3634 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3635 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3636 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3637 | self.executor_server.hold_jobs_in_build = False |
| 3638 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3639 | self.waitUntilSettled() |
| 3640 | |
| 3641 | self.assertEqual(AM2.queried, 0) |
| 3642 | self.assertEqual(BM2.queried, 0) |
| 3643 | self.assertEqual(A.data['status'], 'MERGED') |
| 3644 | self.assertEqual(B.data['status'], 'MERGED') |
| 3645 | self.assertEqual(A.reported, 2) |
| 3646 | self.assertEqual(B.reported, 2) |
| 3647 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3648 | changes = self.getJobFromHistory( |
| 3649 | 'project-merge', 'org/project1').changes |
| 3650 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3651 | |
| 3652 | def test_crd_branch(self): |
| 3653 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3654 | |
| 3655 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3656 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3657 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3658 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3659 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3660 | A.addApproval('code-review', 2) |
| 3661 | B.addApproval('code-review', 2) |
| 3662 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3663 | |
| 3664 | # A Depends-On: B+C |
| 3665 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3666 | A.subject, B.data['id']) |
| 3667 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3668 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3669 | B.addApproval('approved', 1) |
| 3670 | C.addApproval('approved', 1) |
| 3671 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3672 | self.waitUntilSettled() |
| 3673 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3674 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3675 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3676 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3677 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3678 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3679 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3680 | self.executor_server.hold_jobs_in_build = False |
| 3681 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3682 | self.waitUntilSettled() |
| 3683 | |
| 3684 | self.assertEqual(A.data['status'], 'MERGED') |
| 3685 | self.assertEqual(B.data['status'], 'MERGED') |
| 3686 | self.assertEqual(C.data['status'], 'MERGED') |
| 3687 | self.assertEqual(A.reported, 2) |
| 3688 | self.assertEqual(B.reported, 2) |
| 3689 | self.assertEqual(C.reported, 2) |
| 3690 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3691 | changes = self.getJobFromHistory( |
| 3692 | 'project-merge', 'org/project1').changes |
| 3693 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3694 | |
| 3695 | def test_crd_multiline(self): |
| 3696 | "Test multiple depends-on lines in commit" |
| 3697 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3698 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3699 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3700 | A.addApproval('code-review', 2) |
| 3701 | B.addApproval('code-review', 2) |
| 3702 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3703 | |
| 3704 | # A Depends-On: B+C |
| 3705 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3706 | A.subject, B.data['id'], C.data['id']) |
| 3707 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3708 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3709 | B.addApproval('approved', 1) |
| 3710 | C.addApproval('approved', 1) |
| 3711 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3712 | self.waitUntilSettled() |
| 3713 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3714 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3715 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3716 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3717 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3718 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3719 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3720 | self.executor_server.hold_jobs_in_build = False |
| 3721 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3722 | self.waitUntilSettled() |
| 3723 | |
| 3724 | self.assertEqual(A.data['status'], 'MERGED') |
| 3725 | self.assertEqual(B.data['status'], 'MERGED') |
| 3726 | self.assertEqual(C.data['status'], 'MERGED') |
| 3727 | self.assertEqual(A.reported, 2) |
| 3728 | self.assertEqual(B.reported, 2) |
| 3729 | self.assertEqual(C.reported, 2) |
| 3730 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3731 | changes = self.getJobFromHistory( |
| 3732 | 'project-merge', 'org/project1').changes |
| 3733 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3734 | |
| 3735 | def test_crd_unshared_gate(self): |
| 3736 | "Test cross-repo dependencies in unshared gate queues" |
| 3737 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3738 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3739 | A.addApproval('code-review', 2) |
| 3740 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3741 | |
| 3742 | # A Depends-On: B |
| 3743 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3744 | A.subject, B.data['id']) |
| 3745 | |
| 3746 | # A and B do not share a queue, make sure that A is unable to |
| 3747 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3748 | B.addApproval('approved', 1) |
| 3749 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3750 | self.waitUntilSettled() |
| 3751 | |
| 3752 | self.assertEqual(A.data['status'], 'NEW') |
| 3753 | self.assertEqual(B.data['status'], 'NEW') |
| 3754 | self.assertEqual(A.reported, 0) |
| 3755 | self.assertEqual(B.reported, 0) |
| 3756 | self.assertEqual(len(self.history), 0) |
| 3757 | |
| 3758 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3759 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3760 | self.waitUntilSettled() |
| 3761 | |
| 3762 | self.assertEqual(B.data['status'], 'MERGED') |
| 3763 | self.assertEqual(B.reported, 2) |
| 3764 | |
| 3765 | # Now that B is merged, A should be able to be enqueued and |
| 3766 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3767 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3768 | self.waitUntilSettled() |
| 3769 | |
| 3770 | self.assertEqual(A.data['status'], 'MERGED') |
| 3771 | self.assertEqual(A.reported, 2) |
| 3772 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3773 | def test_crd_gate_reverse(self): |
| 3774 | "Test reverse cross-repo dependencies" |
| 3775 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3776 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3777 | A.addApproval('code-review', 2) |
| 3778 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3779 | |
| 3780 | # A Depends-On: B |
| 3781 | |
| 3782 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3783 | A.subject, B.data['id']) |
| 3784 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3785 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3786 | self.waitUntilSettled() |
| 3787 | |
| 3788 | self.assertEqual(A.data['status'], 'NEW') |
| 3789 | self.assertEqual(B.data['status'], 'NEW') |
| 3790 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3791 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3792 | A.addApproval('approved', 1) |
| 3793 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3794 | self.waitUntilSettled() |
| 3795 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3796 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3797 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3798 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3799 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3800 | self.executor_server.hold_jobs_in_build = False |
| 3801 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3802 | self.waitUntilSettled() |
| 3803 | |
| 3804 | self.assertEqual(A.data['status'], 'MERGED') |
| 3805 | self.assertEqual(B.data['status'], 'MERGED') |
| 3806 | self.assertEqual(A.reported, 2) |
| 3807 | self.assertEqual(B.reported, 2) |
| 3808 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3809 | changes = self.getJobFromHistory( |
| 3810 | 'project-merge', 'org/project1').changes |
| 3811 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3812 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3813 | def test_crd_cycle(self): |
| 3814 | "Test cross-repo dependency cycles" |
| 3815 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3816 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3817 | A.addApproval('code-review', 2) |
| 3818 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3819 | |
| 3820 | # A -> B -> A (via commit-depends) |
| 3821 | |
| 3822 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3823 | A.subject, B.data['id']) |
| 3824 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3825 | B.subject, A.data['id']) |
| 3826 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3827 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3828 | self.waitUntilSettled() |
| 3829 | |
| 3830 | self.assertEqual(A.reported, 0) |
| 3831 | self.assertEqual(B.reported, 0) |
| 3832 | self.assertEqual(A.data['status'], 'NEW') |
| 3833 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3834 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3835 | def test_crd_gate_unknown(self): |
| 3836 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 3837 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3838 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3839 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3840 | A.addApproval('code-review', 2) |
| 3841 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3842 | |
| 3843 | # A Depends-On: B |
| 3844 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3845 | A.subject, B.data['id']) |
| 3846 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3847 | B.addApproval('approved', 1) |
| 3848 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3849 | self.waitUntilSettled() |
| 3850 | |
| 3851 | # Unknown projects cannot share a queue with any other |
| 3852 | # since they don't have common jobs with any other (they have no jobs). |
| 3853 | # Changes which depend on unknown project changes |
| 3854 | # should not be processed in dependent pipeline |
| 3855 | self.assertEqual(A.data['status'], 'NEW') |
| 3856 | self.assertEqual(B.data['status'], 'NEW') |
| 3857 | self.assertEqual(A.reported, 0) |
| 3858 | self.assertEqual(B.reported, 0) |
| 3859 | self.assertEqual(len(self.history), 0) |
| 3860 | |
| 3861 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3862 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3863 | B.setMerged() |
| 3864 | self.waitUntilSettled() |
| 3865 | self.assertEqual(len(self.history), 0) |
| 3866 | |
| 3867 | # Now that B is merged, A should be able to be enqueued and |
| 3868 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3869 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3870 | self.waitUntilSettled() |
| 3871 | |
| 3872 | self.assertEqual(A.data['status'], 'MERGED') |
| 3873 | self.assertEqual(A.reported, 2) |
| 3874 | self.assertEqual(B.data['status'], 'MERGED') |
| 3875 | self.assertEqual(B.reported, 0) |
| 3876 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3877 | def test_crd_check(self): |
| 3878 | "Test cross-repo dependencies in independent pipelines" |
| 3879 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3880 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3881 | self.gearman_server.hold_jobs_in_queue = True |
| 3882 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3883 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3884 | |
| 3885 | # A Depends-On: B |
| 3886 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3887 | A.subject, B.data['id']) |
| 3888 | |
| 3889 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3890 | self.waitUntilSettled() |
| 3891 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3892 | self.gearman_server.hold_jobs_in_queue = False |
| 3893 | self.gearman_server.release() |
| 3894 | self.waitUntilSettled() |
| 3895 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3896 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3897 | self.waitUntilSettled() |
| 3898 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 3899 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3900 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3901 | self.executor_server.hold_jobs_in_build = False |
| 3902 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3903 | self.waitUntilSettled() |
| 3904 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3905 | self.assertEqual(A.data['status'], 'NEW') |
| 3906 | self.assertEqual(B.data['status'], 'NEW') |
| 3907 | self.assertEqual(A.reported, 1) |
| 3908 | self.assertEqual(B.reported, 0) |
| 3909 | |
| 3910 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3911 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3912 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3913 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3914 | def test_crd_check_git_depends(self): |
| 3915 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3916 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3917 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3918 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3919 | |
| 3920 | # Add two git-dependent changes and make sure they both report |
| 3921 | # success. |
| 3922 | B.setDependsOn(A, 1) |
| 3923 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3924 | self.waitUntilSettled() |
| 3925 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3926 | self.waitUntilSettled() |
| 3927 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3928 | self.orderedRelease() |
| 3929 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3930 | self.waitUntilSettled() |
| 3931 | |
| 3932 | self.assertEqual(A.data['status'], 'NEW') |
| 3933 | self.assertEqual(B.data['status'], 'NEW') |
| 3934 | self.assertEqual(A.reported, 1) |
| 3935 | self.assertEqual(B.reported, 1) |
| 3936 | |
| 3937 | self.assertEqual(self.history[0].changes, '1,1') |
| 3938 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3939 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3940 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3941 | |
| 3942 | self.assertIn('Build succeeded', A.messages[0]) |
| 3943 | self.assertIn('Build succeeded', B.messages[0]) |
| 3944 | |
| 3945 | def test_crd_check_duplicate(self): |
| 3946 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3947 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3948 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3949 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3950 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3951 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3952 | |
| 3953 | # Add two git-dependent changes... |
| 3954 | B.setDependsOn(A, 1) |
| 3955 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3956 | self.waitUntilSettled() |
| 3957 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3958 | |
| 3959 | # ...make sure the live one is not duplicated... |
| 3960 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3961 | self.waitUntilSettled() |
| 3962 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3963 | |
| 3964 | # ...but the non-live one is able to be. |
| 3965 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3966 | self.waitUntilSettled() |
| 3967 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 3968 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 3969 | # Release jobs in order to avoid races with change A jobs |
| 3970 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 3971 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3972 | self.executor_server.hold_jobs_in_build = False |
| 3973 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3974 | self.waitUntilSettled() |
| 3975 | |
| 3976 | self.assertEqual(A.data['status'], 'NEW') |
| 3977 | self.assertEqual(B.data['status'], 'NEW') |
| 3978 | self.assertEqual(A.reported, 1) |
| 3979 | self.assertEqual(B.reported, 1) |
| 3980 | |
| 3981 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 3982 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3983 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3984 | |
| 3985 | self.assertIn('Build succeeded', A.messages[0]) |
| 3986 | self.assertIn('Build succeeded', B.messages[0]) |
| 3987 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3988 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3989 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 3990 | |
| 3991 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3992 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 3993 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3994 | |
| 3995 | # A Depends-On: B |
| 3996 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3997 | A.subject, B.data['id']) |
| 3998 | |
| 3999 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4000 | self.waitUntilSettled() |
| 4001 | |
| 4002 | self.sched.reconfigure(self.config) |
| 4003 | |
| 4004 | # Make sure the items still share a change queue, and the |
| 4005 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4006 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4007 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4008 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4009 | first_item = queue.queue[0] |
| 4010 | for item in queue.queue: |
| 4011 | self.assertEqual(item.queue, first_item.queue) |
| 4012 | self.assertFalse(first_item.live) |
| 4013 | self.assertTrue(queue.queue[1].live) |
| 4014 | |
| 4015 | self.gearman_server.hold_jobs_in_queue = False |
| 4016 | self.gearman_server.release() |
| 4017 | self.waitUntilSettled() |
| 4018 | |
| 4019 | self.assertEqual(A.data['status'], 'NEW') |
| 4020 | self.assertEqual(B.data['status'], 'NEW') |
| 4021 | self.assertEqual(A.reported, 1) |
| 4022 | self.assertEqual(B.reported, 0) |
| 4023 | |
| 4024 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4025 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4026 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4027 | def test_crd_check_reconfiguration(self): |
| 4028 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4029 | |
| 4030 | def test_crd_undefined_project(self): |
| 4031 | """Test that undefined projects in dependencies are handled for |
| 4032 | independent pipelines""" |
| 4033 | # It's a hack for fake gerrit, |
| 4034 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4035 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4036 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4037 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4038 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4039 | def test_crd_check_ignore_dependencies(self): |
| 4040 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4041 | |
| 4042 | self.gearman_server.hold_jobs_in_queue = True |
| 4043 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4044 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4045 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4046 | |
| 4047 | # A Depends-On: B |
| 4048 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4049 | A.subject, B.data['id']) |
| 4050 | # C git-depends on B |
| 4051 | C.setDependsOn(B, 1) |
| 4052 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4053 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4054 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4055 | self.waitUntilSettled() |
| 4056 | |
| 4057 | # Make sure none of the items share a change queue, and all |
| 4058 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4059 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4060 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4061 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4062 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4063 | for item in check_pipeline.getAllItems(): |
| 4064 | self.assertTrue(item.live) |
| 4065 | |
| 4066 | self.gearman_server.hold_jobs_in_queue = False |
| 4067 | self.gearman_server.release() |
| 4068 | self.waitUntilSettled() |
| 4069 | |
| 4070 | self.assertEqual(A.data['status'], 'NEW') |
| 4071 | self.assertEqual(B.data['status'], 'NEW') |
| 4072 | self.assertEqual(C.data['status'], 'NEW') |
| 4073 | self.assertEqual(A.reported, 1) |
| 4074 | self.assertEqual(B.reported, 1) |
| 4075 | self.assertEqual(C.reported, 1) |
| 4076 | |
| 4077 | # Each job should have tested exactly one change |
| 4078 | for job in self.history: |
| 4079 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4080 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4081 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4082 | def test_crd_check_transitive(self): |
| 4083 | "Test transitive cross-repo dependencies" |
| 4084 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4085 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4086 | # and C,2 (not C,1 which would indicate stale data in the |
| 4087 | # cache for B). |
| 4088 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4089 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4090 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4091 | |
| 4092 | # A Depends-On: B |
| 4093 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4094 | A.subject, B.data['id']) |
| 4095 | |
| 4096 | # B Depends-On: C |
| 4097 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4098 | B.subject, C.data['id']) |
| 4099 | |
| 4100 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4101 | self.waitUntilSettled() |
| 4102 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4103 | |
| 4104 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4105 | self.waitUntilSettled() |
| 4106 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4107 | |
| 4108 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4109 | self.waitUntilSettled() |
| 4110 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4111 | |
| 4112 | C.addPatchset() |
| 4113 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4114 | self.waitUntilSettled() |
| 4115 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4116 | |
| 4117 | A.addPatchset() |
| 4118 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4119 | self.waitUntilSettled() |
| 4120 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4121 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4122 | def test_crd_check_unknown(self): |
| 4123 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4124 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4125 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4126 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4127 | # A Depends-On: B |
| 4128 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4129 | A.subject, B.data['id']) |
| 4130 | |
| 4131 | # Make sure zuul has seen an event on B. |
| 4132 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4133 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4134 | self.waitUntilSettled() |
| 4135 | |
| 4136 | self.assertEqual(A.data['status'], 'NEW') |
| 4137 | self.assertEqual(A.reported, 1) |
| 4138 | self.assertEqual(B.data['status'], 'NEW') |
| 4139 | self.assertEqual(B.reported, 0) |
| 4140 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4141 | def test_crd_cycle_join(self): |
| 4142 | "Test an updated change creates a cycle" |
| 4143 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4144 | |
| 4145 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4146 | self.waitUntilSettled() |
| 4147 | |
| 4148 | # Create B->A |
| 4149 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4150 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4151 | B.subject, A.data['id']) |
| 4152 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4153 | self.waitUntilSettled() |
| 4154 | |
| 4155 | # Update A to add A->B (a cycle). |
| 4156 | A.addPatchset() |
| 4157 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4158 | A.subject, B.data['id']) |
| 4159 | # Normally we would submit the patchset-created event for |
| 4160 | # processing here, however, we have no way of noting whether |
| 4161 | # the dependency cycle detection correctly raised an |
| 4162 | # exception, so instead, we reach into the source driver and |
| 4163 | # call the method that would ultimately be called by the event |
| 4164 | # processing. |
| 4165 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4166 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 4167 | (trusted, project) = tenant.getProject('org/project') |
| 4168 | source = project.source |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4169 | |
| 4170 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4171 | # it easier for users to create events for testing. |
| 4172 | event = zuul.model.TriggerEvent() |
| 4173 | event.trigger_name = 'gerrit' |
| 4174 | event.change_number = '1' |
| 4175 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4176 | with testtools.ExpectedException( |
| 4177 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4178 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4179 | self.log.debug("Got expected dependency cycle exception") |
| 4180 | |
| 4181 | # Now if we update B to remove the depends-on, everything |
| 4182 | # should be okay. B; A->B |
| 4183 | |
| 4184 | B.addPatchset() |
| 4185 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4186 | |
| 4187 | source.getChange(event, True) |
| 4188 | event.change_number = '2' |
| 4189 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4190 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4191 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4192 | def test_disable_at(self): |
| 4193 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4194 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4195 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4196 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4197 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4198 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4199 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4200 | |
| 4201 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4202 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4203 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4204 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4205 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4206 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4207 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4208 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4209 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4210 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4211 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4212 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4213 | self.executor_server.failJob('project-test1', A) |
| 4214 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4215 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4216 | self.executor_server.failJob('project-test1', D) |
| 4217 | self.executor_server.failJob('project-test1', E) |
| 4218 | self.executor_server.failJob('project-test1', F) |
| 4219 | self.executor_server.failJob('project-test1', G) |
| 4220 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4221 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4222 | self.executor_server.failJob('project-test1', J) |
| 4223 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4224 | |
| 4225 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4226 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4227 | self.waitUntilSettled() |
| 4228 | |
| 4229 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4230 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4231 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4232 | |
| 4233 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4234 | self.waitUntilSettled() |
| 4235 | |
| 4236 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4237 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4238 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4239 | |
| 4240 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4241 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4242 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4243 | self.waitUntilSettled() |
| 4244 | |
| 4245 | # We should be disabled now |
| 4246 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4247 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4248 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4249 | |
| 4250 | # We need to wait between each of these patches to make sure the |
| 4251 | # smtp messages come back in an expected order |
| 4252 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4253 | self.waitUntilSettled() |
| 4254 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4255 | self.waitUntilSettled() |
| 4256 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4257 | self.waitUntilSettled() |
| 4258 | |
| 4259 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4260 | # leaving a message on each change |
| 4261 | self.assertEqual(1, len(A.messages)) |
| 4262 | self.assertIn('Build failed.', A.messages[0]) |
| 4263 | self.assertEqual(1, len(B.messages)) |
| 4264 | self.assertIn('Build failed.', B.messages[0]) |
| 4265 | self.assertEqual(1, len(C.messages)) |
| 4266 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4267 | self.assertEqual(1, len(D.messages)) |
| 4268 | self.assertIn('Build failed.', D.messages[0]) |
| 4269 | self.assertEqual(1, len(E.messages)) |
| 4270 | self.assertIn('Build failed.', E.messages[0]) |
| 4271 | self.assertEqual(1, len(F.messages)) |
| 4272 | self.assertIn('Build failed.', F.messages[0]) |
| 4273 | |
| 4274 | # The last 3 (GHI) would have only reported via smtp. |
| 4275 | self.assertEqual(3, len(self.smtp_messages)) |
| 4276 | self.assertEqual(0, len(G.messages)) |
| 4277 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4278 | self.assertIn( |
| 4279 | 'project-test1 https://server/job', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4280 | self.assertEqual(0, len(H.messages)) |
| 4281 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4282 | self.assertIn( |
| 4283 | 'project-test1 https://server/job', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4284 | self.assertEqual(0, len(I.messages)) |
| 4285 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4286 | self.assertIn( |
| 4287 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4288 | |
| 4289 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4290 | # comes out of disabled |
| 4291 | self.sched.reconfigure(self.config) |
| 4292 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4293 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4294 | |
| 4295 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4296 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4297 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4298 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4299 | |
| 4300 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4301 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4302 | self.waitUntilSettled() |
| 4303 | |
| 4304 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4305 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4306 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4307 | |
| 4308 | # J and K went back to gerrit |
| 4309 | self.assertEqual(1, len(J.messages)) |
| 4310 | self.assertIn('Build failed.', J.messages[0]) |
| 4311 | self.assertEqual(1, len(K.messages)) |
| 4312 | self.assertIn('Build failed.', K.messages[0]) |
| 4313 | # No more messages reported via smtp |
| 4314 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4315 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4316 | @simple_layout('layouts/one-job-project.yaml') |
| 4317 | def test_one_job_project(self): |
| 4318 | "Test that queueing works with one job" |
| 4319 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4320 | 'master', 'A') |
| 4321 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4322 | 'master', 'B') |
| 4323 | A.addApproval('code-review', 2) |
| 4324 | B.addApproval('code-review', 2) |
| 4325 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4326 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4327 | self.waitUntilSettled() |
| 4328 | |
| 4329 | self.assertEqual(A.data['status'], 'MERGED') |
| 4330 | self.assertEqual(A.reported, 2) |
| 4331 | self.assertEqual(B.data['status'], 'MERGED') |
| 4332 | self.assertEqual(B.reported, 2) |
| 4333 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4334 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4335 | "Test that if a execute server fails to run a job, it is run again" |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4336 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4337 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4339 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4340 | self.waitUntilSettled() |
| 4341 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4342 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4343 | self.waitUntilSettled() |
| 4344 | |
| 4345 | self.assertEqual(len(self.builds), 2) |
| 4346 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4347 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4348 | self.waitUntilSettled() |
| 4349 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4350 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4351 | self.assertEqual(len(self.builds), 1, |
| 4352 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4353 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4354 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4355 | self.waitUntilSettled() |
| 4356 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4357 | self.executor_server.hold_jobs_in_build = False |
| 4358 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4359 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4360 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4361 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4362 | self.assertEqual(A.reported, 1) |
| 4363 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4364 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4365 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4366 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4367 | |
| 4368 | self.fake_nodepool.paused = True |
| 4369 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4370 | A.addApproval('code-review', 2) |
| 4371 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4372 | self.waitUntilSettled() |
| 4373 | |
| 4374 | self.zk.client.stop() |
| 4375 | self.zk.client.start() |
| 4376 | self.fake_nodepool.paused = False |
| 4377 | self.waitUntilSettled() |
| 4378 | |
| 4379 | self.assertEqual(A.data['status'], 'MERGED') |
| 4380 | self.assertEqual(A.reported, 2) |
| 4381 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4382 | def test_nodepool_failure(self): |
| 4383 | "Test that jobs are reported after a nodepool failure" |
| 4384 | |
| 4385 | self.fake_nodepool.paused = True |
| 4386 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4387 | A.addApproval('code-review', 2) |
| 4388 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4389 | self.waitUntilSettled() |
| 4390 | |
| 4391 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4392 | self.fake_nodepool.addFailRequest(req) |
| 4393 | |
| 4394 | self.fake_nodepool.paused = False |
| 4395 | self.waitUntilSettled() |
| 4396 | |
| 4397 | self.assertEqual(A.data['status'], 'NEW') |
| 4398 | self.assertEqual(A.reported, 2) |
| 4399 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4400 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4401 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4402 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4403 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4404 | class TestExecutor(ZuulTestCase): |
| 4405 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4406 | |
| 4407 | def assertFinalState(self): |
| 4408 | # In this test, we expect to shut down in a non-final state, |
| 4409 | # so skip these checks. |
| 4410 | pass |
| 4411 | |
| 4412 | def assertCleanShutdown(self): |
| 4413 | self.log.debug("Assert clean shutdown") |
| 4414 | |
| 4415 | # After shutdown, make sure no jobs are running |
| 4416 | self.assertEqual({}, self.executor_server.job_workers) |
| 4417 | |
| 4418 | # Make sure that git.Repo objects have been garbage collected. |
| 4419 | repos = [] |
| 4420 | gc.collect() |
| 4421 | for obj in gc.get_objects(): |
| 4422 | if isinstance(obj, git.Repo): |
| 4423 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4424 | repos.append(obj) |
| 4425 | self.assertEqual(len(repos), 0) |
| 4426 | |
| 4427 | def test_executor_shutdown(self): |
| 4428 | "Test that the executor can shut down with jobs running" |
| 4429 | |
| 4430 | self.executor_server.hold_jobs_in_build = True |
| 4431 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4432 | A.addApproval('code-review', 2) |
| 4433 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4434 | self.waitUntilSettled() |
| 4435 | |
| 4436 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4437 | class TestDependencyGraph(ZuulTestCase): |
| 4438 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4439 | |
| 4440 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4441 | "Test a job in a dependency graph is queued only once" |
| 4442 | # Job dependencies, starting with A |
| 4443 | # A |
| 4444 | # / \ |
| 4445 | # B C |
| 4446 | # / \ / \ |
| 4447 | # D F E |
| 4448 | # | |
| 4449 | # G |
| 4450 | |
| 4451 | self.executor_server.hold_jobs_in_build = True |
| 4452 | change = self.fake_gerrit.addFakeChange( |
| 4453 | 'org/project', 'master', 'change') |
| 4454 | change.addApproval('code-review', 2) |
| 4455 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4456 | |
| 4457 | self.waitUntilSettled() |
| 4458 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4459 | |
| 4460 | self.executor_server.release('A') |
| 4461 | self.waitUntilSettled() |
| 4462 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4463 | |
| 4464 | self.executor_server.release('B') |
| 4465 | self.waitUntilSettled() |
| 4466 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4467 | |
| 4468 | self.executor_server.release('D') |
| 4469 | self.waitUntilSettled() |
| 4470 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4471 | |
| 4472 | self.executor_server.release('C') |
| 4473 | self.waitUntilSettled() |
| 4474 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4475 | |
| 4476 | self.executor_server.release('F') |
| 4477 | self.waitUntilSettled() |
| 4478 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4479 | |
| 4480 | self.executor_server.release('G') |
| 4481 | self.waitUntilSettled() |
| 4482 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4483 | |
| 4484 | self.executor_server.release('E') |
| 4485 | self.waitUntilSettled() |
| 4486 | self.assertEqual(len(self.builds), 0) |
| 4487 | |
| 4488 | self.executor_server.hold_jobs_in_build = False |
| 4489 | self.executor_server.release() |
| 4490 | self.waitUntilSettled() |
| 4491 | |
| 4492 | self.assertEqual(len(self.builds), 0) |
| 4493 | self.assertEqual(len(self.history), 7) |
| 4494 | |
| 4495 | self.assertEqual(change.data['status'], 'MERGED') |
| 4496 | self.assertEqual(change.reported, 2) |
| 4497 | |
| 4498 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4499 | "Test that a job waits till all dependencies are successful" |
| 4500 | # Job dependencies, starting with A |
| 4501 | # A |
| 4502 | # / \ |
| 4503 | # B C* |
| 4504 | # / \ / \ |
| 4505 | # D F E |
| 4506 | # | |
| 4507 | # G |
| 4508 | |
| 4509 | self.executor_server.hold_jobs_in_build = True |
| 4510 | change = self.fake_gerrit.addFakeChange( |
| 4511 | 'org/project', 'master', 'change') |
| 4512 | change.addApproval('code-review', 2) |
| 4513 | |
| 4514 | self.executor_server.failJob('C', change) |
| 4515 | |
| 4516 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4517 | |
| 4518 | self.waitUntilSettled() |
| 4519 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4520 | |
| 4521 | self.executor_server.release('A') |
| 4522 | self.waitUntilSettled() |
| 4523 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4524 | |
| 4525 | self.executor_server.release('B') |
| 4526 | self.waitUntilSettled() |
| 4527 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4528 | |
| 4529 | self.executor_server.release('D') |
| 4530 | self.waitUntilSettled() |
| 4531 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4532 | |
| 4533 | self.executor_server.release('C') |
| 4534 | self.waitUntilSettled() |
| 4535 | self.assertEqual(len(self.builds), 0) |
| 4536 | |
| 4537 | self.executor_server.hold_jobs_in_build = False |
| 4538 | self.executor_server.release() |
| 4539 | self.waitUntilSettled() |
| 4540 | |
| 4541 | self.assertEqual(len(self.builds), 0) |
| 4542 | self.assertEqual(len(self.history), 4) |
| 4543 | |
| 4544 | self.assertEqual(change.data['status'], 'NEW') |
| 4545 | self.assertEqual(change.reported, 2) |
| 4546 | |
| 4547 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4548 | class TestDuplicatePipeline(ZuulTestCase): |
| 4549 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4550 | |
| 4551 | def test_duplicate_pipelines(self): |
| 4552 | "Test that a change matching multiple pipelines works" |
| 4553 | |
| 4554 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4555 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4556 | self.waitUntilSettled() |
| 4557 | |
| 4558 | self.assertHistory([ |
| 4559 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4560 | pipeline='dup1'), |
| 4561 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4562 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4563 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4564 | |
| 4565 | self.assertEqual(len(A.messages), 2) |
| 4566 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4567 | if 'dup1' in A.messages[0]: |
| 4568 | self.assertIn('dup1', A.messages[0]) |
| 4569 | self.assertNotIn('dup2', A.messages[0]) |
| 4570 | self.assertIn('project-test1', A.messages[0]) |
| 4571 | self.assertIn('dup2', A.messages[1]) |
| 4572 | self.assertNotIn('dup1', A.messages[1]) |
| 4573 | self.assertIn('project-test1', A.messages[1]) |
| 4574 | else: |
| 4575 | self.assertIn('dup1', A.messages[1]) |
| 4576 | self.assertNotIn('dup2', A.messages[1]) |
| 4577 | self.assertIn('project-test1', A.messages[1]) |
| 4578 | self.assertIn('dup2', A.messages[0]) |
| 4579 | self.assertNotIn('dup1', A.messages[0]) |
| 4580 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4581 | |
| 4582 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4583 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4584 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4585 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4586 | def test_job_from_templates_executed(self): |
| 4587 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4588 | |
| 4589 | A = self.fake_gerrit.addFakeChange( |
| 4590 | 'org/templated-project', 'master', 'A') |
| 4591 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4592 | self.waitUntilSettled() |
| 4593 | |
| 4594 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4595 | 'SUCCESS') |
| 4596 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4597 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4598 | |
| 4599 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4600 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4601 | |
| 4602 | A = self.fake_gerrit.addFakeChange( |
| 4603 | 'org/layered-project', 'master', 'A') |
| 4604 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4605 | self.waitUntilSettled() |
| 4606 | |
| 4607 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4608 | 'SUCCESS') |
| 4609 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4610 | 'SUCCESS') |
| 4611 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4612 | ).result, 'SUCCESS') |
| 4613 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4614 | ).result, 'SUCCESS') |
| 4615 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4616 | ).result, 'SUCCESS') |
| 4617 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4618 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4619 | |
| 4620 | |
| 4621 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4622 | tenant_config_file = 'config/success-url/main.yaml' |
| 4623 | |
| 4624 | def test_success_url(self): |
| 4625 | "Ensure bad build params are ignored" |
| 4626 | self.sched.reconfigure(self.config) |
| 4627 | self.init_repo('org/docs') |
| 4628 | |
| 4629 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4630 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4631 | self.waitUntilSettled() |
| 4632 | |
| 4633 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4634 | self.assertEqual(len(self.history), 2) |
| 4635 | |
| 4636 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4637 | for build in self.history: |
| 4638 | if build.name == 'docs-draft-test': |
| 4639 | uuid = build.uuid[:7] |
| 4640 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4641 | |
| 4642 | # Two msgs: 'Starting...' + results |
| 4643 | self.assertEqual(len(self.smtp_messages), 2) |
| 4644 | body = self.smtp_messages[1]['body'].splitlines() |
| 4645 | self.assertEqual('Build succeeded.', body[0]) |
| 4646 | |
| 4647 | self.assertIn( |
| 4648 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4649 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4650 | body[2]) |
| 4651 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4652 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4653 | self.assertIn( |
| 4654 | '- docs-draft-test2 https://server/job', |
| 4655 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4656 | |
| 4657 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4658 | class TestSchedulerMerges(ZuulTestCase): |
| 4659 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4660 | |
| 4661 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4662 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4663 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4664 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4665 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4666 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4667 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4668 | A.addApproval('code-review', 2) |
| 4669 | B.addApproval('code-review', 2) |
| 4670 | C.addApproval('code-review', 2) |
| 4671 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4672 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4673 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4674 | self.waitUntilSettled() |
| 4675 | |
| 4676 | build = self.builds[-1] |
| 4677 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4678 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4679 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4680 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4681 | repo = git.Repo(path) |
| 4682 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4683 | repo_messages.reverse() |
| 4684 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4685 | self.executor_server.hold_jobs_in_build = False |
| 4686 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4687 | self.waitUntilSettled() |
| 4688 | |
| 4689 | return repo_messages |
| 4690 | |
| 4691 | def _test_merge(self, mode): |
| 4692 | us_path = os.path.join( |
| 4693 | self.upstream_root, 'org/project-%s' % mode) |
| 4694 | expected_messages = [ |
| 4695 | 'initial commit', |
| 4696 | 'add content from fixture', |
| 4697 | # the intermediate commits order is nondeterministic |
| 4698 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4699 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4700 | ] |
| 4701 | result = self._test_project_merge_mode(mode) |
| 4702 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4703 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4704 | |
| 4705 | def test_project_merge_mode_merge(self): |
| 4706 | self._test_merge('merge') |
| 4707 | |
| 4708 | def test_project_merge_mode_merge_resolve(self): |
| 4709 | self._test_merge('merge-resolve') |
| 4710 | |
| 4711 | def test_project_merge_mode_cherrypick(self): |
| 4712 | expected_messages = [ |
| 4713 | 'initial commit', |
| 4714 | 'add content from fixture', |
| 4715 | 'A-1', |
| 4716 | 'B-1', |
| 4717 | 'C-1'] |
| 4718 | result = self._test_project_merge_mode('cherry-pick') |
| 4719 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4720 | |
| 4721 | def test_merge_branch(self): |
| 4722 | "Test that the right commits are on alternate branches" |
| 4723 | self.create_branch('org/project-merge-branches', 'mp') |
| 4724 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4725 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4726 | A = self.fake_gerrit.addFakeChange( |
| 4727 | 'org/project-merge-branches', 'mp', 'A') |
| 4728 | B = self.fake_gerrit.addFakeChange( |
| 4729 | 'org/project-merge-branches', 'mp', 'B') |
| 4730 | C = self.fake_gerrit.addFakeChange( |
| 4731 | 'org/project-merge-branches', 'mp', 'C') |
| 4732 | A.addApproval('code-review', 2) |
| 4733 | B.addApproval('code-review', 2) |
| 4734 | C.addApproval('code-review', 2) |
| 4735 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4736 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4737 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4738 | self.waitUntilSettled() |
| 4739 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4740 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4741 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4742 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4743 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4744 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4745 | self.waitUntilSettled() |
| 4746 | |
| 4747 | build = self.builds[-1] |
| 4748 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4749 | ref = self.getParameter(build, 'ZUUL_REF') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4750 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4751 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4752 | repo = git.Repo(path) |
| 4753 | |
| 4754 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4755 | repo_messages.reverse() |
| 4756 | correct_messages = [ |
| 4757 | 'initial commit', |
| 4758 | 'add content from fixture', |
| 4759 | 'mp commit', |
| 4760 | 'A-1', 'B-1', 'C-1'] |
| 4761 | self.assertEqual(repo_messages, correct_messages) |
| 4762 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4763 | self.executor_server.hold_jobs_in_build = False |
| 4764 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4765 | self.waitUntilSettled() |
| 4766 | |
| 4767 | def test_merge_multi_branch(self): |
| 4768 | "Test that dependent changes on multiple branches are merged" |
| 4769 | self.create_branch('org/project-merge-branches', 'mp') |
| 4770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4771 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4772 | A = self.fake_gerrit.addFakeChange( |
| 4773 | 'org/project-merge-branches', 'master', 'A') |
| 4774 | B = self.fake_gerrit.addFakeChange( |
| 4775 | 'org/project-merge-branches', 'mp', 'B') |
| 4776 | C = self.fake_gerrit.addFakeChange( |
| 4777 | 'org/project-merge-branches', 'master', 'C') |
| 4778 | A.addApproval('code-review', 2) |
| 4779 | B.addApproval('code-review', 2) |
| 4780 | C.addApproval('code-review', 2) |
| 4781 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4782 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4783 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4784 | self.waitUntilSettled() |
| 4785 | |
| 4786 | job_A = None |
| 4787 | for job in self.builds: |
| 4788 | if 'project-merge' in job.name: |
| 4789 | job_A = job |
| 4790 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4791 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4792 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4793 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4794 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4795 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4796 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4797 | repo = git.Repo(path) |
| 4798 | repo_messages = [c.message.strip() |
| 4799 | for c in repo.iter_commits(ref_A)] |
| 4800 | repo_messages.reverse() |
| 4801 | correct_messages = [ |
| 4802 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4803 | self.assertEqual(repo_messages, correct_messages) |
| 4804 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4805 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4806 | self.waitUntilSettled() |
| 4807 | |
| 4808 | job_B = None |
| 4809 | for job in self.builds: |
| 4810 | if 'project-merge' in job.name: |
| 4811 | job_B = job |
| 4812 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4813 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4814 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4815 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4816 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4817 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4818 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4819 | repo = git.Repo(path) |
| 4820 | repo_messages = [c.message.strip() |
| 4821 | for c in repo.iter_commits(ref_B)] |
| 4822 | repo_messages.reverse() |
| 4823 | correct_messages = [ |
| 4824 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4825 | self.assertEqual(repo_messages, correct_messages) |
| 4826 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4827 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4828 | self.waitUntilSettled() |
| 4829 | |
| 4830 | job_C = None |
| 4831 | for job in self.builds: |
| 4832 | if 'project-merge' in job.name: |
| 4833 | job_C = job |
| 4834 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4835 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4836 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4837 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4838 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4839 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4840 | repo = git.Repo(path) |
| 4841 | repo_messages = [c.message.strip() |
| 4842 | for c in repo.iter_commits(ref_C)] |
| 4843 | |
| 4844 | repo_messages.reverse() |
| 4845 | correct_messages = [ |
| 4846 | 'initial commit', 'add content from fixture', |
| 4847 | 'A-1', 'C-1'] |
| 4848 | # Ensure the right commits are in the history for this ref |
| 4849 | self.assertEqual(repo_messages, correct_messages) |
| 4850 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4851 | self.executor_server.hold_jobs_in_build = False |
| 4852 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4853 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 4854 | |
| 4855 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 4856 | class TestSemaphore(ZuulTestCase): |
| 4857 | tenant_config_file = 'config/semaphore/main.yaml' |
| 4858 | |
| 4859 | def test_semaphore_one(self): |
| 4860 | "Test semaphores with max=1 (mutex)" |
| 4861 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4862 | |
| 4863 | self.executor_server.hold_jobs_in_build = True |
| 4864 | |
| 4865 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4866 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4867 | self.assertFalse('test-semaphore' in |
| 4868 | tenant.semaphore_handler.semaphores) |
| 4869 | |
| 4870 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4871 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4872 | self.waitUntilSettled() |
| 4873 | |
| 4874 | self.assertEqual(len(self.builds), 3) |
| 4875 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4876 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 4877 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4878 | |
| 4879 | self.executor_server.release('semaphore-one-test1') |
| 4880 | self.waitUntilSettled() |
| 4881 | |
| 4882 | self.assertEqual(len(self.builds), 3) |
| 4883 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4884 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4885 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4886 | self.assertTrue('test-semaphore' in |
| 4887 | tenant.semaphore_handler.semaphores) |
| 4888 | |
| 4889 | self.executor_server.release('semaphore-one-test2') |
| 4890 | self.waitUntilSettled() |
| 4891 | |
| 4892 | self.assertEqual(len(self.builds), 3) |
| 4893 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4894 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4895 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 4896 | self.assertTrue('test-semaphore' in |
| 4897 | tenant.semaphore_handler.semaphores) |
| 4898 | |
| 4899 | self.executor_server.release('semaphore-one-test1') |
| 4900 | self.waitUntilSettled() |
| 4901 | |
| 4902 | self.assertEqual(len(self.builds), 3) |
| 4903 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4904 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4905 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4906 | self.assertTrue('test-semaphore' in |
| 4907 | tenant.semaphore_handler.semaphores) |
| 4908 | |
| 4909 | self.executor_server.release('semaphore-one-test2') |
| 4910 | self.waitUntilSettled() |
| 4911 | |
| 4912 | self.assertEqual(len(self.builds), 2) |
| 4913 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4914 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4915 | self.assertFalse('test-semaphore' in |
| 4916 | tenant.semaphore_handler.semaphores) |
| 4917 | |
| 4918 | self.executor_server.hold_jobs_in_build = False |
| 4919 | self.executor_server.release() |
| 4920 | |
| 4921 | self.waitUntilSettled() |
| 4922 | self.assertEqual(len(self.builds), 0) |
| 4923 | |
| 4924 | self.assertEqual(A.reported, 1) |
| 4925 | self.assertEqual(B.reported, 1) |
| 4926 | self.assertFalse('test-semaphore' in |
| 4927 | tenant.semaphore_handler.semaphores) |
| 4928 | |
| 4929 | def test_semaphore_two(self): |
| 4930 | "Test semaphores with max>1" |
| 4931 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4932 | |
| 4933 | self.executor_server.hold_jobs_in_build = True |
| 4934 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4935 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4936 | self.assertFalse('test-semaphore-two' in |
| 4937 | tenant.semaphore_handler.semaphores) |
| 4938 | |
| 4939 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4940 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4941 | self.waitUntilSettled() |
| 4942 | |
| 4943 | self.assertEqual(len(self.builds), 4) |
| 4944 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4945 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 4946 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4947 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 4948 | self.assertTrue('test-semaphore-two' in |
| 4949 | tenant.semaphore_handler.semaphores) |
| 4950 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4951 | 'test-semaphore-two', [])), 2) |
| 4952 | |
| 4953 | self.executor_server.release('semaphore-two-test1') |
| 4954 | self.waitUntilSettled() |
| 4955 | |
| 4956 | self.assertEqual(len(self.builds), 4) |
| 4957 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4958 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 4959 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4960 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 4961 | self.assertTrue('test-semaphore-two' in |
| 4962 | tenant.semaphore_handler.semaphores) |
| 4963 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4964 | 'test-semaphore-two', [])), 2) |
| 4965 | |
| 4966 | self.executor_server.release('semaphore-two-test2') |
| 4967 | self.waitUntilSettled() |
| 4968 | |
| 4969 | self.assertEqual(len(self.builds), 4) |
| 4970 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4971 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4972 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 4973 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 4974 | self.assertTrue('test-semaphore-two' in |
| 4975 | tenant.semaphore_handler.semaphores) |
| 4976 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4977 | 'test-semaphore-two', [])), 2) |
| 4978 | |
| 4979 | self.executor_server.release('semaphore-two-test1') |
| 4980 | self.waitUntilSettled() |
| 4981 | |
| 4982 | self.assertEqual(len(self.builds), 3) |
| 4983 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4984 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4985 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4986 | self.assertTrue('test-semaphore-two' in |
| 4987 | tenant.semaphore_handler.semaphores) |
| 4988 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4989 | 'test-semaphore-two', [])), 1) |
| 4990 | |
| 4991 | self.executor_server.release('semaphore-two-test2') |
| 4992 | self.waitUntilSettled() |
| 4993 | |
| 4994 | self.assertEqual(len(self.builds), 2) |
| 4995 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4996 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4997 | self.assertFalse('test-semaphore-two' in |
| 4998 | tenant.semaphore_handler.semaphores) |
| 4999 | |
| 5000 | self.executor_server.hold_jobs_in_build = False |
| 5001 | self.executor_server.release() |
| 5002 | |
| 5003 | self.waitUntilSettled() |
| 5004 | self.assertEqual(len(self.builds), 0) |
| 5005 | |
| 5006 | self.assertEqual(A.reported, 1) |
| 5007 | self.assertEqual(B.reported, 1) |
| 5008 | |
| 5009 | def test_semaphore_abandon(self): |
| 5010 | "Test abandon with job semaphores" |
| 5011 | self.executor_server.hold_jobs_in_build = True |
| 5012 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5013 | check_pipeline = tenant.layout.pipelines['check'] |
| 5014 | |
| 5015 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5016 | self.assertFalse('test-semaphore' in |
| 5017 | tenant.semaphore_handler.semaphores) |
| 5018 | |
| 5019 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5020 | self.waitUntilSettled() |
| 5021 | |
| 5022 | self.assertTrue('test-semaphore' in |
| 5023 | tenant.semaphore_handler.semaphores) |
| 5024 | |
| 5025 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5026 | self.waitUntilSettled() |
| 5027 | |
| 5028 | # The check pipeline should be empty |
| 5029 | items = check_pipeline.getAllItems() |
| 5030 | self.assertEqual(len(items), 0) |
| 5031 | |
| 5032 | # The semaphore should be released |
| 5033 | self.assertFalse('test-semaphore' in |
| 5034 | tenant.semaphore_handler.semaphores) |
| 5035 | |
| 5036 | self.executor_server.hold_jobs_in_build = False |
| 5037 | self.executor_server.release() |
| 5038 | self.waitUntilSettled() |
| 5039 | |
| 5040 | def test_semaphore_reconfigure(self): |
| 5041 | "Test reconfigure with job semaphores" |
| 5042 | self.executor_server.hold_jobs_in_build = True |
| 5043 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5044 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5045 | self.assertFalse('test-semaphore' in |
| 5046 | tenant.semaphore_handler.semaphores) |
| 5047 | |
| 5048 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5049 | self.waitUntilSettled() |
| 5050 | |
| 5051 | self.assertTrue('test-semaphore' in |
| 5052 | tenant.semaphore_handler.semaphores) |
| 5053 | |
| 5054 | # reconfigure without layout change |
| 5055 | self.sched.reconfigure(self.config) |
| 5056 | self.waitUntilSettled() |
| 5057 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5058 | |
| 5059 | # semaphore still must be held |
| 5060 | self.assertTrue('test-semaphore' in |
| 5061 | tenant.semaphore_handler.semaphores) |
| 5062 | |
| 5063 | self.commitConfigUpdate( |
| 5064 | 'common-config', |
| 5065 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5066 | self.sched.reconfigure(self.config) |
| 5067 | self.waitUntilSettled() |
| 5068 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5069 | |
| 5070 | self.executor_server.release('project-test1') |
| 5071 | self.waitUntilSettled() |
| 5072 | |
| 5073 | # There should be no builds anymore |
| 5074 | self.assertEqual(len(self.builds), 0) |
| 5075 | |
| 5076 | # The semaphore should be released |
| 5077 | self.assertFalse('test-semaphore' in |
| 5078 | tenant.semaphore_handler.semaphores) |
| 5079 | |
| 5080 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5081 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5082 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5083 | |
| 5084 | def test_semaphore_tenant_isolation(self): |
| 5085 | "Test semaphores in multiple tenants" |
| 5086 | |
| 5087 | self.waitUntilSettled() |
| 5088 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5089 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5090 | |
| 5091 | self.executor_server.hold_jobs_in_build = True |
| 5092 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5093 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5094 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5095 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5096 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5097 | self.assertFalse('test-semaphore' in |
| 5098 | tenant_one.semaphore_handler.semaphores) |
| 5099 | self.assertFalse('test-semaphore' in |
| 5100 | tenant_two.semaphore_handler.semaphores) |
| 5101 | |
| 5102 | # add patches to project1 of tenant-one |
| 5103 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5104 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5105 | self.waitUntilSettled() |
| 5106 | |
| 5107 | # one build of project1-test1 must run |
| 5108 | # semaphore of tenant-one must be acquired once |
| 5109 | # semaphore of tenant-two must not be acquired |
| 5110 | self.assertEqual(len(self.builds), 1) |
| 5111 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5112 | self.assertTrue('test-semaphore' in |
| 5113 | tenant_one.semaphore_handler.semaphores) |
| 5114 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5115 | 'test-semaphore', [])), 1) |
| 5116 | self.assertFalse('test-semaphore' in |
| 5117 | tenant_two.semaphore_handler.semaphores) |
| 5118 | |
| 5119 | # add patches to project2 of tenant-two |
| 5120 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5121 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5122 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5123 | self.waitUntilSettled() |
| 5124 | |
| 5125 | # one build of project1-test1 must run |
| 5126 | # two builds of project2-test1 must run |
| 5127 | # semaphore of tenant-one must be acquired once |
| 5128 | # semaphore of tenant-two must be acquired twice |
| 5129 | self.assertEqual(len(self.builds), 3) |
| 5130 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5131 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5132 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5133 | self.assertTrue('test-semaphore' in |
| 5134 | tenant_one.semaphore_handler.semaphores) |
| 5135 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5136 | 'test-semaphore', [])), 1) |
| 5137 | self.assertTrue('test-semaphore' in |
| 5138 | tenant_two.semaphore_handler.semaphores) |
| 5139 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5140 | 'test-semaphore', [])), 2) |
| 5141 | |
| 5142 | self.executor_server.release('project1-test1') |
| 5143 | self.waitUntilSettled() |
| 5144 | |
| 5145 | # one build of project1-test1 must run |
| 5146 | # two builds of project2-test1 must run |
| 5147 | # semaphore of tenant-one must be acquired once |
| 5148 | # semaphore of tenant-two must be acquired twice |
| 5149 | self.assertEqual(len(self.builds), 3) |
| 5150 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5151 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5152 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5153 | self.assertTrue('test-semaphore' in |
| 5154 | tenant_one.semaphore_handler.semaphores) |
| 5155 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5156 | 'test-semaphore', [])), 1) |
| 5157 | self.assertTrue('test-semaphore' in |
| 5158 | tenant_two.semaphore_handler.semaphores) |
| 5159 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5160 | 'test-semaphore', [])), 2) |
| 5161 | |
| 5162 | self.executor_server.release('project2-test1') |
| 5163 | self.waitUntilSettled() |
| 5164 | |
| 5165 | # one build of project1-test1 must run |
| 5166 | # one build of project2-test1 must run |
| 5167 | # semaphore of tenant-one must be acquired once |
| 5168 | # semaphore of tenant-two must be acquired once |
| 5169 | self.assertEqual(len(self.builds), 2) |
| 5170 | self.assertTrue('test-semaphore' in |
| 5171 | tenant_one.semaphore_handler.semaphores) |
| 5172 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5173 | 'test-semaphore', [])), 1) |
| 5174 | self.assertTrue('test-semaphore' in |
| 5175 | tenant_two.semaphore_handler.semaphores) |
| 5176 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5177 | 'test-semaphore', [])), 1) |
| 5178 | |
| 5179 | self.executor_server.hold_jobs_in_build = False |
| 5180 | self.executor_server.release() |
| 5181 | |
| 5182 | self.waitUntilSettled() |
| 5183 | |
| 5184 | # no build must run |
| 5185 | # semaphore of tenant-one must not be acquired |
| 5186 | # semaphore of tenant-two must not be acquired |
| 5187 | self.assertEqual(len(self.builds), 0) |
| 5188 | self.assertFalse('test-semaphore' in |
| 5189 | tenant_one.semaphore_handler.semaphores) |
| 5190 | self.assertFalse('test-semaphore' in |
| 5191 | tenant_two.semaphore_handler.semaphores) |
| 5192 | |
| 5193 | self.assertEqual(A.reported, 1) |
| 5194 | self.assertEqual(B.reported, 1) |
| 5195 | |
| 5196 | |
| 5197 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5198 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5199 | |
| 5200 | def test_semaphore_in_repo(self): |
| 5201 | "Test semaphores in repo config" |
| 5202 | |
| 5203 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5204 | # max value should not be evaluated dynamically but must be updated |
| 5205 | # after the change lands. |
| 5206 | |
| 5207 | self.waitUntilSettled() |
| 5208 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5209 | |
| 5210 | in_repo_conf = textwrap.dedent( |
| 5211 | """ |
| 5212 | - job: |
| 5213 | name: project-test2 |
| 5214 | semaphore: test-semaphore |
| 5215 | |
| 5216 | - project: |
| 5217 | name: org/project |
| 5218 | tenant-one-gate: |
| 5219 | jobs: |
| 5220 | - project-test2 |
| 5221 | |
| 5222 | # the max value in dynamic layout must be ignored |
| 5223 | - semaphore: |
| 5224 | name: test-semaphore |
| 5225 | max: 2 |
| 5226 | """) |
| 5227 | |
| 5228 | in_repo_playbook = textwrap.dedent( |
| 5229 | """ |
| 5230 | - hosts: all |
| 5231 | tasks: [] |
| 5232 | """) |
| 5233 | |
| 5234 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5235 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5236 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5237 | files=file_dict) |
| 5238 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5239 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5240 | B.setDependsOn(A, 1) |
| 5241 | C.setDependsOn(A, 1) |
| 5242 | |
| 5243 | self.executor_server.hold_jobs_in_build = True |
| 5244 | |
| 5245 | A.addApproval('code-review', 2) |
| 5246 | B.addApproval('code-review', 2) |
| 5247 | C.addApproval('code-review', 2) |
| 5248 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5249 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5250 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5251 | self.waitUntilSettled() |
| 5252 | |
| 5253 | # check that the layout in a queue item still has max value of 1 |
| 5254 | # for test-semaphore |
| 5255 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5256 | queue = None |
| 5257 | for queue_candidate in pipeline.queues: |
| 5258 | if queue_candidate.name == 'org/project': |
| 5259 | queue = queue_candidate |
| 5260 | break |
| 5261 | queue_item = queue.queue[0] |
| 5262 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5263 | dynamic_test_semaphore = \ |
| 5264 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5265 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5266 | |
| 5267 | # one build must be in queue, one semaphores acquired |
| 5268 | self.assertEqual(len(self.builds), 1) |
| 5269 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5270 | self.assertTrue('test-semaphore' in |
| 5271 | tenant.semaphore_handler.semaphores) |
| 5272 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5273 | 'test-semaphore', [])), 1) |
| 5274 | |
| 5275 | self.executor_server.release('project-test2') |
| 5276 | self.waitUntilSettled() |
| 5277 | |
| 5278 | # change A must be merged |
| 5279 | self.assertEqual(A.data['status'], 'MERGED') |
| 5280 | self.assertEqual(A.reported, 2) |
| 5281 | |
| 5282 | # send change-merged event as the gerrit mock doesn't send it |
| 5283 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5284 | self.waitUntilSettled() |
| 5285 | |
| 5286 | # now that change A was merged, the new semaphore max must be effective |
| 5287 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5288 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5289 | |
| 5290 | # two builds must be in queue, two semaphores acquired |
| 5291 | self.assertEqual(len(self.builds), 2) |
| 5292 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5293 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5294 | self.assertTrue('test-semaphore' in |
| 5295 | tenant.semaphore_handler.semaphores) |
| 5296 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5297 | 'test-semaphore', [])), 2) |
| 5298 | |
| 5299 | self.executor_server.release('project-test2') |
| 5300 | self.waitUntilSettled() |
| 5301 | |
| 5302 | self.assertEqual(len(self.builds), 0) |
| 5303 | self.assertFalse('test-semaphore' in |
| 5304 | tenant.semaphore_handler.semaphores) |
| 5305 | |
| 5306 | self.executor_server.hold_jobs_in_build = False |
| 5307 | self.executor_server.release() |
| 5308 | |
| 5309 | self.waitUntilSettled() |
| 5310 | self.assertEqual(len(self.builds), 0) |
| 5311 | |
| 5312 | self.assertEqual(A.reported, 2) |
| 5313 | self.assertEqual(B.reported, 2) |
| 5314 | self.assertEqual(C.reported, 2) |