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 |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 24 | import sys |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | import time |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 26 | from unittest import (skip, skipIf) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 27 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 28 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 29 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 30 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 32 | import zuul.change_matcher |
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?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 67 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 68 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 69 | value='1|g') |
| 70 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 71 | kind='ms') |
| 72 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 73 | value='1|c') |
| 74 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 75 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 76 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 77 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 78 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 79 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 80 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 81 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 82 | for build in self.builds: |
| 83 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 84 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 85 | def test_initial_pipeline_gauges(self): |
| 86 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 87 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 88 | value='0|g') |
| 89 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 90 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 91 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 92 | def test_job_branch(self): |
| 93 | "Test the correct variant of a job runs on a branch" |
| 94 | self.create_branch('org/project', 'stable') |
| 95 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 96 | A.addApproval('code-review', 2) |
| 97 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 98 | self.waitUntilSettled() |
| 99 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 100 | 'SUCCESS') |
| 101 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 102 | 'SUCCESS') |
| 103 | self.assertEqual(A.data['status'], 'MERGED') |
| 104 | self.assertEqual(A.reported, 2, |
| 105 | "A should report start and success") |
| 106 | self.assertIn('gate', A.messages[1], |
| 107 | "A should transit gate") |
| 108 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 109 | 'image2') |
| 110 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 111 | def test_parallel_changes(self): |
| 112 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 113 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 114 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 115 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 116 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 117 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 118 | A.addApproval('code-review', 2) |
| 119 | B.addApproval('code-review', 2) |
| 120 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 121 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 122 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 123 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 124 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 125 | |
| 126 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 127 | self.assertEqual(len(self.builds), 1) |
| 128 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 129 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 130 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 131 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 132 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 133 | self.assertEqual(len(self.builds), 3) |
| 134 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 135 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 136 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 137 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 138 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 139 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 140 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 141 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 142 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 143 | self.assertEqual(len(self.builds), 5) |
| 144 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 145 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 146 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 147 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 148 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 149 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 150 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 151 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 152 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 154 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 155 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 156 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 157 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 158 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 159 | self.assertEqual(len(self.builds), 6) |
| 160 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 161 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 162 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 165 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 166 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 167 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 168 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 169 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 170 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 171 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 172 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 173 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 174 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 175 | self.executor_server.hold_jobs_in_build = False |
| 176 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 177 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 178 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 179 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 180 | self.assertEqual(len(self.history), 9) |
| 181 | self.assertEqual(A.data['status'], 'MERGED') |
| 182 | self.assertEqual(B.data['status'], 'MERGED') |
| 183 | self.assertEqual(C.data['status'], 'MERGED') |
| 184 | self.assertEqual(A.reported, 2) |
| 185 | self.assertEqual(B.reported, 2) |
| 186 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 187 | |
| 188 | def test_failed_changes(self): |
| 189 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 190 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 191 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 192 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 193 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 194 | A.addApproval('code-review', 2) |
| 195 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 196 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 197 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 198 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 199 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 200 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 201 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 202 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 203 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 204 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 205 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 206 | # A/project-merge is complete |
| 207 | self.assertBuilds([ |
| 208 | dict(name='project-test1', changes='1,1'), |
| 209 | dict(name='project-test2', changes='1,1'), |
| 210 | dict(name='project-merge', changes='1,1 2,1'), |
| 211 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 212 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 213 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 214 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 215 | # A/project-merge is complete |
| 216 | # B/project-merge is complete |
| 217 | self.assertBuilds([ |
| 218 | dict(name='project-test1', changes='1,1'), |
| 219 | dict(name='project-test2', changes='1,1'), |
| 220 | dict(name='project-test1', changes='1,1 2,1'), |
| 221 | dict(name='project-test2', changes='1,1 2,1'), |
| 222 | ]) |
| 223 | |
| 224 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 225 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 226 | self.builds[0].release() |
| 227 | self.waitUntilSettled() |
| 228 | |
| 229 | self.orderedRelease() |
| 230 | self.assertHistory([ |
| 231 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 232 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 233 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 234 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 235 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 236 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 237 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 238 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 239 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 240 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 241 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 242 | self.assertEqual(A.data['status'], 'NEW') |
| 243 | self.assertEqual(B.data['status'], 'MERGED') |
| 244 | self.assertEqual(A.reported, 2) |
| 245 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 246 | |
| 247 | def test_independent_queues(self): |
| 248 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 249 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 250 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 251 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 252 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 253 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 254 | A.addApproval('code-review', 2) |
| 255 | B.addApproval('code-review', 2) |
| 256 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 257 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 258 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 259 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 260 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 261 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 262 | self.waitUntilSettled() |
| 263 | |
| 264 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 265 | self.waitUntilSettled() |
| 266 | |
| 267 | # 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] | 268 | self.assertBuilds([ |
| 269 | dict(name='project-merge', changes='1,1'), |
| 270 | dict(name='project-merge', changes='2,1'), |
| 271 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 272 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 273 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 274 | self.builds[0].release() |
| 275 | self.waitUntilSettled() |
| 276 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 277 | self.waitUntilSettled() |
| 278 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 279 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 280 | self.waitUntilSettled() |
| 281 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 282 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 283 | self.assertBuilds([ |
| 284 | dict(name='project-test1', changes='1,1'), |
| 285 | dict(name='project-test2', changes='1,1'), |
| 286 | dict(name='project-test1', changes='2,1'), |
| 287 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 288 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 289 | dict(name='project-test1', changes='2,1 3,1'), |
| 290 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 291 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 292 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 293 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 294 | self.orderedRelease() |
| 295 | self.assertHistory([ |
| 296 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 297 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 298 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 299 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 300 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 301 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 302 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 303 | dict( |
| 304 | name='project1-project2-integration', |
| 305 | result='SUCCESS', |
| 306 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 307 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 308 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 309 | dict(name='project1-project2-integration', |
| 310 | result='SUCCESS', |
| 311 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 312 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 313 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 314 | self.assertEqual(A.data['status'], 'MERGED') |
| 315 | self.assertEqual(B.data['status'], 'MERGED') |
| 316 | self.assertEqual(C.data['status'], 'MERGED') |
| 317 | self.assertEqual(A.reported, 2) |
| 318 | self.assertEqual(B.reported, 2) |
| 319 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 320 | |
| 321 | def test_failed_change_at_head(self): |
| 322 | "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] | 323 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 324 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 325 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 326 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 327 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 328 | A.addApproval('code-review', 2) |
| 329 | B.addApproval('code-review', 2) |
| 330 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 331 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 332 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 333 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 334 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 335 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 336 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 337 | |
| 338 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 339 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 340 | self.assertBuilds([ |
| 341 | dict(name='project-merge', changes='1,1'), |
| 342 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 343 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 344 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 346 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 347 | self.waitUntilSettled() |
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() |
| 350 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 351 | self.assertBuilds([ |
| 352 | dict(name='project-test1', changes='1,1'), |
| 353 | dict(name='project-test2', changes='1,1'), |
| 354 | dict(name='project-test1', changes='1,1 2,1'), |
| 355 | dict(name='project-test2', changes='1,1 2,1'), |
| 356 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 357 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 358 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 359 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 360 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 361 | self.waitUntilSettled() |
| 362 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 363 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 364 | self.assertBuilds([ |
| 365 | dict(name='project-test2', changes='1,1'), |
| 366 | dict(name='project-merge', changes='2,1'), |
| 367 | ]) |
| 368 | # Unordered history comparison because the aborts can finish |
| 369 | # in any order. |
| 370 | self.assertHistory([ |
| 371 | dict(name='project-merge', result='SUCCESS', |
| 372 | changes='1,1'), |
| 373 | dict(name='project-merge', result='SUCCESS', |
| 374 | changes='1,1 2,1'), |
| 375 | dict(name='project-merge', result='SUCCESS', |
| 376 | changes='1,1 2,1 3,1'), |
| 377 | dict(name='project-test1', result='FAILURE', |
| 378 | changes='1,1'), |
| 379 | dict(name='project-test1', result='ABORTED', |
| 380 | changes='1,1 2,1'), |
| 381 | dict(name='project-test2', result='ABORTED', |
| 382 | changes='1,1 2,1'), |
| 383 | dict(name='project-test1', result='ABORTED', |
| 384 | changes='1,1 2,1 3,1'), |
| 385 | dict(name='project-test2', result='ABORTED', |
| 386 | changes='1,1 2,1 3,1'), |
| 387 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 389 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 390 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 391 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 392 | self.waitUntilSettled() |
| 393 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 394 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 395 | self.assertBuilds([]) |
| 396 | self.assertHistory([ |
| 397 | dict(name='project-merge', result='SUCCESS', |
| 398 | changes='1,1'), |
| 399 | dict(name='project-merge', result='SUCCESS', |
| 400 | changes='1,1 2,1'), |
| 401 | dict(name='project-merge', result='SUCCESS', |
| 402 | changes='1,1 2,1 3,1'), |
| 403 | dict(name='project-test1', result='FAILURE', |
| 404 | changes='1,1'), |
| 405 | dict(name='project-test1', result='ABORTED', |
| 406 | changes='1,1 2,1'), |
| 407 | dict(name='project-test2', result='ABORTED', |
| 408 | changes='1,1 2,1'), |
| 409 | dict(name='project-test1', result='ABORTED', |
| 410 | changes='1,1 2,1 3,1'), |
| 411 | dict(name='project-test2', result='ABORTED', |
| 412 | changes='1,1 2,1 3,1'), |
| 413 | dict(name='project-merge', result='SUCCESS', |
| 414 | changes='2,1'), |
| 415 | dict(name='project-merge', result='SUCCESS', |
| 416 | changes='2,1 3,1'), |
| 417 | dict(name='project-test2', result='SUCCESS', |
| 418 | changes='1,1'), |
| 419 | dict(name='project-test1', result='SUCCESS', |
| 420 | changes='2,1'), |
| 421 | dict(name='project-test2', result='SUCCESS', |
| 422 | changes='2,1'), |
| 423 | dict(name='project-test1', result='SUCCESS', |
| 424 | changes='2,1 3,1'), |
| 425 | dict(name='project-test2', result='SUCCESS', |
| 426 | changes='2,1 3,1'), |
| 427 | ], ordered=False) |
| 428 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 429 | self.assertEqual(A.data['status'], 'NEW') |
| 430 | self.assertEqual(B.data['status'], 'MERGED') |
| 431 | self.assertEqual(C.data['status'], 'MERGED') |
| 432 | self.assertEqual(A.reported, 2) |
| 433 | self.assertEqual(B.reported, 2) |
| 434 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 435 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 436 | def test_failed_change_in_middle(self): |
| 437 | "Test a failed change in the middle of the queue" |
| 438 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 439 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 440 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 441 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 442 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 443 | A.addApproval('code-review', 2) |
| 444 | B.addApproval('code-review', 2) |
| 445 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 446 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 447 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 448 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 449 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 450 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 451 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 452 | |
| 453 | self.waitUntilSettled() |
| 454 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 455 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 456 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 457 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 458 | self.waitUntilSettled() |
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() |
| 461 | |
| 462 | self.assertEqual(len(self.builds), 6) |
| 463 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 464 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 465 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 466 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 467 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 468 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 469 | |
| 470 | self.release(self.builds[2]) |
| 471 | self.waitUntilSettled() |
| 472 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 473 | # project-test1 and project-test2 for A |
| 474 | # project-test2 for B |
| 475 | # project-merge for C (without B) |
| 476 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 477 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 478 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 479 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 480 | self.waitUntilSettled() |
| 481 | |
| 482 | # project-test1 and project-test2 for A |
| 483 | # project-test2 for B |
| 484 | # project-test1 and project-test2 for C |
| 485 | self.assertEqual(len(self.builds), 5) |
| 486 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 487 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 488 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 489 | builds = items[0].current_build_set.getBuilds() |
| 490 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 491 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 492 | builds = items[1].current_build_set.getBuilds() |
| 493 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 494 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 495 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 496 | builds = items[2].current_build_set.getBuilds() |
| 497 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 498 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 499 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 500 | self.executor_server.hold_jobs_in_build = False |
| 501 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 502 | self.waitUntilSettled() |
| 503 | |
| 504 | self.assertEqual(len(self.builds), 0) |
| 505 | self.assertEqual(len(self.history), 12) |
| 506 | self.assertEqual(A.data['status'], 'MERGED') |
| 507 | self.assertEqual(B.data['status'], 'NEW') |
| 508 | self.assertEqual(C.data['status'], 'MERGED') |
| 509 | self.assertEqual(A.reported, 2) |
| 510 | self.assertEqual(B.reported, 2) |
| 511 | self.assertEqual(C.reported, 2) |
| 512 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 513 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 514 | def test_failed_change_at_head_with_queue(self): |
| 515 | "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] | 516 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 517 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 518 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 519 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 520 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 521 | A.addApproval('code-review', 2) |
| 522 | B.addApproval('code-review', 2) |
| 523 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 524 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 525 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 526 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 527 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 528 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 529 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 530 | |
| 531 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 532 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 533 | self.assertEqual(len(self.builds), 0) |
| 534 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 535 | self.assertEqual(queue[0].name, b'executor:execute') |
| 536 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 537 | self.assertEqual(job_args['job'], 'project-merge') |
| 538 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 539 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 540 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 541 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 542 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 544 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 545 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 546 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 547 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 548 | self.assertEqual(len(self.builds), 0) |
| 549 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 550 | |
| 551 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 552 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 553 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 554 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 555 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 556 | 'project-test2') |
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[2].arguments.decode('utf8'))['job'], |
| 559 | 'project-test1') |
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[3].arguments.decode('utf8'))['job'], |
| 562 | 'project-test2') |
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[4].arguments.decode('utf8'))['job'], |
| 565 | 'project-test1') |
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[5].arguments.decode('utf8'))['job'], |
| 568 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 569 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 570 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 571 | self.waitUntilSettled() |
| 572 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 573 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 574 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 575 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 576 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 577 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 578 | self.gearman_server.hold_jobs_in_queue = False |
| 579 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 580 | self.waitUntilSettled() |
| 581 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 582 | self.assertEqual(len(self.builds), 0) |
| 583 | self.assertEqual(len(self.history), 11) |
| 584 | self.assertEqual(A.data['status'], 'NEW') |
| 585 | self.assertEqual(B.data['status'], 'MERGED') |
| 586 | self.assertEqual(C.data['status'], 'MERGED') |
| 587 | self.assertEqual(A.reported, 2) |
| 588 | self.assertEqual(B.reported, 2) |
| 589 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 590 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 591 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 592 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 593 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 594 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 595 | A.addApproval('code-review', 2) |
| 596 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 597 | self.waitUntilSettled() |
| 598 | time.sleep(2) |
| 599 | |
| 600 | data = json.loads(self.sched.formatStatusJSON()) |
| 601 | found_job = None |
| 602 | for pipeline in data['pipelines']: |
| 603 | if pipeline['name'] != 'gate': |
| 604 | continue |
| 605 | for queue in pipeline['change_queues']: |
| 606 | for head in queue['heads']: |
| 607 | for item in head: |
| 608 | for job in item['jobs']: |
| 609 | if job['name'] == 'project-merge': |
| 610 | found_job = job |
| 611 | break |
| 612 | |
| 613 | self.assertIsNotNone(found_job) |
| 614 | if iteration == 1: |
| 615 | self.assertIsNotNone(found_job['estimated_time']) |
| 616 | self.assertIsNone(found_job['remaining_time']) |
| 617 | else: |
| 618 | self.assertIsNotNone(found_job['estimated_time']) |
| 619 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 620 | self.assertIsNotNone(found_job['remaining_time']) |
| 621 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 622 | self.executor_server.hold_jobs_in_build = False |
| 623 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 624 | self.waitUntilSettled() |
| 625 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 626 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 627 | def test_time_database(self): |
| 628 | "Test the time database" |
| 629 | |
| 630 | self._test_time_database(1) |
| 631 | self._test_time_database(2) |
| 632 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 633 | def test_two_failed_changes_at_head(self): |
| 634 | "Test that changes are reparented correctly if 2 fail at head" |
| 635 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 636 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 637 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 638 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 639 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 640 | A.addApproval('code-review', 2) |
| 641 | B.addApproval('code-review', 2) |
| 642 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 643 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 644 | self.executor_server.failJob('project-test1', A) |
| 645 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 646 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 647 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 648 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 649 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 650 | self.waitUntilSettled() |
| 651 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 652 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 653 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 654 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 655 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 656 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 657 | self.waitUntilSettled() |
| 658 | |
| 659 | self.assertEqual(len(self.builds), 6) |
| 660 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 661 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 662 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 663 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 664 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 665 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 666 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 667 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 668 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 669 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 670 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 671 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 672 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 673 | |
| 674 | # Fail change B first |
| 675 | self.release(self.builds[2]) |
| 676 | self.waitUntilSettled() |
| 677 | |
| 678 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 679 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 680 | self.waitUntilSettled() |
| 681 | |
| 682 | self.assertEqual(len(self.builds), 5) |
| 683 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 684 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 685 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 686 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 687 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 688 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 689 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 690 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 691 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 692 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 693 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 694 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 695 | |
| 696 | # Finish running all passing jobs for change A |
| 697 | self.release(self.builds[1]) |
| 698 | self.waitUntilSettled() |
| 699 | # Fail and report change A |
| 700 | self.release(self.builds[0]) |
| 701 | self.waitUntilSettled() |
| 702 | |
| 703 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 704 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 705 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 706 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | self.waitUntilSettled() |
| 708 | |
| 709 | self.assertEqual(len(self.builds), 4) |
| 710 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 711 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 712 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 713 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 714 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 715 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 716 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 717 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 718 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 719 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 720 | # After A failed and B and C restarted, B should be back in |
| 721 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 722 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 723 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 724 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 725 | self.executor_server.hold_jobs_in_build = False |
| 726 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 727 | self.waitUntilSettled() |
| 728 | |
| 729 | self.assertEqual(len(self.builds), 0) |
| 730 | self.assertEqual(len(self.history), 21) |
| 731 | self.assertEqual(A.data['status'], 'NEW') |
| 732 | self.assertEqual(B.data['status'], 'NEW') |
| 733 | self.assertEqual(C.data['status'], 'MERGED') |
| 734 | self.assertEqual(A.reported, 2) |
| 735 | self.assertEqual(B.reported, 2) |
| 736 | self.assertEqual(C.reported, 2) |
| 737 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 738 | def test_patch_order(self): |
| 739 | "Test that dependent patches are tested in the right order" |
| 740 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 741 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 742 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 743 | A.addApproval('code-review', 2) |
| 744 | B.addApproval('code-review', 2) |
| 745 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 746 | |
| 747 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 748 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 749 | M2.setMerged() |
| 750 | M1.setMerged() |
| 751 | |
| 752 | # C -> B -> A -> M1 -> M2 |
| 753 | # M2 is here to make sure it is never queried. If it is, it |
| 754 | # means zuul is walking down the entire history of merged |
| 755 | # changes. |
| 756 | |
| 757 | C.setDependsOn(B, 1) |
| 758 | B.setDependsOn(A, 1) |
| 759 | A.setDependsOn(M1, 1) |
| 760 | M1.setDependsOn(M2, 1) |
| 761 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 762 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 763 | |
| 764 | self.waitUntilSettled() |
| 765 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 766 | self.assertEqual(A.data['status'], 'NEW') |
| 767 | self.assertEqual(B.data['status'], 'NEW') |
| 768 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 769 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 770 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 771 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 772 | |
| 773 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 774 | self.assertEqual(M2.queried, 0) |
| 775 | self.assertEqual(A.data['status'], 'MERGED') |
| 776 | self.assertEqual(B.data['status'], 'MERGED') |
| 777 | self.assertEqual(C.data['status'], 'MERGED') |
| 778 | self.assertEqual(A.reported, 2) |
| 779 | self.assertEqual(B.reported, 2) |
| 780 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 781 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 782 | def test_needed_changes_enqueue(self): |
| 783 | "Test that a needed change is enqueued ahead" |
| 784 | # A Given a git tree like this, if we enqueue |
| 785 | # / \ change C, we should walk up and down the tree |
| 786 | # B G and enqueue changes in the order ABCDEFG. |
| 787 | # /|\ This is also the order that you would get if |
| 788 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 789 | # / the ordering is stable across re-enqueue events. |
| 790 | # D |
| 791 | |
| 792 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 793 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 794 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 795 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 796 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 797 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 798 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 799 | B.setDependsOn(A, 1) |
| 800 | C.setDependsOn(B, 1) |
| 801 | D.setDependsOn(C, 1) |
| 802 | E.setDependsOn(B, 1) |
| 803 | F.setDependsOn(B, 1) |
| 804 | G.setDependsOn(A, 1) |
| 805 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 806 | A.addApproval('code-review', 2) |
| 807 | B.addApproval('code-review', 2) |
| 808 | C.addApproval('code-review', 2) |
| 809 | D.addApproval('code-review', 2) |
| 810 | E.addApproval('code-review', 2) |
| 811 | F.addApproval('code-review', 2) |
| 812 | G.addApproval('code-review', 2) |
| 813 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 814 | |
| 815 | self.waitUntilSettled() |
| 816 | |
| 817 | self.assertEqual(A.data['status'], 'NEW') |
| 818 | self.assertEqual(B.data['status'], 'NEW') |
| 819 | self.assertEqual(C.data['status'], 'NEW') |
| 820 | self.assertEqual(D.data['status'], 'NEW') |
| 821 | self.assertEqual(E.data['status'], 'NEW') |
| 822 | self.assertEqual(F.data['status'], 'NEW') |
| 823 | self.assertEqual(G.data['status'], 'NEW') |
| 824 | |
| 825 | # We're about to add approvals to changes without adding the |
| 826 | # triggering events to Zuul, so that we can be sure that it is |
| 827 | # enqueing the changes based on dependencies, not because of |
| 828 | # triggering events. Since it will have the changes cached |
| 829 | # already (without approvals), we need to clear the cache |
| 830 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 831 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 832 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 833 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 834 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 835 | A.addApproval('approved', 1) |
| 836 | B.addApproval('approved', 1) |
| 837 | D.addApproval('approved', 1) |
| 838 | E.addApproval('approved', 1) |
| 839 | F.addApproval('approved', 1) |
| 840 | G.addApproval('approved', 1) |
| 841 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 842 | |
| 843 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 844 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 845 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 846 | self.executor_server.hold_jobs_in_build = False |
| 847 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 848 | self.waitUntilSettled() |
| 849 | |
| 850 | self.assertEqual(A.data['status'], 'MERGED') |
| 851 | self.assertEqual(B.data['status'], 'MERGED') |
| 852 | self.assertEqual(C.data['status'], 'MERGED') |
| 853 | self.assertEqual(D.data['status'], 'MERGED') |
| 854 | self.assertEqual(E.data['status'], 'MERGED') |
| 855 | self.assertEqual(F.data['status'], 'MERGED') |
| 856 | self.assertEqual(G.data['status'], 'MERGED') |
| 857 | self.assertEqual(A.reported, 2) |
| 858 | self.assertEqual(B.reported, 2) |
| 859 | self.assertEqual(C.reported, 2) |
| 860 | self.assertEqual(D.reported, 2) |
| 861 | self.assertEqual(E.reported, 2) |
| 862 | self.assertEqual(F.reported, 2) |
| 863 | self.assertEqual(G.reported, 2) |
| 864 | self.assertEqual(self.history[6].changes, |
| 865 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 866 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 867 | def test_source_cache(self): |
| 868 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 869 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 870 | |
| 871 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 872 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 873 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 874 | A.addApproval('code-review', 2) |
| 875 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 876 | |
| 877 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 878 | M1.setMerged() |
| 879 | |
| 880 | B.setDependsOn(A, 1) |
| 881 | A.setDependsOn(M1, 1) |
| 882 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 883 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 884 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 885 | |
| 886 | self.waitUntilSettled() |
| 887 | |
| 888 | for build in self.builds: |
| 889 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 890 | build.release() |
| 891 | self.waitUntilSettled() |
| 892 | for build in self.builds: |
| 893 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 894 | build.release() |
| 895 | self.waitUntilSettled() |
| 896 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 897 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 898 | self.waitUntilSettled() |
| 899 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 900 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 901 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 902 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 903 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 904 | self.executor_server.hold_jobs_in_build = False |
| 905 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 906 | self.waitUntilSettled() |
| 907 | |
| 908 | self.assertEqual(A.data['status'], 'MERGED') |
| 909 | self.assertEqual(B.data['status'], 'MERGED') |
| 910 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 911 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 912 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 913 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 914 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 915 | # TODO: move to test_gerrit (this is a unit test!) |
| 916 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 917 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 918 | (trusted, project) = tenant.getProject('org/project') |
| 919 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 920 | |
| 921 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 922 | # it easier for users to create events for testing. |
| 923 | event = zuul.model.TriggerEvent() |
| 924 | event.trigger_name = 'gerrit' |
| 925 | event.change_number = '1' |
| 926 | event.patch_number = '2' |
| 927 | |
| 928 | a = source.getChange(event) |
| 929 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 930 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 931 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 932 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 933 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 934 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 935 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 936 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 937 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 938 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 939 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 940 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 941 | def test_project_merge_conflict(self): |
| 942 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 943 | |
| 944 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 945 | A = self.fake_gerrit.addFakeChange('org/project', |
| 946 | 'master', 'A', |
| 947 | files={'conflict': 'foo'}) |
| 948 | B = self.fake_gerrit.addFakeChange('org/project', |
| 949 | 'master', 'B', |
| 950 | files={'conflict': 'bar'}) |
| 951 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 952 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 953 | A.addApproval('code-review', 2) |
| 954 | B.addApproval('code-review', 2) |
| 955 | C.addApproval('code-review', 2) |
| 956 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 957 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 958 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 959 | self.waitUntilSettled() |
| 960 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 961 | self.assertEqual(A.reported, 1) |
| 962 | self.assertEqual(B.reported, 1) |
| 963 | self.assertEqual(C.reported, 1) |
| 964 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 965 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 966 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 967 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 968 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 969 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 970 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 971 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 972 | self.gearman_server.hold_jobs_in_queue = False |
| 973 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 974 | self.waitUntilSettled() |
| 975 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 976 | self.assertEqual(A.data['status'], 'MERGED') |
| 977 | self.assertEqual(B.data['status'], 'NEW') |
| 978 | self.assertEqual(C.data['status'], 'MERGED') |
| 979 | self.assertEqual(A.reported, 2) |
| 980 | self.assertEqual(B.reported, 2) |
| 981 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 982 | |
| 983 | self.assertHistory([ |
| 984 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 985 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 986 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 987 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 988 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 989 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 990 | ], ordered=False) |
| 991 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 992 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 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 |
| 997 | # the executor returns a merge failure after the scheduler has |
| 998 | # successfully merged. |
| 999 | self.gearman_server.hold_jobs_in_queue = True |
| 1000 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1001 | 'master', 'A', |
| 1002 | files={'conflict': 'foo'}) |
| 1003 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1004 | 'master', 'B', |
| 1005 | files={'conflict': 'bar'}) |
| 1006 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1007 | 'master', 'C') |
| 1008 | C.setDependsOn(B, 1) |
| 1009 | |
| 1010 | # A enters the gate queue; B and C enter the check queue |
| 1011 | A.addApproval('code-review', 2) |
| 1012 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1013 | self.waitUntilSettled() |
| 1014 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1015 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1016 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1017 | self.waitUntilSettled() |
| 1018 | |
| 1019 | self.assertEqual(A.reported, 1) |
| 1020 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1021 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1022 | |
| 1023 | # A merges while B and C are queued in check |
| 1024 | # Release A project-merge |
| 1025 | queue = self.gearman_server.getQueue() |
| 1026 | self.release(queue[0]) |
| 1027 | self.waitUntilSettled() |
| 1028 | |
| 1029 | # Release A project-test* |
| 1030 | # gate has higher precedence, so A's test jobs are added in |
| 1031 | # front of the merge jobs for B and C |
| 1032 | queue = self.gearman_server.getQueue() |
| 1033 | self.release(queue[0]) |
| 1034 | self.release(queue[1]) |
| 1035 | self.waitUntilSettled() |
| 1036 | |
| 1037 | self.assertEqual(A.data['status'], 'MERGED') |
| 1038 | self.assertEqual(B.data['status'], 'NEW') |
| 1039 | self.assertEqual(C.data['status'], 'NEW') |
| 1040 | self.assertEqual(A.reported, 2) |
| 1041 | self.assertEqual(B.reported, 0) |
| 1042 | self.assertEqual(C.reported, 0) |
| 1043 | self.assertHistory([ |
| 1044 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1045 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1046 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1047 | ], ordered=False) |
| 1048 | |
| 1049 | # B and C report merge conflicts |
| 1050 | # Release B project-merge |
| 1051 | queue = self.gearman_server.getQueue() |
| 1052 | self.release(queue[0]) |
| 1053 | self.waitUntilSettled() |
| 1054 | |
| 1055 | # Release C |
| 1056 | self.gearman_server.hold_jobs_in_queue = False |
| 1057 | self.gearman_server.release() |
| 1058 | self.waitUntilSettled() |
| 1059 | |
| 1060 | self.assertEqual(A.data['status'], 'MERGED') |
| 1061 | self.assertEqual(B.data['status'], 'NEW') |
| 1062 | self.assertEqual(C.data['status'], 'NEW') |
| 1063 | self.assertEqual(A.reported, 2) |
| 1064 | self.assertEqual(B.reported, 1) |
| 1065 | self.assertEqual(C.reported, 1) |
| 1066 | |
| 1067 | self.assertHistory([ |
| 1068 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1069 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1070 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-merge', result='MERGER_FAILURE', changes='2,1'), |
| 1072 | dict(name='project-merge', result='MERGER_FAILURE', |
| 1073 | changes='2,1 3,1'), |
| 1074 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1075 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1076 | def test_post(self): |
| 1077 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1078 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1079 | e = { |
| 1080 | "type": "ref-updated", |
| 1081 | "submitter": { |
| 1082 | "name": "User Name", |
| 1083 | }, |
| 1084 | "refUpdate": { |
| 1085 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1086 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1087 | "refName": "master", |
| 1088 | "project": "org/project", |
| 1089 | } |
| 1090 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1091 | self.fake_gerrit.addEvent(e) |
| 1092 | self.waitUntilSettled() |
| 1093 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1094 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1095 | self.assertEqual(len(self.history), 1) |
| 1096 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1097 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1098 | def test_post_ignore_deletes(self): |
| 1099 | "Test that deleting refs does not trigger post jobs" |
| 1100 | |
| 1101 | e = { |
| 1102 | "type": "ref-updated", |
| 1103 | "submitter": { |
| 1104 | "name": "User Name", |
| 1105 | }, |
| 1106 | "refUpdate": { |
| 1107 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1108 | "newRev": "0000000000000000000000000000000000000000", |
| 1109 | "refName": "master", |
| 1110 | "project": "org/project", |
| 1111 | } |
| 1112 | } |
| 1113 | self.fake_gerrit.addEvent(e) |
| 1114 | self.waitUntilSettled() |
| 1115 | |
| 1116 | job_names = [x.name for x in self.history] |
| 1117 | self.assertEqual(len(self.history), 0) |
| 1118 | self.assertNotIn('project-post', job_names) |
| 1119 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1120 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1121 | def test_post_ignore_deletes_negative(self): |
| 1122 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1123 | e = { |
| 1124 | "type": "ref-updated", |
| 1125 | "submitter": { |
| 1126 | "name": "User Name", |
| 1127 | }, |
| 1128 | "refUpdate": { |
| 1129 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1130 | "newRev": "0000000000000000000000000000000000000000", |
| 1131 | "refName": "master", |
| 1132 | "project": "org/project", |
| 1133 | } |
| 1134 | } |
| 1135 | self.fake_gerrit.addEvent(e) |
| 1136 | self.waitUntilSettled() |
| 1137 | |
| 1138 | job_names = [x.name for x in self.history] |
| 1139 | self.assertEqual(len(self.history), 1) |
| 1140 | self.assertIn('project-post', job_names) |
| 1141 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1142 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1143 | def test_build_configuration_branch_interaction(self): |
| 1144 | "Test that switching between branches works" |
| 1145 | self.test_build_configuration() |
| 1146 | self.test_build_configuration_branch() |
| 1147 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1148 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1149 | repo = git.Repo(path) |
| 1150 | repo.heads.master.commit = repo.commit('init') |
| 1151 | self.test_build_configuration() |
| 1152 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1153 | def test_dependent_changes_dequeue(self): |
| 1154 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1155 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1156 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1157 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1158 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1159 | A.addApproval('code-review', 2) |
| 1160 | B.addApproval('code-review', 2) |
| 1161 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1162 | |
| 1163 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1164 | M1.setMerged() |
| 1165 | |
| 1166 | # C -> B -> A -> M1 |
| 1167 | |
| 1168 | C.setDependsOn(B, 1) |
| 1169 | B.setDependsOn(A, 1) |
| 1170 | A.setDependsOn(M1, 1) |
| 1171 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1172 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1173 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1174 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1175 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1176 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1177 | |
| 1178 | self.waitUntilSettled() |
| 1179 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1180 | self.assertEqual(A.data['status'], 'NEW') |
| 1181 | self.assertEqual(A.reported, 2) |
| 1182 | self.assertEqual(B.data['status'], 'NEW') |
| 1183 | self.assertEqual(B.reported, 2) |
| 1184 | self.assertEqual(C.data['status'], 'NEW') |
| 1185 | self.assertEqual(C.reported, 2) |
| 1186 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1187 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1188 | def test_failing_dependent_changes(self): |
| 1189 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1190 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1191 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1192 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1193 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1194 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1195 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1196 | A.addApproval('code-review', 2) |
| 1197 | B.addApproval('code-review', 2) |
| 1198 | C.addApproval('code-review', 2) |
| 1199 | D.addApproval('code-review', 2) |
| 1200 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1201 | |
| 1202 | # E, D -> C -> B, A |
| 1203 | |
| 1204 | D.setDependsOn(C, 1) |
| 1205 | C.setDependsOn(B, 1) |
| 1206 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1207 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1208 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1209 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1210 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1211 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1212 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1213 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1214 | |
| 1215 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1216 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1217 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1218 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1219 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1220 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1221 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1222 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1223 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1224 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1225 | self.waitUntilSettled() |
| 1226 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1227 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1228 | for build in self.builds: |
| 1229 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1230 | build.release() |
| 1231 | self.waitUntilSettled() |
| 1232 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1233 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1234 | self.waitUntilSettled() |
| 1235 | |
| 1236 | self.assertEqual(A.data['status'], 'MERGED') |
| 1237 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1238 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1239 | self.assertEqual(B.data['status'], 'NEW') |
| 1240 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1241 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1242 | self.assertEqual(C.data['status'], 'NEW') |
| 1243 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1244 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1245 | self.assertEqual(D.data['status'], 'NEW') |
| 1246 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1247 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1248 | self.assertEqual(E.data['status'], 'MERGED') |
| 1249 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1250 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1251 | self.assertEqual(len(self.history), 18) |
| 1252 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1253 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1254 | "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] | 1255 | # If it's dequeued more than once, we should see extra |
| 1256 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1257 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1258 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1259 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1260 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1261 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1262 | A.addApproval('code-review', 2) |
| 1263 | B.addApproval('code-review', 2) |
| 1264 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1265 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1266 | self.executor_server.failJob('project-test1', A) |
| 1267 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1268 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1269 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1270 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1271 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1272 | |
| 1273 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1274 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1275 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1276 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1277 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1278 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1279 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1280 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1281 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1282 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1283 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1284 | self.waitUntilSettled() |
| 1285 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1286 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1287 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1288 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1289 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1290 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1291 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1292 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1293 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1294 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1295 | self.waitUntilSettled() |
| 1296 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1297 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1298 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1300 | self.executor_server.hold_jobs_in_build = False |
| 1301 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1302 | self.waitUntilSettled() |
| 1303 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1304 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1305 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1306 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1307 | self.assertEqual(A.data['status'], 'NEW') |
| 1308 | self.assertEqual(B.data['status'], 'MERGED') |
| 1309 | self.assertEqual(C.data['status'], 'MERGED') |
| 1310 | self.assertEqual(A.reported, 2) |
| 1311 | self.assertEqual(B.reported, 2) |
| 1312 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1313 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1314 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1315 | def test_nonvoting_job(self): |
| 1316 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1317 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1318 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1319 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1320 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1321 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1322 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1323 | |
| 1324 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1325 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1326 | self.assertEqual(A.data['status'], 'MERGED') |
| 1327 | self.assertEqual(A.reported, 2) |
| 1328 | self.assertEqual( |
| 1329 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1330 | 'SUCCESS') |
| 1331 | self.assertEqual( |
| 1332 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1333 | 'SUCCESS') |
| 1334 | self.assertEqual( |
| 1335 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1336 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1337 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1338 | for build in self.builds: |
| 1339 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1340 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1341 | def test_check_queue_success(self): |
| 1342 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1343 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1344 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1345 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1346 | |
| 1347 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1348 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1349 | self.assertEqual(A.data['status'], 'NEW') |
| 1350 | self.assertEqual(A.reported, 1) |
| 1351 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1352 | 'SUCCESS') |
| 1353 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1354 | 'SUCCESS') |
| 1355 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1356 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1357 | |
| 1358 | def test_check_queue_failure(self): |
| 1359 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1360 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1361 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1362 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1363 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1364 | |
| 1365 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1366 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1367 | self.assertEqual(A.data['status'], 'NEW') |
| 1368 | self.assertEqual(A.reported, 1) |
| 1369 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1370 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1371 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1372 | 'SUCCESS') |
| 1373 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1374 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1375 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1376 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1377 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1378 | # This particular test does a large amount of merges and needs a little |
| 1379 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1380 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1381 | "test that dependent changes behind dequeued changes work" |
| 1382 | # This complicated test is a reproduction of a real life bug |
| 1383 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1384 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1385 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1386 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1387 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1388 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1389 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1390 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1391 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1392 | D.setDependsOn(C, 1) |
| 1393 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1394 | A.addApproval('code-review', 2) |
| 1395 | B.addApproval('code-review', 2) |
| 1396 | C.addApproval('code-review', 2) |
| 1397 | D.addApproval('code-review', 2) |
| 1398 | E.addApproval('code-review', 2) |
| 1399 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1400 | |
| 1401 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1402 | |
| 1403 | # Change object re-use in the gerrit trigger is hidden if |
| 1404 | # changes are added in quick succession; waiting makes it more |
| 1405 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1406 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1407 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1408 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1409 | self.waitUntilSettled() |
| 1410 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1411 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1412 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1413 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1414 | self.waitUntilSettled() |
| 1415 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1416 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1417 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1418 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1419 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1420 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1421 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1422 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1423 | self.waitUntilSettled() |
| 1424 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1425 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1426 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1427 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1428 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1429 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1430 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1431 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1432 | self.waitUntilSettled() |
| 1433 | |
| 1434 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1435 | |
| 1436 | # Grab pointers to the jobs we want to release before |
| 1437 | # releasing any, because list indexes may change as |
| 1438 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1439 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1440 | a.release() |
| 1441 | b.release() |
| 1442 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1443 | self.waitUntilSettled() |
| 1444 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1445 | self.executor_server.hold_jobs_in_build = False |
| 1446 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1447 | self.waitUntilSettled() |
| 1448 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1449 | self.assertEqual(A.data['status'], 'NEW') |
| 1450 | self.assertEqual(B.data['status'], 'MERGED') |
| 1451 | self.assertEqual(C.data['status'], 'MERGED') |
| 1452 | self.assertEqual(D.data['status'], 'MERGED') |
| 1453 | self.assertEqual(E.data['status'], 'MERGED') |
| 1454 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1455 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1456 | self.assertEqual(A.reported, 2) |
| 1457 | self.assertEqual(B.reported, 2) |
| 1458 | self.assertEqual(C.reported, 2) |
| 1459 | self.assertEqual(D.reported, 2) |
| 1460 | self.assertEqual(E.reported, 2) |
| 1461 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1462 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1463 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1464 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1465 | |
| 1466 | def test_merger_repack(self): |
| 1467 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1468 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1469 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1470 | A.addApproval('code-review', 2) |
| 1471 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1472 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1473 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1474 | 'SUCCESS') |
| 1475 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1476 | 'SUCCESS') |
| 1477 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1478 | 'SUCCESS') |
| 1479 | self.assertEqual(A.data['status'], 'MERGED') |
| 1480 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1481 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1482 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1483 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1484 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1485 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1486 | if os.path.exists(path): |
| 1487 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1488 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1489 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1490 | if os.path.exists(path): |
| 1491 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1492 | |
| 1493 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1494 | A.addApproval('code-review', 2) |
| 1495 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1496 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1497 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1498 | 'SUCCESS') |
| 1499 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1500 | 'SUCCESS') |
| 1501 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1502 | 'SUCCESS') |
| 1503 | self.assertEqual(A.data['status'], 'MERGED') |
| 1504 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1505 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1506 | def test_merger_repack_large_change(self): |
| 1507 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1508 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1509 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1510 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1511 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1512 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1513 | self.executor_server.merger._addProject('review.example.com', |
| 1514 | 'org/project', url) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1515 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1516 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1517 | # TODOv3(jeblair): add hostname to upstream root |
| 1518 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1519 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1520 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1521 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1522 | if os.path.exists(path): |
| 1523 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1524 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1525 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1526 | if os.path.exists(path): |
| 1527 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1528 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1529 | A.addApproval('code-review', 2) |
| 1530 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1531 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1532 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1533 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1534 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1535 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1536 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1537 | 'SUCCESS') |
| 1538 | self.assertEqual(A.data['status'], 'MERGED') |
| 1539 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1540 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1541 | def test_new_patchset_dequeues_old(self): |
| 1542 | "Test that a new patchset causes the old to be dequeued" |
| 1543 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1544 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1545 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1546 | M.setMerged() |
| 1547 | |
| 1548 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1549 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1550 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1551 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1552 | A.addApproval('code-review', 2) |
| 1553 | B.addApproval('code-review', 2) |
| 1554 | C.addApproval('code-review', 2) |
| 1555 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1556 | |
| 1557 | C.setDependsOn(B, 1) |
| 1558 | B.setDependsOn(A, 1) |
| 1559 | A.setDependsOn(M, 1) |
| 1560 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1561 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1562 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1563 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1564 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1565 | self.waitUntilSettled() |
| 1566 | |
| 1567 | B.addPatchset() |
| 1568 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1569 | self.waitUntilSettled() |
| 1570 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1571 | self.executor_server.hold_jobs_in_build = False |
| 1572 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1573 | self.waitUntilSettled() |
| 1574 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1575 | self.assertEqual(A.data['status'], 'MERGED') |
| 1576 | self.assertEqual(A.reported, 2) |
| 1577 | self.assertEqual(B.data['status'], 'NEW') |
| 1578 | self.assertEqual(B.reported, 2) |
| 1579 | self.assertEqual(C.data['status'], 'NEW') |
| 1580 | self.assertEqual(C.reported, 2) |
| 1581 | self.assertEqual(D.data['status'], 'MERGED') |
| 1582 | self.assertEqual(D.reported, 2) |
| 1583 | 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] | 1584 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1585 | def test_new_patchset_check(self): |
| 1586 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1587 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1588 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1589 | |
| 1590 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1591 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1592 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1593 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1594 | |
| 1595 | # Add two git-dependent changes |
| 1596 | B.setDependsOn(A, 1) |
| 1597 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1598 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1599 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1600 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1601 | |
| 1602 | # A live item, and a non-live/live pair |
| 1603 | items = check_pipeline.getAllItems() |
| 1604 | self.assertEqual(len(items), 3) |
| 1605 | |
| 1606 | self.assertEqual(items[0].change.number, '1') |
| 1607 | self.assertEqual(items[0].change.patchset, '1') |
| 1608 | self.assertFalse(items[0].live) |
| 1609 | |
| 1610 | self.assertEqual(items[1].change.number, '2') |
| 1611 | self.assertEqual(items[1].change.patchset, '1') |
| 1612 | self.assertTrue(items[1].live) |
| 1613 | |
| 1614 | self.assertEqual(items[2].change.number, '1') |
| 1615 | self.assertEqual(items[2].change.patchset, '1') |
| 1616 | self.assertTrue(items[2].live) |
| 1617 | |
| 1618 | # Add a new patchset to A |
| 1619 | A.addPatchset() |
| 1620 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1621 | self.waitUntilSettled() |
| 1622 | |
| 1623 | # The live copy of A,1 should be gone, but the non-live and B |
| 1624 | # should continue, and we should have a new A,2 |
| 1625 | items = check_pipeline.getAllItems() |
| 1626 | self.assertEqual(len(items), 3) |
| 1627 | |
| 1628 | self.assertEqual(items[0].change.number, '1') |
| 1629 | self.assertEqual(items[0].change.patchset, '1') |
| 1630 | self.assertFalse(items[0].live) |
| 1631 | |
| 1632 | self.assertEqual(items[1].change.number, '2') |
| 1633 | self.assertEqual(items[1].change.patchset, '1') |
| 1634 | self.assertTrue(items[1].live) |
| 1635 | |
| 1636 | self.assertEqual(items[2].change.number, '1') |
| 1637 | self.assertEqual(items[2].change.patchset, '2') |
| 1638 | self.assertTrue(items[2].live) |
| 1639 | |
| 1640 | # Add a new patchset to B |
| 1641 | B.addPatchset() |
| 1642 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1643 | self.waitUntilSettled() |
| 1644 | |
| 1645 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1646 | # but we should have a new B,2 (still based on A,1) |
| 1647 | items = check_pipeline.getAllItems() |
| 1648 | self.assertEqual(len(items), 3) |
| 1649 | |
| 1650 | self.assertEqual(items[0].change.number, '1') |
| 1651 | self.assertEqual(items[0].change.patchset, '2') |
| 1652 | self.assertTrue(items[0].live) |
| 1653 | |
| 1654 | self.assertEqual(items[1].change.number, '1') |
| 1655 | self.assertEqual(items[1].change.patchset, '1') |
| 1656 | self.assertFalse(items[1].live) |
| 1657 | |
| 1658 | self.assertEqual(items[2].change.number, '2') |
| 1659 | self.assertEqual(items[2].change.patchset, '2') |
| 1660 | self.assertTrue(items[2].live) |
| 1661 | |
| 1662 | self.builds[0].release() |
| 1663 | self.waitUntilSettled() |
| 1664 | self.builds[0].release() |
| 1665 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1666 | self.executor_server.hold_jobs_in_build = False |
| 1667 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1668 | self.waitUntilSettled() |
| 1669 | |
| 1670 | self.assertEqual(A.reported, 1) |
| 1671 | self.assertEqual(B.reported, 1) |
| 1672 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1673 | self.assertEqual(self.history[0].changes, '1,1') |
| 1674 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1675 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1676 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1677 | self.assertEqual(self.history[2].changes, '1,2') |
| 1678 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1679 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1680 | |
| 1681 | def test_abandoned_gate(self): |
| 1682 | "Test that an abandoned change is dequeued from gate" |
| 1683 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1684 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1685 | |
| 1686 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1687 | A.addApproval('code-review', 2) |
| 1688 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1689 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1690 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1691 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1692 | |
| 1693 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1694 | self.waitUntilSettled() |
| 1695 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1696 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1697 | self.waitUntilSettled() |
| 1698 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1699 | self.assertBuilds([]) |
| 1700 | self.assertHistory([ |
| 1701 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1702 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1703 | self.assertEqual(A.reported, 1, |
| 1704 | "Abandoned gate change should report only start") |
| 1705 | |
| 1706 | def test_abandoned_check(self): |
| 1707 | "Test that an abandoned change is dequeued from check" |
| 1708 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1709 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1710 | |
| 1711 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1712 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1713 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1714 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1715 | |
| 1716 | # Add two git-dependent changes |
| 1717 | B.setDependsOn(A, 1) |
| 1718 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1719 | self.waitUntilSettled() |
| 1720 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1721 | self.waitUntilSettled() |
| 1722 | # A live item, and a non-live/live pair |
| 1723 | items = check_pipeline.getAllItems() |
| 1724 | self.assertEqual(len(items), 3) |
| 1725 | |
| 1726 | self.assertEqual(items[0].change.number, '1') |
| 1727 | self.assertFalse(items[0].live) |
| 1728 | |
| 1729 | self.assertEqual(items[1].change.number, '2') |
| 1730 | self.assertTrue(items[1].live) |
| 1731 | |
| 1732 | self.assertEqual(items[2].change.number, '1') |
| 1733 | self.assertTrue(items[2].live) |
| 1734 | |
| 1735 | # Abandon A |
| 1736 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1737 | self.waitUntilSettled() |
| 1738 | |
| 1739 | # The live copy of A should be gone, but the non-live and B |
| 1740 | # should continue |
| 1741 | items = check_pipeline.getAllItems() |
| 1742 | self.assertEqual(len(items), 2) |
| 1743 | |
| 1744 | self.assertEqual(items[0].change.number, '1') |
| 1745 | self.assertFalse(items[0].live) |
| 1746 | |
| 1747 | self.assertEqual(items[1].change.number, '2') |
| 1748 | self.assertTrue(items[1].live) |
| 1749 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1750 | self.executor_server.hold_jobs_in_build = False |
| 1751 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1752 | self.waitUntilSettled() |
| 1753 | |
| 1754 | self.assertEqual(len(self.history), 4) |
| 1755 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1756 | 'Build should have been aborted') |
| 1757 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1758 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1759 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1760 | def test_abandoned_not_timer(self): |
| 1761 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1762 | # This test can not use simple_layout because it must start |
| 1763 | # with a configuration which does not include a |
| 1764 | # timer-triggered job so that we have an opportunity to set |
| 1765 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1766 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1767 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1768 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1769 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1770 | # The pipeline triggers every second, so we should have seen |
| 1771 | # several by now. |
| 1772 | time.sleep(5) |
| 1773 | self.waitUntilSettled() |
| 1774 | # Stop queuing timer triggered jobs so that the assertions |
| 1775 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1776 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1777 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1778 | self.sched.reconfigure(self.config) |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1779 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1780 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1781 | |
| 1782 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1783 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1784 | self.waitUntilSettled() |
| 1785 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1786 | |
| 1787 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1788 | self.waitUntilSettled() |
| 1789 | |
| 1790 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1791 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1792 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1793 | self.waitUntilSettled() |
| 1794 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1795 | def test_zuul_url_return(self): |
| 1796 | "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] | 1797 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1798 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1799 | |
| 1800 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1801 | A.addApproval('code-review', 2) |
| 1802 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1803 | self.waitUntilSettled() |
| 1804 | |
| 1805 | self.assertEqual(len(self.builds), 1) |
| 1806 | for build in self.builds: |
| 1807 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1808 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1809 | self.executor_server.hold_jobs_in_build = False |
| 1810 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1811 | self.waitUntilSettled() |
| 1812 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1813 | def test_new_patchset_dequeues_old_on_head(self): |
| 1814 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1815 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1816 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1817 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1818 | M.setMerged() |
| 1819 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1820 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1821 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1822 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1823 | A.addApproval('code-review', 2) |
| 1824 | B.addApproval('code-review', 2) |
| 1825 | C.addApproval('code-review', 2) |
| 1826 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1827 | |
| 1828 | C.setDependsOn(B, 1) |
| 1829 | B.setDependsOn(A, 1) |
| 1830 | A.setDependsOn(M, 1) |
| 1831 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1832 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1833 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1834 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1835 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1836 | self.waitUntilSettled() |
| 1837 | |
| 1838 | A.addPatchset() |
| 1839 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1840 | self.waitUntilSettled() |
| 1841 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1842 | self.executor_server.hold_jobs_in_build = False |
| 1843 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1844 | self.waitUntilSettled() |
| 1845 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1846 | self.assertEqual(A.data['status'], 'NEW') |
| 1847 | self.assertEqual(A.reported, 2) |
| 1848 | self.assertEqual(B.data['status'], 'NEW') |
| 1849 | self.assertEqual(B.reported, 2) |
| 1850 | self.assertEqual(C.data['status'], 'NEW') |
| 1851 | self.assertEqual(C.reported, 2) |
| 1852 | self.assertEqual(D.data['status'], 'MERGED') |
| 1853 | self.assertEqual(D.reported, 2) |
| 1854 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1855 | |
| 1856 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1857 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1858 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1859 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1860 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1861 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1862 | A.addApproval('code-review', 2) |
| 1863 | B.addApproval('code-review', 2) |
| 1864 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1865 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1866 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1867 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1868 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1869 | self.waitUntilSettled() |
| 1870 | |
| 1871 | B.addPatchset() |
| 1872 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1873 | self.waitUntilSettled() |
| 1874 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1875 | self.executor_server.hold_jobs_in_build = False |
| 1876 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1877 | self.waitUntilSettled() |
| 1878 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1879 | self.assertEqual(A.data['status'], 'MERGED') |
| 1880 | self.assertEqual(A.reported, 2) |
| 1881 | self.assertEqual(B.data['status'], 'NEW') |
| 1882 | self.assertEqual(B.reported, 2) |
| 1883 | self.assertEqual(C.data['status'], 'MERGED') |
| 1884 | self.assertEqual(C.reported, 2) |
| 1885 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1886 | |
| 1887 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1888 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1889 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1890 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1891 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1892 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1893 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1894 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1895 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1896 | self.waitUntilSettled() |
| 1897 | |
| 1898 | B.addPatchset() |
| 1899 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1900 | self.waitUntilSettled() |
| 1901 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1902 | self.executor_server.hold_jobs_in_build = False |
| 1903 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1904 | self.waitUntilSettled() |
| 1905 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1906 | self.assertEqual(A.data['status'], 'NEW') |
| 1907 | self.assertEqual(A.reported, 1) |
| 1908 | self.assertEqual(B.data['status'], 'NEW') |
| 1909 | self.assertEqual(B.reported, 1) |
| 1910 | self.assertEqual(C.data['status'], 'NEW') |
| 1911 | self.assertEqual(C.reported, 1) |
| 1912 | self.assertEqual(len(self.history), 10) |
| 1913 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1914 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1915 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1916 | def test_noop_job(self): |
| 1917 | "Test that the internal noop job works" |
| 1918 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1919 | A.addApproval('code-review', 2) |
| 1920 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1921 | self.waitUntilSettled() |
| 1922 | |
| 1923 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1924 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1925 | self.assertEqual(len(self.history), 0) |
| 1926 | self.assertEqual(A.data['status'], 'MERGED') |
| 1927 | self.assertEqual(A.reported, 2) |
| 1928 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 1929 | @simple_layout('layouts/no-jobs-project.yaml') |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 1930 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1931 | def test_no_job_project(self): |
| 1932 | "Test that reports with no jobs don't get sent" |
| 1933 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1934 | 'master', 'A') |
| 1935 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1936 | self.waitUntilSettled() |
| 1937 | |
| 1938 | # Change wasn't reported to |
| 1939 | self.assertEqual(A.reported, False) |
| 1940 | |
| 1941 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1942 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1943 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1944 | items = check_pipeline.getAllItems() |
| 1945 | self.assertEqual(len(items), 0) |
| 1946 | |
| 1947 | self.assertEqual(len(self.history), 0) |
| 1948 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1949 | def test_zuul_refs(self): |
| 1950 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1951 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1952 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 1953 | M1.setMerged() |
| 1954 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 1955 | M2.setMerged() |
| 1956 | |
| 1957 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1958 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1959 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1960 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1961 | A.addApproval('code-review', 2) |
| 1962 | B.addApproval('code-review', 2) |
| 1963 | C.addApproval('code-review', 2) |
| 1964 | D.addApproval('code-review', 2) |
| 1965 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1966 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1967 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1968 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1969 | |
| 1970 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1971 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1972 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1973 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 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() |
| 1979 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1980 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1981 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1982 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1983 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 1984 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1985 | a_build = x |
| 1986 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1987 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1988 | b_build = x |
| 1989 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1990 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1991 | c_build = x |
| 1992 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1993 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 1994 | d_build = x |
| 1995 | if a_build and b_build and c_build and d_build: |
| 1996 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1997 | |
| 1998 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1999 | self.assertIsNotNone(a_zref) |
| 2000 | self.assertIsNotNone(b_zref) |
| 2001 | self.assertIsNotNone(c_zref) |
| 2002 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2003 | |
| 2004 | # And they should all be different |
| 2005 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2006 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2007 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2008 | # should have a, not b, and should not be in project2 |
| 2009 | self.assertTrue(a_build.hasChanges(A)) |
| 2010 | self.assertFalse(a_build.hasChanges(B, M2)) |
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 and b, and should not be in project2 |
| 2013 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2014 | self.assertFalse(b_build.hasChanges(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 in 1, c in 2 |
| 2017 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2018 | self.assertFalse(c_build.hasChanges(D)) |
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 and d in 2 |
| 2021 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2022 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2023 | self.executor_server.hold_jobs_in_build = False |
| 2024 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2025 | self.waitUntilSettled() |
| 2026 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2027 | self.assertEqual(A.data['status'], 'MERGED') |
| 2028 | self.assertEqual(A.reported, 2) |
| 2029 | self.assertEqual(B.data['status'], 'MERGED') |
| 2030 | self.assertEqual(B.reported, 2) |
| 2031 | self.assertEqual(C.data['status'], 'MERGED') |
| 2032 | self.assertEqual(C.reported, 2) |
| 2033 | self.assertEqual(D.data['status'], 'MERGED') |
| 2034 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2035 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2036 | def test_rerun_on_error(self): |
| 2037 | "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] | 2038 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2039 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2040 | A.addApproval('code-review', 2) |
| 2041 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2042 | self.waitUntilSettled() |
| 2043 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2044 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2045 | self.executor_server.hold_jobs_in_build = False |
| 2046 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2047 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2048 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2049 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2050 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2051 | def test_statsd(self): |
| 2052 | "Test each of the statsd methods used in the scheduler" |
| 2053 | import extras |
| 2054 | statsd = extras.try_import('statsd.statsd') |
| 2055 | statsd.incr('test-incr') |
| 2056 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2057 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2058 | self.assertReportedStat('test-incr', '1|c') |
| 2059 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2060 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2061 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 2062 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2063 | def test_stuck_job_cleanup(self): |
| 2064 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2065 | |
| 2066 | # 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] | 2067 | self.gearman_server.hold_jobs_in_queue = True |
| 2068 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2069 | A.addApproval('code-review', 2) |
| 2070 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2071 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2072 | # 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] | 2073 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2074 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2075 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2076 | self.sched.reconfigure(self.config) |
| 2077 | self.waitUntilSettled() |
| 2078 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2079 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2080 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2081 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2082 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2083 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2084 | |
| 2085 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2086 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2087 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2088 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2089 | def test_file_head(self): |
| 2090 | # This is a regression test for an observed bug. A change |
| 2091 | # with a file named "HEAD" in the root directory of the repo |
| 2092 | # was processed by a merger. It then was unable to reset the |
| 2093 | # repo because of: |
| 2094 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2095 | # with exit code 128 |
| 2096 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2097 | # and filename |
| 2098 | # Use '--' to separate filenames from revisions' |
| 2099 | |
| 2100 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2101 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2102 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2103 | |
| 2104 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2105 | self.waitUntilSettled() |
| 2106 | |
| 2107 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2108 | self.waitUntilSettled() |
| 2109 | |
| 2110 | self.assertIn('Build succeeded', A.messages[0]) |
| 2111 | self.assertIn('Build succeeded', B.messages[0]) |
| 2112 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2113 | def test_file_jobs(self): |
| 2114 | "Test that file jobs run only when appropriate" |
| 2115 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2116 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2117 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2118 | A.addApproval('code-review', 2) |
| 2119 | B.addApproval('code-review', 2) |
| 2120 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2121 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2122 | self.waitUntilSettled() |
| 2123 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2124 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2125 | if x.name == 'project-testfile'] |
| 2126 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2127 | self.assertEqual(len(testfile_jobs), 1) |
| 2128 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2129 | self.assertEqual(A.data['status'], 'MERGED') |
| 2130 | self.assertEqual(A.reported, 2) |
| 2131 | self.assertEqual(B.data['status'], 'MERGED') |
| 2132 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2133 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2134 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2135 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2136 | if should_skip: |
| 2137 | files = {'ignoreme': 'ignored\n'} |
| 2138 | else: |
| 2139 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2140 | |
| 2141 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2142 | 'master', |
| 2143 | 'test irrelevant-files', |
| 2144 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2145 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2146 | self.waitUntilSettled() |
| 2147 | |
| 2148 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2149 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2150 | |
| 2151 | if should_skip: |
| 2152 | self.assertEqual([], tested_change_ids) |
| 2153 | else: |
| 2154 | self.assertIn(change.data['number'], tested_change_ids) |
| 2155 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2156 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2157 | def test_irrelevant_files_match_skips_job(self): |
| 2158 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2159 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2160 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2161 | def test_irrelevant_files_no_match_runs_job(self): |
| 2162 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2163 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2164 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2165 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2166 | files = {'ignoreme': 'ignored\n'} |
| 2167 | |
| 2168 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2169 | 'master', |
| 2170 | 'test irrelevant-files', |
| 2171 | files=files) |
| 2172 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2173 | self.waitUntilSettled() |
| 2174 | |
| 2175 | run_jobs = set([build.name for build in self.history]) |
| 2176 | |
| 2177 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2178 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2179 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2180 | def test_queue_names(self): |
| 2181 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2182 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2183 | (trusted, project1) = tenant.getProject('org/project1') |
| 2184 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2185 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2186 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2187 | self.assertEqual(q1.name, 'integrated') |
| 2188 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2189 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 2190 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2191 | def test_queue_precedence(self): |
| 2192 | "Test that queue precedence works" |
| 2193 | |
| 2194 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2195 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2196 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2197 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2198 | A.addApproval('code-review', 2) |
| 2199 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2200 | |
| 2201 | self.waitUntilSettled() |
| 2202 | self.gearman_server.hold_jobs_in_queue = False |
| 2203 | self.gearman_server.release() |
| 2204 | self.waitUntilSettled() |
| 2205 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2206 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2207 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2208 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2209 | self.waitUntilSettled() |
| 2210 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2211 | self.log.debug(self.history) |
| 2212 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2213 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2214 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2215 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2216 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2217 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2218 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2219 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2220 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2221 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2222 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2223 | A.addApproval('code-review', 2) |
| 2224 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2225 | self.waitUntilSettled() |
| 2226 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2227 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2228 | self.waitUntilSettled() |
| 2229 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2230 | port = self.webapp.server.socket.getsockname()[1] |
| 2231 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2232 | req = urllib.request.Request( |
| 2233 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2234 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2235 | headers = f.info() |
| 2236 | self.assertIn('Content-Length', headers) |
| 2237 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2238 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2239 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2240 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2241 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2242 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2243 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2244 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2245 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2246 | self.executor_server.hold_jobs_in_build = False |
| 2247 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2248 | self.waitUntilSettled() |
| 2249 | |
| 2250 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2251 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2252 | for p in data['pipelines']: |
| 2253 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2254 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2255 | self.assertEqual(q['window'], 20) |
| 2256 | else: |
| 2257 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2258 | for head in q['heads']: |
| 2259 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2260 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2261 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2262 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2263 | status_jobs.append(job) |
| 2264 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2265 | self.assertEqual('https://server/job/project-merge/0/', |
| 2266 | status_jobs[0]['url']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2267 | self.assertEqual('https://server/job/project-merge/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2268 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2269 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2270 | self.assertEqual('https://server/job/project-test1/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2271 | status_jobs[1]['url']) |
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]['report_url']) |
| 2274 | |
| 2275 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2276 | self.assertEqual('https://server/job/project-test2/0/', |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2277 | status_jobs[2]['url']) |
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]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2280 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2281 | def test_live_reconfiguration(self): |
| 2282 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2283 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2284 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2285 | A.addApproval('code-review', 2) |
| 2286 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2287 | self.waitUntilSettled() |
| 2288 | |
| 2289 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2290 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2291 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2292 | self.executor_server.hold_jobs_in_build = False |
| 2293 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2294 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2295 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2296 | 'SUCCESS') |
| 2297 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2298 | 'SUCCESS') |
| 2299 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2300 | 'SUCCESS') |
| 2301 | self.assertEqual(A.data['status'], 'MERGED') |
| 2302 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2303 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2304 | def test_live_reconfiguration_merge_conflict(self): |
| 2305 | # A real-world bug: a change in a gate queue has a merge |
| 2306 | # conflict and a job is added to its project while it's |
| 2307 | # sitting in the queue. The job gets added to the change and |
| 2308 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2309 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2310 | |
| 2311 | # This change is fine. It's here to stop the queue long |
| 2312 | # enough for the next change to be subject to the |
| 2313 | # reconfiguration, as well as to provide a conflict for the |
| 2314 | # next change. This change will succeed and merge. |
| 2315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2316 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2317 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2318 | |
| 2319 | # This change will be in merge conflict. During the |
| 2320 | # reconfiguration, we will add a job. We want to make sure |
| 2321 | # that doesn't cause it to get stuck. |
| 2322 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2323 | B.addPatchset({'conflict': 'B'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2324 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2325 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2326 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2327 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2328 | |
| 2329 | self.waitUntilSettled() |
| 2330 | |
| 2331 | # No jobs have run yet |
| 2332 | self.assertEqual(A.data['status'], 'NEW') |
| 2333 | self.assertEqual(A.reported, 1) |
| 2334 | self.assertEqual(B.data['status'], 'NEW') |
| 2335 | self.assertEqual(B.reported, 1) |
| 2336 | self.assertEqual(len(self.history), 0) |
| 2337 | |
| 2338 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2339 | self.commitConfigUpdate('common-config', |
| 2340 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2341 | self.sched.reconfigure(self.config) |
| 2342 | self.waitUntilSettled() |
| 2343 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2344 | self.executor_server.hold_jobs_in_build = False |
| 2345 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2346 | self.waitUntilSettled() |
| 2347 | |
| 2348 | self.assertEqual(A.data['status'], 'MERGED') |
| 2349 | self.assertEqual(A.reported, 2) |
| 2350 | self.assertEqual(B.data['status'], 'NEW') |
| 2351 | self.assertEqual(B.reported, 2) |
| 2352 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2353 | 'SUCCESS') |
| 2354 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2355 | 'SUCCESS') |
| 2356 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2357 | 'SUCCESS') |
| 2358 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2359 | 'SUCCESS') |
| 2360 | self.assertEqual(len(self.history), 4) |
| 2361 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2362 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2363 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2364 | # that tests a job added to a job tree with a failed root does |
| 2365 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2366 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2367 | |
| 2368 | # This change is fine. It's here to stop the queue long |
| 2369 | # enough for the next change to be subject to the |
| 2370 | # reconfiguration. This change will succeed and merge. |
| 2371 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2372 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2373 | A.addApproval('code-review', 2) |
| 2374 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2375 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2376 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2377 | self.waitUntilSettled() |
| 2378 | |
| 2379 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2380 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2381 | B.addApproval('code-review', 2) |
| 2382 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2383 | self.waitUntilSettled() |
| 2384 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2385 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2386 | self.waitUntilSettled() |
| 2387 | |
| 2388 | # Both -merge jobs have run, but no others. |
| 2389 | self.assertEqual(A.data['status'], 'NEW') |
| 2390 | self.assertEqual(A.reported, 1) |
| 2391 | self.assertEqual(B.data['status'], 'NEW') |
| 2392 | self.assertEqual(B.reported, 1) |
| 2393 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2394 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2395 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2396 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2397 | self.assertEqual(len(self.history), 2) |
| 2398 | |
| 2399 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2400 | self.commitConfigUpdate('common-config', |
| 2401 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2402 | self.sched.reconfigure(self.config) |
| 2403 | self.waitUntilSettled() |
| 2404 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2405 | self.executor_server.hold_jobs_in_build = False |
| 2406 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2407 | self.waitUntilSettled() |
| 2408 | |
| 2409 | self.assertEqual(A.data['status'], 'MERGED') |
| 2410 | self.assertEqual(A.reported, 2) |
| 2411 | self.assertEqual(B.data['status'], 'NEW') |
| 2412 | self.assertEqual(B.reported, 2) |
| 2413 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2414 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2415 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2416 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2417 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2418 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2419 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2420 | self.assertEqual(len(self.history), 5) |
| 2421 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2422 | def test_live_reconfiguration_failed_job(self): |
| 2423 | # Test that a change with a removed failing job does not |
| 2424 | # disrupt reconfiguration. If a change has a failed job and |
| 2425 | # that job is removed during a reconfiguration, we observed a |
| 2426 | # bug where the code to re-set build statuses would run on |
| 2427 | # that build and raise an exception because the job no longer |
| 2428 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2429 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2430 | |
| 2431 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2432 | |
| 2433 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2434 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2435 | |
| 2436 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2437 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2438 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2439 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2440 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2441 | self.waitUntilSettled() |
| 2442 | |
| 2443 | self.assertEqual(A.data['status'], 'NEW') |
| 2444 | self.assertEqual(A.reported, 0) |
| 2445 | |
| 2446 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2447 | 'SUCCESS') |
| 2448 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2449 | 'FAILURE') |
| 2450 | self.assertEqual(len(self.history), 2) |
| 2451 | |
| 2452 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2453 | self.commitConfigUpdate('common-config', |
| 2454 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2455 | self.sched.reconfigure(self.config) |
| 2456 | self.waitUntilSettled() |
| 2457 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2458 | self.executor_server.hold_jobs_in_build = False |
| 2459 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2460 | self.waitUntilSettled() |
| 2461 | |
| 2462 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2463 | 'SUCCESS') |
| 2464 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2465 | 'SUCCESS') |
| 2466 | self.assertEqual(len(self.history), 4) |
| 2467 | |
| 2468 | self.assertEqual(A.data['status'], 'NEW') |
| 2469 | self.assertEqual(A.reported, 1) |
| 2470 | self.assertIn('Build succeeded', A.messages[0]) |
| 2471 | # Ensure the removed job was not included in the report. |
| 2472 | self.assertNotIn('project-test1', A.messages[0]) |
| 2473 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2474 | def test_live_reconfiguration_shared_queue(self): |
| 2475 | # Test that a change with a failing job which was removed from |
| 2476 | # this project but otherwise still exists in the system does |
| 2477 | # not disrupt reconfiguration. |
| 2478 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2479 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2480 | |
| 2481 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2482 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2483 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2484 | |
| 2485 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2486 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2487 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2488 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2489 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2490 | self.waitUntilSettled() |
| 2491 | |
| 2492 | self.assertEqual(A.data['status'], 'NEW') |
| 2493 | self.assertEqual(A.reported, 0) |
| 2494 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2495 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2496 | 'SUCCESS') |
| 2497 | self.assertEqual(self.getJobFromHistory( |
| 2498 | 'project1-project2-integration').result, 'FAILURE') |
| 2499 | self.assertEqual(len(self.history), 2) |
| 2500 | |
| 2501 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2502 | self.commitConfigUpdate( |
| 2503 | 'common-config', |
| 2504 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2505 | self.sched.reconfigure(self.config) |
| 2506 | self.waitUntilSettled() |
| 2507 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2508 | self.executor_server.hold_jobs_in_build = False |
| 2509 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2510 | self.waitUntilSettled() |
| 2511 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2512 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2513 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2514 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2515 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2516 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2517 | 'SUCCESS') |
| 2518 | self.assertEqual(self.getJobFromHistory( |
| 2519 | 'project1-project2-integration').result, 'FAILURE') |
| 2520 | self.assertEqual(len(self.history), 4) |
| 2521 | |
| 2522 | self.assertEqual(A.data['status'], 'NEW') |
| 2523 | self.assertEqual(A.reported, 1) |
| 2524 | self.assertIn('Build succeeded', A.messages[0]) |
| 2525 | # Ensure the removed job was not included in the report. |
| 2526 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2527 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2528 | def test_double_live_reconfiguration_shared_queue(self): |
| 2529 | # This was a real-world regression. A change is added to |
| 2530 | # gate; a reconfigure happens, a second change which depends |
| 2531 | # on the first is added, and a second reconfiguration happens. |
| 2532 | # Ensure that both changes merge. |
| 2533 | |
| 2534 | # A failure may indicate incorrect caching or cleaning up of |
| 2535 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2536 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2537 | |
| 2538 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2539 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2540 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2541 | A.addApproval('code-review', 2) |
| 2542 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2543 | |
| 2544 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2545 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2546 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2547 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2548 | self.waitUntilSettled() |
| 2549 | |
| 2550 | # Reconfigure (with only one change in the pipeline). |
| 2551 | self.sched.reconfigure(self.config) |
| 2552 | self.waitUntilSettled() |
| 2553 | |
| 2554 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2555 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2556 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2557 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2558 | self.waitUntilSettled() |
| 2559 | |
| 2560 | # Reconfigure (with both in the pipeline). |
| 2561 | self.sched.reconfigure(self.config) |
| 2562 | self.waitUntilSettled() |
| 2563 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2564 | self.executor_server.hold_jobs_in_build = False |
| 2565 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2566 | self.waitUntilSettled() |
| 2567 | |
| 2568 | self.assertEqual(len(self.history), 8) |
| 2569 | |
| 2570 | self.assertEqual(A.data['status'], 'MERGED') |
| 2571 | self.assertEqual(A.reported, 2) |
| 2572 | self.assertEqual(B.data['status'], 'MERGED') |
| 2573 | self.assertEqual(B.reported, 2) |
| 2574 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2575 | def test_live_reconfiguration_del_project(self): |
| 2576 | # Test project deletion from layout |
| 2577 | # while changes are enqueued |
| 2578 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2579 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2580 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2581 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2582 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2583 | |
| 2584 | # A Depends-On: B |
| 2585 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2586 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2587 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2588 | |
| 2589 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2590 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2591 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2592 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2593 | self.waitUntilSettled() |
| 2594 | self.assertEqual(len(self.builds), 5) |
| 2595 | |
| 2596 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2597 | self.commitConfigUpdate( |
| 2598 | 'common-config', |
| 2599 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2600 | self.sched.reconfigure(self.config) |
| 2601 | self.waitUntilSettled() |
| 2602 | |
| 2603 | # Builds for C aborted, builds for A succeed, |
| 2604 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2605 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2606 | self.assertEqual(job_c.changes, '3,1') |
| 2607 | self.assertEqual(job_c.result, 'ABORTED') |
| 2608 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2609 | self.executor_server.hold_jobs_in_build = False |
| 2610 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2611 | self.waitUntilSettled() |
| 2612 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2613 | self.assertEqual( |
| 2614 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2615 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2616 | |
| 2617 | self.assertEqual(A.data['status'], 'NEW') |
| 2618 | self.assertEqual(B.data['status'], 'NEW') |
| 2619 | self.assertEqual(C.data['status'], 'NEW') |
| 2620 | self.assertEqual(A.reported, 1) |
| 2621 | self.assertEqual(B.reported, 0) |
| 2622 | self.assertEqual(C.reported, 0) |
| 2623 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2624 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2625 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2626 | self.assertIn('Build succeeded', A.messages[0]) |
| 2627 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2628 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2629 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2630 | self.updateConfigLayout( |
| 2631 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2632 | self.sched.reconfigure(self.config) |
| 2633 | |
| 2634 | self.init_repo("org/new-project") |
| 2635 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2636 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2637 | A.addApproval('code-review', 2) |
| 2638 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2639 | self.waitUntilSettled() |
| 2640 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2641 | 'SUCCESS') |
| 2642 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2643 | 'SUCCESS') |
| 2644 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2645 | 'SUCCESS') |
| 2646 | self.assertEqual(A.data['status'], 'MERGED') |
| 2647 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2648 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2649 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2650 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2651 | self.init_repo("org/delete-project") |
| 2652 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2653 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2654 | A.addApproval('code-review', 2) |
| 2655 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2656 | self.waitUntilSettled() |
| 2657 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2658 | 'SUCCESS') |
| 2659 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2660 | 'SUCCESS') |
| 2661 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2662 | 'SUCCESS') |
| 2663 | self.assertEqual(A.data['status'], 'MERGED') |
| 2664 | self.assertEqual(A.reported, 2) |
| 2665 | |
| 2666 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2667 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2668 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2669 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2670 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2671 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2672 | |
| 2673 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2674 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2675 | B.addApproval('code-review', 2) |
| 2676 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2677 | self.waitUntilSettled() |
| 2678 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2679 | 'SUCCESS') |
| 2680 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2681 | 'SUCCESS') |
| 2682 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2683 | 'SUCCESS') |
| 2684 | self.assertEqual(B.data['status'], 'MERGED') |
| 2685 | self.assertEqual(B.reported, 2) |
| 2686 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2687 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2688 | def test_tags(self): |
| 2689 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2690 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2691 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2692 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2693 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2694 | self.waitUntilSettled() |
| 2695 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2696 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2697 | |
| 2698 | results = {self.getJobFromHistory('merge', |
| 2699 | project='org/project1').uuid: 'extratag merge', |
| 2700 | self.getJobFromHistory('merge', |
| 2701 | project='org/project2').uuid: 'merge'} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2702 | |
| 2703 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2704 | self.assertEqual(results.get(build.uuid, ''), |
| 2705 | build.parameters['vars']['zuul'].get('tags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2706 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2707 | def test_timer(self): |
| 2708 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2709 | # This test can not use simple_layout because it must start |
| 2710 | # with a configuration which does not include a |
| 2711 | # timer-triggered job so that we have an opportunity to set |
| 2712 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2713 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2714 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2715 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2716 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2717 | # The pipeline triggers every second, so we should have seen |
| 2718 | # several by now. |
| 2719 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2720 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2721 | |
| 2722 | self.assertEqual(len(self.builds), 2) |
| 2723 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2724 | port = self.webapp.server.socket.getsockname()[1] |
| 2725 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2726 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2727 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2728 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2729 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2730 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2731 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2732 | # Stop queuing timer triggered jobs so that the assertions |
| 2733 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2734 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2735 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2736 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2737 | self.waitUntilSettled() |
| 2738 | |
| 2739 | self.assertEqual(self.getJobFromHistory( |
| 2740 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2741 | self.assertEqual(self.getJobFromHistory( |
| 2742 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2743 | |
| 2744 | data = json.loads(data) |
| 2745 | status_jobs = set() |
| 2746 | for p in data['pipelines']: |
| 2747 | for q in p['change_queues']: |
| 2748 | for head in q['heads']: |
| 2749 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2750 | for job in change['jobs']: |
| 2751 | status_jobs.add(job['name']) |
| 2752 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 2753 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2754 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2755 | def test_idle(self): |
| 2756 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2757 | # This test can not use simple_layout because it must start |
| 2758 | # with a configuration which does not include a |
| 2759 | # timer-triggered job so that we have an opportunity to set |
| 2760 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2761 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2762 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2763 | for x in range(1, 3): |
| 2764 | # Test that timer triggers periodic jobs even across |
| 2765 | # layout config reloads. |
| 2766 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2767 | self.commitConfigUpdate('common-config', |
| 2768 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2769 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2770 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2771 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2772 | # The pipeline triggers every second, so we should have seen |
| 2773 | # several by now. |
| 2774 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2775 | |
| 2776 | # Stop queuing timer triggered jobs so that the assertions |
| 2777 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2778 | self.commitConfigUpdate('common-config', |
| 2779 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2780 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2781 | self.waitUntilSettled() |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2782 | self.assertEqual(len(self.builds), 2, |
| 2783 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2784 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2785 | self.waitUntilSettled() |
| 2786 | self.assertEqual(len(self.builds), 0) |
| 2787 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2788 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2789 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2790 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2791 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2792 | self.waitUntilSettled() |
| 2793 | |
| 2794 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2795 | self.waitUntilSettled() |
| 2796 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2797 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2798 | |
| 2799 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2800 | # work on the knowledge of what the first message should be as |
| 2801 | # it is only configured to go to SMTP. |
| 2802 | |
| 2803 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2804 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2805 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2806 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2807 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2808 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2809 | |
| 2810 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2811 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2812 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2813 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2814 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2815 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2816 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2817 | def test_timer_smtp(self): |
| 2818 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2819 | # This test can not use simple_layout because it must start |
| 2820 | # with a configuration which does not include a |
| 2821 | # timer-triggered job so that we have an opportunity to set |
| 2822 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2823 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2824 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2825 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2826 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2827 | # The pipeline triggers every second, so we should have seen |
| 2828 | # several by now. |
| 2829 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2830 | self.waitUntilSettled() |
| 2831 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2832 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2833 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2834 | self.waitUntilSettled() |
| 2835 | self.assertEqual(len(self.history), 2) |
| 2836 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2837 | self.assertEqual(self.getJobFromHistory( |
| 2838 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2839 | self.assertEqual(self.getJobFromHistory( |
| 2840 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2841 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2842 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2843 | |
| 2844 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2845 | # work on the knowledge of what the first message should be as |
| 2846 | # it is only configured to go to SMTP. |
| 2847 | |
| 2848 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2849 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2850 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2851 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2852 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2853 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2854 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2855 | # Stop queuing timer triggered jobs and let any that may have |
| 2856 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2857 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2858 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2859 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2860 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2861 | self.waitUntilSettled() |
| 2862 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 2863 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 2864 | def test_timer_sshkey(self): |
| 2865 | "Test that a periodic job can setup SSH key authentication" |
| 2866 | self.worker.hold_jobs_in_build = True |
| 2867 | self.config.set('zuul', 'layout_config', |
| 2868 | 'tests/fixtures/layout-timer.yaml') |
| 2869 | self.sched.reconfigure(self.config) |
| 2870 | self.registerJobs() |
| 2871 | |
| 2872 | # The pipeline triggers every second, so we should have seen |
| 2873 | # several by now. |
| 2874 | time.sleep(5) |
| 2875 | self.waitUntilSettled() |
| 2876 | |
| 2877 | self.assertEqual(len(self.builds), 2) |
| 2878 | |
| 2879 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 2880 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 2881 | with open(ssh_wrapper) as f: |
| 2882 | ssh_wrapper_content = f.read() |
| 2883 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 2884 | # In the unit tests Merger runs in the same process, |
| 2885 | # so we see its' environment variables |
| 2886 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 2887 | |
| 2888 | self.worker.release('.*') |
| 2889 | self.waitUntilSettled() |
| 2890 | self.assertEqual(len(self.history), 2) |
| 2891 | |
| 2892 | self.assertEqual(self.getJobFromHistory( |
| 2893 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2894 | self.assertEqual(self.getJobFromHistory( |
| 2895 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2896 | |
| 2897 | # Stop queuing timer triggered jobs and let any that may have |
| 2898 | # queued through so that end of test assertions pass. |
| 2899 | self.config.set('zuul', 'layout_config', |
| 2900 | 'tests/fixtures/layout-no-timer.yaml') |
| 2901 | self.sched.reconfigure(self.config) |
| 2902 | self.registerJobs() |
| 2903 | self.waitUntilSettled() |
| 2904 | self.worker.release('.*') |
| 2905 | self.waitUntilSettled() |
| 2906 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2907 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2908 | "Test that the RPC client can enqueue a change" |
| 2909 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2910 | A.addApproval('code-review', 2) |
| 2911 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2912 | |
| 2913 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2914 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2915 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2916 | r = client.enqueue(tenant='tenant-one', |
| 2917 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2918 | project='org/project', |
| 2919 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2920 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2921 | self.waitUntilSettled() |
| 2922 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2923 | 'SUCCESS') |
| 2924 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2925 | 'SUCCESS') |
| 2926 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2927 | 'SUCCESS') |
| 2928 | self.assertEqual(A.data['status'], 'MERGED') |
| 2929 | self.assertEqual(A.reported, 2) |
| 2930 | self.assertEqual(r, True) |
| 2931 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2932 | def test_client_enqueue_ref(self): |
| 2933 | "Test that the RPC client can enqueue a ref" |
| 2934 | |
| 2935 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2936 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2937 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2938 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2939 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 2940 | pipeline='post', |
| 2941 | project='org/project', |
| 2942 | trigger='gerrit', |
| 2943 | ref='master', |
| 2944 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 2945 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 2946 | self.waitUntilSettled() |
| 2947 | job_names = [x.name for x in self.history] |
| 2948 | self.assertEqual(len(self.history), 1) |
| 2949 | self.assertIn('project-post', job_names) |
| 2950 | self.assertEqual(r, True) |
| 2951 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2952 | def test_client_enqueue_negative(self): |
| 2953 | "Test that the RPC client returns errors" |
| 2954 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 2955 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 2956 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2957 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2958 | "Invalid tenant"): |
| 2959 | r = client.enqueue(tenant='tenant-foo', |
| 2960 | pipeline='gate', |
| 2961 | project='org/project', |
| 2962 | trigger='gerrit', |
| 2963 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2964 | self.assertEqual(r, False) |
| 2965 | |
| 2966 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2967 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2968 | r = client.enqueue(tenant='tenant-one', |
| 2969 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2970 | project='project-does-not-exist', |
| 2971 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2972 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2973 | self.assertEqual(r, False) |
| 2974 | |
| 2975 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2976 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2977 | r = client.enqueue(tenant='tenant-one', |
| 2978 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2979 | project='org/project', |
| 2980 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2981 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2982 | self.assertEqual(r, False) |
| 2983 | |
| 2984 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2985 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2986 | r = client.enqueue(tenant='tenant-one', |
| 2987 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2988 | project='org/project', |
| 2989 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2990 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2991 | self.assertEqual(r, False) |
| 2992 | |
| 2993 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 2994 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 2995 | r = client.enqueue(tenant='tenant-one', |
| 2996 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2997 | project='org/project', |
| 2998 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 2999 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3000 | self.assertEqual(r, False) |
| 3001 | |
| 3002 | self.waitUntilSettled() |
| 3003 | self.assertEqual(len(self.history), 0) |
| 3004 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3005 | |
| 3006 | def test_client_promote(self): |
| 3007 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3008 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3009 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3010 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3011 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3012 | A.addApproval('code-review', 2) |
| 3013 | B.addApproval('code-review', 2) |
| 3014 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3015 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3016 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3017 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3018 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3019 | |
| 3020 | self.waitUntilSettled() |
| 3021 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3022 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3023 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3024 | enqueue_times = {} |
| 3025 | for item in items: |
| 3026 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3027 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3028 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3029 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3030 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3031 | r = client.promote(tenant='tenant-one', |
| 3032 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3033 | change_ids=['2,1', '3,1']) |
| 3034 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3035 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3036 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3037 | for item in items: |
| 3038 | self.assertEqual( |
| 3039 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3040 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3041 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3042 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3043 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3044 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3045 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3046 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3047 | self.waitUntilSettled() |
| 3048 | |
| 3049 | self.assertEqual(len(self.builds), 6) |
| 3050 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3051 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3052 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3053 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3054 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3055 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3056 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3057 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3058 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3059 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3060 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3061 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3062 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3063 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3064 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3065 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3066 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3067 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3068 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3069 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3070 | self.waitUntilSettled() |
| 3071 | |
| 3072 | self.assertEqual(A.data['status'], 'MERGED') |
| 3073 | self.assertEqual(A.reported, 2) |
| 3074 | self.assertEqual(B.data['status'], 'MERGED') |
| 3075 | self.assertEqual(B.reported, 2) |
| 3076 | self.assertEqual(C.data['status'], 'MERGED') |
| 3077 | self.assertEqual(C.reported, 2) |
| 3078 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3079 | self.assertEqual(r, True) |
| 3080 | |
| 3081 | def test_client_promote_dependent(self): |
| 3082 | "Test that the RPC client can promote a dependent change" |
| 3083 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3084 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3085 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3086 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3087 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3088 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3089 | |
| 3090 | C.setDependsOn(B, 1) |
| 3091 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3092 | A.addApproval('code-review', 2) |
| 3093 | B.addApproval('code-review', 2) |
| 3094 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3095 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3096 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3097 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3098 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3099 | |
| 3100 | self.waitUntilSettled() |
| 3101 | |
| 3102 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3103 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3104 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3105 | r = client.promote(tenant='tenant-one', |
| 3106 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3107 | change_ids=['3,1']) |
| 3108 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3109 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3110 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3111 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3112 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3113 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3114 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3115 | self.waitUntilSettled() |
| 3116 | |
| 3117 | self.assertEqual(len(self.builds), 6) |
| 3118 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3119 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3120 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3121 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3122 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3123 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3124 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3125 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3126 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3127 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3128 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3129 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3130 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3131 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3132 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3133 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3134 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3135 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3136 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3137 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3138 | self.waitUntilSettled() |
| 3139 | |
| 3140 | self.assertEqual(A.data['status'], 'MERGED') |
| 3141 | self.assertEqual(A.reported, 2) |
| 3142 | self.assertEqual(B.data['status'], 'MERGED') |
| 3143 | self.assertEqual(B.reported, 2) |
| 3144 | self.assertEqual(C.data['status'], 'MERGED') |
| 3145 | self.assertEqual(C.reported, 2) |
| 3146 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3147 | self.assertEqual(r, True) |
| 3148 | |
| 3149 | def test_client_promote_negative(self): |
| 3150 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3151 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3152 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3153 | A.addApproval('code-review', 2) |
| 3154 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3155 | self.waitUntilSettled() |
| 3156 | |
| 3157 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3158 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3159 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3160 | |
| 3161 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3162 | r = client.promote(tenant='tenant-one', |
| 3163 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3164 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | self.assertEqual(r, False) |
| 3166 | |
| 3167 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3168 | r = client.promote(tenant='tenant-one', |
| 3169 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3170 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3171 | self.assertEqual(r, False) |
| 3172 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3173 | self.executor_server.hold_jobs_in_build = False |
| 3174 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3175 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3176 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3177 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3178 | def test_queue_rate_limiting(self): |
| 3179 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3180 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3181 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3182 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3183 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3184 | |
| 3185 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3186 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3187 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3188 | A.addApproval('code-review', 2) |
| 3189 | B.addApproval('code-review', 2) |
| 3190 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3191 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3192 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3193 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3194 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3195 | self.waitUntilSettled() |
| 3196 | |
| 3197 | # Only A and B will have their merge jobs queued because |
| 3198 | # window is 2. |
| 3199 | self.assertEqual(len(self.builds), 2) |
| 3200 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3201 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3202 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3203 | # Release the merge jobs one at a time. |
| 3204 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3205 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3206 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3207 | self.waitUntilSettled() |
| 3208 | |
| 3209 | # Only A and B will have their test jobs queued because |
| 3210 | # window is 2. |
| 3211 | self.assertEqual(len(self.builds), 4) |
| 3212 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3213 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3214 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3215 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3216 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3217 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3218 | self.waitUntilSettled() |
| 3219 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3220 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3221 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3222 | # A failed so window is reduced by 1 to 1. |
| 3223 | self.assertEqual(queue.window, 1) |
| 3224 | self.assertEqual(queue.window_floor, 1) |
| 3225 | self.assertEqual(A.data['status'], 'NEW') |
| 3226 | |
| 3227 | # Gate is reset and only B's merge job is queued because |
| 3228 | # window shrunk to 1. |
| 3229 | self.assertEqual(len(self.builds), 1) |
| 3230 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3232 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3233 | self.waitUntilSettled() |
| 3234 | |
| 3235 | # Only B's test jobs are queued because window is still 1. |
| 3236 | self.assertEqual(len(self.builds), 2) |
| 3237 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3238 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3239 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3240 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3241 | self.waitUntilSettled() |
| 3242 | |
| 3243 | # B was successfully merged so window is increased to 2. |
| 3244 | self.assertEqual(queue.window, 2) |
| 3245 | self.assertEqual(queue.window_floor, 1) |
| 3246 | self.assertEqual(B.data['status'], 'MERGED') |
| 3247 | |
| 3248 | # Only C is left and its merge job is queued. |
| 3249 | self.assertEqual(len(self.builds), 1) |
| 3250 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3251 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3252 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3253 | self.waitUntilSettled() |
| 3254 | |
| 3255 | # After successful merge job the test jobs for C are queued. |
| 3256 | self.assertEqual(len(self.builds), 2) |
| 3257 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3258 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3259 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3260 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3261 | self.waitUntilSettled() |
| 3262 | |
| 3263 | # C successfully merged so window is bumped to 3. |
| 3264 | self.assertEqual(queue.window, 3) |
| 3265 | self.assertEqual(queue.window_floor, 1) |
| 3266 | self.assertEqual(C.data['status'], 'MERGED') |
| 3267 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3268 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3269 | def test_queue_rate_limiting_dependent(self): |
| 3270 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3271 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3272 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3273 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3274 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3275 | |
| 3276 | B.setDependsOn(A, 1) |
| 3277 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3278 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3279 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3280 | A.addApproval('code-review', 2) |
| 3281 | B.addApproval('code-review', 2) |
| 3282 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3283 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3284 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3285 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3286 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3287 | self.waitUntilSettled() |
| 3288 | |
| 3289 | # Only A and B will have their merge jobs queued because |
| 3290 | # window is 2. |
| 3291 | self.assertEqual(len(self.builds), 2) |
| 3292 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3293 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3294 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3295 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3296 | |
| 3297 | # Only A and B will have their test jobs queued because |
| 3298 | # window is 2. |
| 3299 | self.assertEqual(len(self.builds), 4) |
| 3300 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3301 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3302 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3303 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3304 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3305 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3306 | self.waitUntilSettled() |
| 3307 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3308 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3309 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3310 | # A failed so window is reduced by 1 to 1. |
| 3311 | self.assertEqual(queue.window, 1) |
| 3312 | self.assertEqual(queue.window_floor, 1) |
| 3313 | self.assertEqual(A.data['status'], 'NEW') |
| 3314 | self.assertEqual(B.data['status'], 'NEW') |
| 3315 | |
| 3316 | # Gate is reset and only C's merge job is queued because |
| 3317 | # window shrunk to 1 and A and B were dequeued. |
| 3318 | self.assertEqual(len(self.builds), 1) |
| 3319 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3320 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3321 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3322 | |
| 3323 | # Only C's test jobs are queued because window is still 1. |
| 3324 | self.assertEqual(len(self.builds), 2) |
| 3325 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3326 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3327 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3328 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3329 | self.waitUntilSettled() |
| 3330 | |
| 3331 | # C was successfully merged so window is increased to 2. |
| 3332 | self.assertEqual(queue.window, 2) |
| 3333 | self.assertEqual(queue.window_floor, 1) |
| 3334 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3335 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3336 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 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 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3346 | self.assertEqual(len(self.executor.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3347 | |
| 3348 | self.log.debug('Current builds:') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3349 | self.log.debug(self.executor.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 | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3356 | build = list(self.executor.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) |
| 3364 | self.assertEqual("localhost", build.worker.hostname) |
| 3365 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3366 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3367 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3368 | self.assertEqual("v1.1", build.worker.version) |
| 3369 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3370 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3371 | self.executor_server.hold_jobs_in_build = False |
| 3372 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3373 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3374 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3375 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3376 | def test_footer_message(self): |
| 3377 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3378 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3379 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3380 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3381 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3382 | self.waitUntilSettled() |
| 3383 | |
| 3384 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3385 | B.addApproval('code-review', 2) |
| 3386 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3387 | self.waitUntilSettled() |
| 3388 | |
| 3389 | self.assertEqual(2, len(self.smtp_messages)) |
| 3390 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3391 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3392 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3393 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3394 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3395 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3396 | For CI problems and help debugging, contact ci@example.org""" |
| 3397 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3398 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3399 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3400 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3401 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3402 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3403 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3404 | def test_merge_failure_reporters(self): |
| 3405 | """Check that the config is set up correctly""" |
| 3406 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3407 | self.updateConfigLayout( |
| 3408 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3409 | self.sched.reconfigure(self.config) |
| 3410 | self.registerJobs() |
| 3411 | |
| 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.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3417 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3418 | self.assertEqual( |
| 3419 | "The merge failed! For more information...", |
| 3420 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3421 | |
| 3422 | self.assertEqual( |
| 3423 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3424 | self.assertEqual( |
| 3425 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3426 | |
| 3427 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3428 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3429 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3430 | |
| 3431 | self.assertTrue( |
| 3432 | ( |
| 3433 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3434 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3435 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3436 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3437 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3438 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3439 | ) or ( |
| 3440 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3441 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3442 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3443 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3444 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3445 | zuul.reporter.smtp.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']) |
| 3542 | self.assertEqual(None, running_item['item_ahead']) |
| 3543 | self.assertEqual('org/project', running_item['project']) |
| 3544 | self.assertEqual(None, running_item['remaining_time']) |
| 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']) |
| 3556 | self.assertEqual(7, len(job['worker'])) |
| 3557 | self.assertEqual(False, job['canceled']) |
| 3558 | self.assertEqual(True, job['voting']) |
| 3559 | self.assertEqual(None, job['result']) |
| 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 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 3877 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3878 | def test_crd_check(self): |
| 3879 | "Test cross-repo dependencies in independent pipelines" |
| 3880 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3881 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3882 | self.gearman_server.hold_jobs_in_queue = True |
| 3883 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3884 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3885 | |
| 3886 | # A Depends-On: B |
| 3887 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3888 | A.subject, B.data['id']) |
| 3889 | |
| 3890 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3891 | self.waitUntilSettled() |
| 3892 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3893 | self.gearman_server.hold_jobs_in_queue = False |
| 3894 | self.gearman_server.release() |
| 3895 | self.waitUntilSettled() |
| 3896 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3897 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3898 | self.waitUntilSettled() |
| 3899 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 3900 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3901 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3902 | self.executor_server.hold_jobs_in_build = False |
| 3903 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3904 | self.waitUntilSettled() |
| 3905 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3906 | self.assertEqual(A.data['status'], 'NEW') |
| 3907 | self.assertEqual(B.data['status'], 'NEW') |
| 3908 | self.assertEqual(A.reported, 1) |
| 3909 | self.assertEqual(B.reported, 0) |
| 3910 | |
| 3911 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 3912 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3913 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3914 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3915 | def test_crd_check_git_depends(self): |
| 3916 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3917 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3918 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3919 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 3920 | |
| 3921 | # Add two git-dependent changes and make sure they both report |
| 3922 | # success. |
| 3923 | B.setDependsOn(A, 1) |
| 3924 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3925 | self.waitUntilSettled() |
| 3926 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3927 | self.waitUntilSettled() |
| 3928 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 3929 | self.orderedRelease() |
| 3930 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3931 | self.waitUntilSettled() |
| 3932 | |
| 3933 | self.assertEqual(A.data['status'], 'NEW') |
| 3934 | self.assertEqual(B.data['status'], 'NEW') |
| 3935 | self.assertEqual(A.reported, 1) |
| 3936 | self.assertEqual(B.reported, 1) |
| 3937 | |
| 3938 | self.assertEqual(self.history[0].changes, '1,1') |
| 3939 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3940 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3941 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3942 | |
| 3943 | self.assertIn('Build succeeded', A.messages[0]) |
| 3944 | self.assertIn('Build succeeded', B.messages[0]) |
| 3945 | |
| 3946 | def test_crd_check_duplicate(self): |
| 3947 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3948 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3949 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3950 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3951 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3952 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3953 | |
| 3954 | # Add two git-dependent changes... |
| 3955 | B.setDependsOn(A, 1) |
| 3956 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3957 | self.waitUntilSettled() |
| 3958 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3959 | |
| 3960 | # ...make sure the live one is not duplicated... |
| 3961 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3962 | self.waitUntilSettled() |
| 3963 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 3964 | |
| 3965 | # ...but the non-live one is able to be. |
| 3966 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3967 | self.waitUntilSettled() |
| 3968 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 3969 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 3970 | # Release jobs in order to avoid races with change A jobs |
| 3971 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 3972 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3973 | self.executor_server.hold_jobs_in_build = False |
| 3974 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3975 | self.waitUntilSettled() |
| 3976 | |
| 3977 | self.assertEqual(A.data['status'], 'NEW') |
| 3978 | self.assertEqual(B.data['status'], 'NEW') |
| 3979 | self.assertEqual(A.reported, 1) |
| 3980 | self.assertEqual(B.reported, 1) |
| 3981 | |
| 3982 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 3983 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 3984 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 3985 | |
| 3986 | self.assertIn('Build succeeded', A.messages[0]) |
| 3987 | self.assertIn('Build succeeded', B.messages[0]) |
| 3988 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3989 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3990 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 3991 | |
| 3992 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3993 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 3994 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3995 | |
| 3996 | # A Depends-On: B |
| 3997 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3998 | A.subject, B.data['id']) |
| 3999 | |
| 4000 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4001 | self.waitUntilSettled() |
| 4002 | |
| 4003 | self.sched.reconfigure(self.config) |
| 4004 | |
| 4005 | # Make sure the items still share a change queue, and the |
| 4006 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4007 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4008 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4009 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4010 | first_item = queue.queue[0] |
| 4011 | for item in queue.queue: |
| 4012 | self.assertEqual(item.queue, first_item.queue) |
| 4013 | self.assertFalse(first_item.live) |
| 4014 | self.assertTrue(queue.queue[1].live) |
| 4015 | |
| 4016 | self.gearman_server.hold_jobs_in_queue = False |
| 4017 | self.gearman_server.release() |
| 4018 | self.waitUntilSettled() |
| 4019 | |
| 4020 | self.assertEqual(A.data['status'], 'NEW') |
| 4021 | self.assertEqual(B.data['status'], 'NEW') |
| 4022 | self.assertEqual(A.reported, 1) |
| 4023 | self.assertEqual(B.reported, 0) |
| 4024 | |
| 4025 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4026 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4027 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 4028 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4029 | def test_crd_check_reconfiguration(self): |
| 4030 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4031 | |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 4032 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4033 | def test_crd_undefined_project(self): |
| 4034 | """Test that undefined projects in dependencies are handled for |
| 4035 | independent pipelines""" |
| 4036 | # It's a hack for fake gerrit, |
| 4037 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4038 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4039 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4040 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4041 | @simple_layout('layouts/ignore-dependencies.yaml') |
Clint Byrum | 8897dca | 2017-05-10 19:14:19 -0700 | [diff] [blame] | 4042 | @skipIf(sys.version_info.major > 2, 'Fails on py3') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4043 | def test_crd_check_ignore_dependencies(self): |
| 4044 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4045 | |
| 4046 | self.gearman_server.hold_jobs_in_queue = True |
| 4047 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4048 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4049 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4050 | |
| 4051 | # A Depends-On: B |
| 4052 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4053 | A.subject, B.data['id']) |
| 4054 | # C git-depends on B |
| 4055 | C.setDependsOn(B, 1) |
| 4056 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4057 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4058 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4059 | self.waitUntilSettled() |
| 4060 | |
| 4061 | # Make sure none of the items share a change queue, and all |
| 4062 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4063 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4064 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4065 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4066 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4067 | for item in check_pipeline.getAllItems(): |
| 4068 | self.assertTrue(item.live) |
| 4069 | |
| 4070 | self.gearman_server.hold_jobs_in_queue = False |
| 4071 | self.gearman_server.release() |
| 4072 | self.waitUntilSettled() |
| 4073 | |
| 4074 | self.assertEqual(A.data['status'], 'NEW') |
| 4075 | self.assertEqual(B.data['status'], 'NEW') |
| 4076 | self.assertEqual(C.data['status'], 'NEW') |
| 4077 | self.assertEqual(A.reported, 1) |
| 4078 | self.assertEqual(B.reported, 1) |
| 4079 | self.assertEqual(C.reported, 1) |
| 4080 | |
| 4081 | # Each job should have tested exactly one change |
| 4082 | for job in self.history: |
| 4083 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4084 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4085 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4086 | def test_crd_check_transitive(self): |
| 4087 | "Test transitive cross-repo dependencies" |
| 4088 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4089 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4090 | # and C,2 (not C,1 which would indicate stale data in the |
| 4091 | # cache for B). |
| 4092 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4093 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4094 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4095 | |
| 4096 | # A Depends-On: B |
| 4097 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4098 | A.subject, B.data['id']) |
| 4099 | |
| 4100 | # B Depends-On: C |
| 4101 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4102 | B.subject, C.data['id']) |
| 4103 | |
| 4104 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4105 | self.waitUntilSettled() |
| 4106 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4107 | |
| 4108 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4109 | self.waitUntilSettled() |
| 4110 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4111 | |
| 4112 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4113 | self.waitUntilSettled() |
| 4114 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4115 | |
| 4116 | C.addPatchset() |
| 4117 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4118 | self.waitUntilSettled() |
| 4119 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4120 | |
| 4121 | A.addPatchset() |
| 4122 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4123 | self.waitUntilSettled() |
| 4124 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4125 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4126 | def test_crd_check_unknown(self): |
| 4127 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4128 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4129 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4130 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4131 | # A Depends-On: B |
| 4132 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4133 | A.subject, B.data['id']) |
| 4134 | |
| 4135 | # Make sure zuul has seen an event on B. |
| 4136 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4137 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4138 | self.waitUntilSettled() |
| 4139 | |
| 4140 | self.assertEqual(A.data['status'], 'NEW') |
| 4141 | self.assertEqual(A.reported, 1) |
| 4142 | self.assertEqual(B.data['status'], 'NEW') |
| 4143 | self.assertEqual(B.reported, 0) |
| 4144 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4145 | def test_crd_cycle_join(self): |
| 4146 | "Test an updated change creates a cycle" |
| 4147 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4148 | |
| 4149 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4150 | self.waitUntilSettled() |
| 4151 | |
| 4152 | # Create B->A |
| 4153 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4154 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4155 | B.subject, A.data['id']) |
| 4156 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4157 | self.waitUntilSettled() |
| 4158 | |
| 4159 | # Update A to add A->B (a cycle). |
| 4160 | A.addPatchset() |
| 4161 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4162 | A.subject, B.data['id']) |
| 4163 | # Normally we would submit the patchset-created event for |
| 4164 | # processing here, however, we have no way of noting whether |
| 4165 | # the dependency cycle detection correctly raised an |
| 4166 | # exception, so instead, we reach into the source driver and |
| 4167 | # call the method that would ultimately be called by the event |
| 4168 | # processing. |
| 4169 | |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4170 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 4171 | (trusted, project) = tenant.getProject('org/project') |
| 4172 | source = project.source |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4173 | |
| 4174 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 4175 | # it easier for users to create events for testing. |
| 4176 | event = zuul.model.TriggerEvent() |
| 4177 | event.trigger_name = 'gerrit' |
| 4178 | event.change_number = '1' |
| 4179 | event.patch_number = '2' |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4180 | with testtools.ExpectedException( |
| 4181 | Exception, "Dependency cycle detected"): |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4182 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4183 | self.log.debug("Got expected dependency cycle exception") |
| 4184 | |
| 4185 | # Now if we update B to remove the depends-on, everything |
| 4186 | # should be okay. B; A->B |
| 4187 | |
| 4188 | B.addPatchset() |
| 4189 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4190 | |
| 4191 | source.getChange(event, True) |
| 4192 | event.change_number = '2' |
| 4193 | source.getChange(event, True) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4194 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4195 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4196 | def test_disable_at(self): |
| 4197 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4198 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4199 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4200 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4201 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4202 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4203 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4204 | |
| 4205 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4206 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4207 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4208 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4209 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4210 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4211 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4212 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4213 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4214 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4215 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4216 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4217 | self.executor_server.failJob('project-test1', A) |
| 4218 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4219 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4220 | self.executor_server.failJob('project-test1', D) |
| 4221 | self.executor_server.failJob('project-test1', E) |
| 4222 | self.executor_server.failJob('project-test1', F) |
| 4223 | self.executor_server.failJob('project-test1', G) |
| 4224 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4225 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4226 | self.executor_server.failJob('project-test1', J) |
| 4227 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4228 | |
| 4229 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4230 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4231 | self.waitUntilSettled() |
| 4232 | |
| 4233 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4234 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4235 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4236 | |
| 4237 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4238 | self.waitUntilSettled() |
| 4239 | |
| 4240 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4241 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4242 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4243 | |
| 4244 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4245 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4246 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4247 | self.waitUntilSettled() |
| 4248 | |
| 4249 | # We should be disabled now |
| 4250 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4251 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4252 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4253 | |
| 4254 | # We need to wait between each of these patches to make sure the |
| 4255 | # smtp messages come back in an expected order |
| 4256 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4257 | self.waitUntilSettled() |
| 4258 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4259 | self.waitUntilSettled() |
| 4260 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4261 | self.waitUntilSettled() |
| 4262 | |
| 4263 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4264 | # leaving a message on each change |
| 4265 | self.assertEqual(1, len(A.messages)) |
| 4266 | self.assertIn('Build failed.', A.messages[0]) |
| 4267 | self.assertEqual(1, len(B.messages)) |
| 4268 | self.assertIn('Build failed.', B.messages[0]) |
| 4269 | self.assertEqual(1, len(C.messages)) |
| 4270 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4271 | self.assertEqual(1, len(D.messages)) |
| 4272 | self.assertIn('Build failed.', D.messages[0]) |
| 4273 | self.assertEqual(1, len(E.messages)) |
| 4274 | self.assertIn('Build failed.', E.messages[0]) |
| 4275 | self.assertEqual(1, len(F.messages)) |
| 4276 | self.assertIn('Build failed.', F.messages[0]) |
| 4277 | |
| 4278 | # The last 3 (GHI) would have only reported via smtp. |
| 4279 | self.assertEqual(3, len(self.smtp_messages)) |
| 4280 | self.assertEqual(0, len(G.messages)) |
| 4281 | self.assertIn('Build failed.', self.smtp_messages[0]['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[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4284 | self.assertEqual(0, len(H.messages)) |
| 4285 | self.assertIn('Build failed.', self.smtp_messages[1]['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[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4288 | self.assertEqual(0, len(I.messages)) |
| 4289 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4290 | self.assertIn( |
| 4291 | 'project-test1 https://server/job', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4292 | |
| 4293 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4294 | # comes out of disabled |
| 4295 | self.sched.reconfigure(self.config) |
| 4296 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4297 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4298 | |
| 4299 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4300 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4301 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4302 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4303 | |
| 4304 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4305 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4306 | self.waitUntilSettled() |
| 4307 | |
| 4308 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4309 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4310 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4311 | |
| 4312 | # J and K went back to gerrit |
| 4313 | self.assertEqual(1, len(J.messages)) |
| 4314 | self.assertIn('Build failed.', J.messages[0]) |
| 4315 | self.assertEqual(1, len(K.messages)) |
| 4316 | self.assertIn('Build failed.', K.messages[0]) |
| 4317 | # No more messages reported via smtp |
| 4318 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4319 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4320 | @simple_layout('layouts/one-job-project.yaml') |
| 4321 | def test_one_job_project(self): |
| 4322 | "Test that queueing works with one job" |
| 4323 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4324 | 'master', 'A') |
| 4325 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4326 | 'master', 'B') |
| 4327 | A.addApproval('code-review', 2) |
| 4328 | B.addApproval('code-review', 2) |
| 4329 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4330 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4331 | self.waitUntilSettled() |
| 4332 | |
| 4333 | self.assertEqual(A.data['status'], 'MERGED') |
| 4334 | self.assertEqual(A.reported, 2) |
| 4335 | self.assertEqual(B.data['status'], 'MERGED') |
| 4336 | self.assertEqual(B.reported, 2) |
| 4337 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4338 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4339 | "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] | 4340 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4341 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4342 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4343 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4344 | self.waitUntilSettled() |
| 4345 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4346 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4347 | self.waitUntilSettled() |
| 4348 | |
| 4349 | self.assertEqual(len(self.builds), 2) |
| 4350 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4351 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4352 | self.waitUntilSettled() |
| 4353 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4354 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4355 | self.assertEqual(len(self.builds), 1, |
| 4356 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4357 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4358 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4359 | self.waitUntilSettled() |
| 4360 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4361 | self.executor_server.hold_jobs_in_build = False |
| 4362 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4363 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4364 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4365 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4366 | self.assertEqual(A.reported, 1) |
| 4367 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4368 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4369 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4370 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4371 | |
| 4372 | self.fake_nodepool.paused = True |
| 4373 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4374 | A.addApproval('code-review', 2) |
| 4375 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4376 | self.waitUntilSettled() |
| 4377 | |
| 4378 | self.zk.client.stop() |
| 4379 | self.zk.client.start() |
| 4380 | self.fake_nodepool.paused = False |
| 4381 | self.waitUntilSettled() |
| 4382 | |
| 4383 | self.assertEqual(A.data['status'], 'MERGED') |
| 4384 | self.assertEqual(A.reported, 2) |
| 4385 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4386 | def test_nodepool_failure(self): |
| 4387 | "Test that jobs are reported after a nodepool failure" |
| 4388 | |
| 4389 | self.fake_nodepool.paused = True |
| 4390 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4391 | A.addApproval('code-review', 2) |
| 4392 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4393 | self.waitUntilSettled() |
| 4394 | |
| 4395 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4396 | self.fake_nodepool.addFailRequest(req) |
| 4397 | |
| 4398 | self.fake_nodepool.paused = False |
| 4399 | self.waitUntilSettled() |
| 4400 | |
| 4401 | self.assertEqual(A.data['status'], 'NEW') |
| 4402 | self.assertEqual(A.reported, 2) |
| 4403 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4404 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4405 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4406 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4407 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4408 | class TestExecutor(ZuulTestCase): |
| 4409 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4410 | |
| 4411 | def assertFinalState(self): |
| 4412 | # In this test, we expect to shut down in a non-final state, |
| 4413 | # so skip these checks. |
| 4414 | pass |
| 4415 | |
| 4416 | def assertCleanShutdown(self): |
| 4417 | self.log.debug("Assert clean shutdown") |
| 4418 | |
| 4419 | # After shutdown, make sure no jobs are running |
| 4420 | self.assertEqual({}, self.executor_server.job_workers) |
| 4421 | |
| 4422 | # Make sure that git.Repo objects have been garbage collected. |
| 4423 | repos = [] |
| 4424 | gc.collect() |
| 4425 | for obj in gc.get_objects(): |
| 4426 | if isinstance(obj, git.Repo): |
| 4427 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4428 | repos.append(obj) |
| 4429 | self.assertEqual(len(repos), 0) |
| 4430 | |
| 4431 | def test_executor_shutdown(self): |
| 4432 | "Test that the executor can shut down with jobs running" |
| 4433 | |
| 4434 | self.executor_server.hold_jobs_in_build = True |
| 4435 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4436 | A.addApproval('code-review', 2) |
| 4437 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4438 | self.waitUntilSettled() |
| 4439 | |
| 4440 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4441 | class TestDependencyGraph(ZuulTestCase): |
| 4442 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4443 | |
| 4444 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4445 | "Test a job in a dependency graph is queued only once" |
| 4446 | # Job dependencies, starting with A |
| 4447 | # A |
| 4448 | # / \ |
| 4449 | # B C |
| 4450 | # / \ / \ |
| 4451 | # D F E |
| 4452 | # | |
| 4453 | # G |
| 4454 | |
| 4455 | self.executor_server.hold_jobs_in_build = True |
| 4456 | change = self.fake_gerrit.addFakeChange( |
| 4457 | 'org/project', 'master', 'change') |
| 4458 | change.addApproval('code-review', 2) |
| 4459 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4460 | |
| 4461 | self.waitUntilSettled() |
| 4462 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4463 | |
| 4464 | self.executor_server.release('A') |
| 4465 | self.waitUntilSettled() |
| 4466 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4467 | |
| 4468 | self.executor_server.release('B') |
| 4469 | self.waitUntilSettled() |
| 4470 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4471 | |
| 4472 | self.executor_server.release('D') |
| 4473 | self.waitUntilSettled() |
| 4474 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4475 | |
| 4476 | self.executor_server.release('C') |
| 4477 | self.waitUntilSettled() |
| 4478 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4479 | |
| 4480 | self.executor_server.release('F') |
| 4481 | self.waitUntilSettled() |
| 4482 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4483 | |
| 4484 | self.executor_server.release('G') |
| 4485 | self.waitUntilSettled() |
| 4486 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4487 | |
| 4488 | self.executor_server.release('E') |
| 4489 | self.waitUntilSettled() |
| 4490 | self.assertEqual(len(self.builds), 0) |
| 4491 | |
| 4492 | self.executor_server.hold_jobs_in_build = False |
| 4493 | self.executor_server.release() |
| 4494 | self.waitUntilSettled() |
| 4495 | |
| 4496 | self.assertEqual(len(self.builds), 0) |
| 4497 | self.assertEqual(len(self.history), 7) |
| 4498 | |
| 4499 | self.assertEqual(change.data['status'], 'MERGED') |
| 4500 | self.assertEqual(change.reported, 2) |
| 4501 | |
| 4502 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4503 | "Test that a job waits till all dependencies are successful" |
| 4504 | # Job dependencies, starting with A |
| 4505 | # A |
| 4506 | # / \ |
| 4507 | # B C* |
| 4508 | # / \ / \ |
| 4509 | # D F E |
| 4510 | # | |
| 4511 | # G |
| 4512 | |
| 4513 | self.executor_server.hold_jobs_in_build = True |
| 4514 | change = self.fake_gerrit.addFakeChange( |
| 4515 | 'org/project', 'master', 'change') |
| 4516 | change.addApproval('code-review', 2) |
| 4517 | |
| 4518 | self.executor_server.failJob('C', change) |
| 4519 | |
| 4520 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4521 | |
| 4522 | self.waitUntilSettled() |
| 4523 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4524 | |
| 4525 | self.executor_server.release('A') |
| 4526 | self.waitUntilSettled() |
| 4527 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4528 | |
| 4529 | self.executor_server.release('B') |
| 4530 | self.waitUntilSettled() |
| 4531 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4532 | |
| 4533 | self.executor_server.release('D') |
| 4534 | self.waitUntilSettled() |
| 4535 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4536 | |
| 4537 | self.executor_server.release('C') |
| 4538 | self.waitUntilSettled() |
| 4539 | self.assertEqual(len(self.builds), 0) |
| 4540 | |
| 4541 | self.executor_server.hold_jobs_in_build = False |
| 4542 | self.executor_server.release() |
| 4543 | self.waitUntilSettled() |
| 4544 | |
| 4545 | self.assertEqual(len(self.builds), 0) |
| 4546 | self.assertEqual(len(self.history), 4) |
| 4547 | |
| 4548 | self.assertEqual(change.data['status'], 'NEW') |
| 4549 | self.assertEqual(change.reported, 2) |
| 4550 | |
| 4551 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4552 | class TestDuplicatePipeline(ZuulTestCase): |
| 4553 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4554 | |
| 4555 | def test_duplicate_pipelines(self): |
| 4556 | "Test that a change matching multiple pipelines works" |
| 4557 | |
| 4558 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4559 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4560 | self.waitUntilSettled() |
| 4561 | |
| 4562 | self.assertHistory([ |
| 4563 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4564 | pipeline='dup1'), |
| 4565 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4566 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4567 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4568 | |
| 4569 | self.assertEqual(len(A.messages), 2) |
| 4570 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4571 | if 'dup1' in A.messages[0]: |
| 4572 | self.assertIn('dup1', A.messages[0]) |
| 4573 | self.assertNotIn('dup2', A.messages[0]) |
| 4574 | self.assertIn('project-test1', A.messages[0]) |
| 4575 | self.assertIn('dup2', A.messages[1]) |
| 4576 | self.assertNotIn('dup1', A.messages[1]) |
| 4577 | self.assertIn('project-test1', A.messages[1]) |
| 4578 | else: |
| 4579 | self.assertIn('dup1', A.messages[1]) |
| 4580 | self.assertNotIn('dup2', A.messages[1]) |
| 4581 | self.assertIn('project-test1', A.messages[1]) |
| 4582 | self.assertIn('dup2', A.messages[0]) |
| 4583 | self.assertNotIn('dup1', A.messages[0]) |
| 4584 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4585 | |
| 4586 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4587 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4588 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4589 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4590 | def test_job_from_templates_executed(self): |
| 4591 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4592 | |
| 4593 | A = self.fake_gerrit.addFakeChange( |
| 4594 | 'org/templated-project', 'master', 'A') |
| 4595 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4596 | self.waitUntilSettled() |
| 4597 | |
| 4598 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4599 | 'SUCCESS') |
| 4600 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4601 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4602 | |
| 4603 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4604 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4605 | |
| 4606 | A = self.fake_gerrit.addFakeChange( |
| 4607 | 'org/layered-project', 'master', 'A') |
| 4608 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4609 | self.waitUntilSettled() |
| 4610 | |
| 4611 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4612 | 'SUCCESS') |
| 4613 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4614 | 'SUCCESS') |
| 4615 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4616 | ).result, 'SUCCESS') |
| 4617 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4618 | ).result, 'SUCCESS') |
| 4619 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4620 | ).result, 'SUCCESS') |
| 4621 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4622 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4623 | |
| 4624 | |
| 4625 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4626 | tenant_config_file = 'config/success-url/main.yaml' |
| 4627 | |
| 4628 | def test_success_url(self): |
| 4629 | "Ensure bad build params are ignored" |
| 4630 | self.sched.reconfigure(self.config) |
| 4631 | self.init_repo('org/docs') |
| 4632 | |
| 4633 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4634 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4635 | self.waitUntilSettled() |
| 4636 | |
| 4637 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4638 | self.assertEqual(len(self.history), 2) |
| 4639 | |
| 4640 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4641 | for build in self.history: |
| 4642 | if build.name == 'docs-draft-test': |
| 4643 | uuid = build.uuid[:7] |
| 4644 | break |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4645 | |
| 4646 | # Two msgs: 'Starting...' + results |
| 4647 | self.assertEqual(len(self.smtp_messages), 2) |
| 4648 | body = self.smtp_messages[1]['body'].splitlines() |
| 4649 | self.assertEqual('Build succeeded.', body[0]) |
| 4650 | |
| 4651 | self.assertIn( |
| 4652 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4653 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4654 | body[2]) |
| 4655 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4656 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4657 | self.assertIn( |
| 4658 | '- docs-draft-test2 https://server/job', |
| 4659 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4660 | |
| 4661 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4662 | class TestSchedulerMerges(ZuulTestCase): |
| 4663 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4664 | |
| 4665 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4666 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4667 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4668 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4669 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4670 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4671 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4672 | A.addApproval('code-review', 2) |
| 4673 | B.addApproval('code-review', 2) |
| 4674 | C.addApproval('code-review', 2) |
| 4675 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4676 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4677 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4678 | self.waitUntilSettled() |
| 4679 | |
| 4680 | build = self.builds[-1] |
| 4681 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4682 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4683 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4684 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4685 | repo = git.Repo(path) |
| 4686 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4687 | repo_messages.reverse() |
| 4688 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4689 | self.executor_server.hold_jobs_in_build = False |
| 4690 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4691 | self.waitUntilSettled() |
| 4692 | |
| 4693 | return repo_messages |
| 4694 | |
| 4695 | def _test_merge(self, mode): |
| 4696 | us_path = os.path.join( |
| 4697 | self.upstream_root, 'org/project-%s' % mode) |
| 4698 | expected_messages = [ |
| 4699 | 'initial commit', |
| 4700 | 'add content from fixture', |
| 4701 | # the intermediate commits order is nondeterministic |
| 4702 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4703 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4704 | ] |
| 4705 | result = self._test_project_merge_mode(mode) |
| 4706 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4707 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4708 | |
| 4709 | def test_project_merge_mode_merge(self): |
| 4710 | self._test_merge('merge') |
| 4711 | |
| 4712 | def test_project_merge_mode_merge_resolve(self): |
| 4713 | self._test_merge('merge-resolve') |
| 4714 | |
| 4715 | def test_project_merge_mode_cherrypick(self): |
| 4716 | expected_messages = [ |
| 4717 | 'initial commit', |
| 4718 | 'add content from fixture', |
| 4719 | 'A-1', |
| 4720 | 'B-1', |
| 4721 | 'C-1'] |
| 4722 | result = self._test_project_merge_mode('cherry-pick') |
| 4723 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4724 | |
| 4725 | def test_merge_branch(self): |
| 4726 | "Test that the right commits are on alternate branches" |
| 4727 | self.create_branch('org/project-merge-branches', 'mp') |
| 4728 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4729 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4730 | A = self.fake_gerrit.addFakeChange( |
| 4731 | 'org/project-merge-branches', 'mp', 'A') |
| 4732 | B = self.fake_gerrit.addFakeChange( |
| 4733 | 'org/project-merge-branches', 'mp', 'B') |
| 4734 | C = self.fake_gerrit.addFakeChange( |
| 4735 | 'org/project-merge-branches', 'mp', 'C') |
| 4736 | A.addApproval('code-review', 2) |
| 4737 | B.addApproval('code-review', 2) |
| 4738 | C.addApproval('code-review', 2) |
| 4739 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4740 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4741 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4742 | self.waitUntilSettled() |
| 4743 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4746 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4747 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4748 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4749 | self.waitUntilSettled() |
| 4750 | |
| 4751 | build = self.builds[-1] |
| 4752 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4753 | ref = self.getParameter(build, 'ZUUL_REF') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4754 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4755 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4756 | repo = git.Repo(path) |
| 4757 | |
| 4758 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4759 | repo_messages.reverse() |
| 4760 | correct_messages = [ |
| 4761 | 'initial commit', |
| 4762 | 'add content from fixture', |
| 4763 | 'mp commit', |
| 4764 | 'A-1', 'B-1', 'C-1'] |
| 4765 | self.assertEqual(repo_messages, correct_messages) |
| 4766 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4767 | self.executor_server.hold_jobs_in_build = False |
| 4768 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4769 | self.waitUntilSettled() |
| 4770 | |
| 4771 | def test_merge_multi_branch(self): |
| 4772 | "Test that dependent changes on multiple branches are merged" |
| 4773 | self.create_branch('org/project-merge-branches', 'mp') |
| 4774 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4775 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4776 | A = self.fake_gerrit.addFakeChange( |
| 4777 | 'org/project-merge-branches', 'master', 'A') |
| 4778 | B = self.fake_gerrit.addFakeChange( |
| 4779 | 'org/project-merge-branches', 'mp', 'B') |
| 4780 | C = self.fake_gerrit.addFakeChange( |
| 4781 | 'org/project-merge-branches', 'master', 'C') |
| 4782 | A.addApproval('code-review', 2) |
| 4783 | B.addApproval('code-review', 2) |
| 4784 | C.addApproval('code-review', 2) |
| 4785 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4786 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4787 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4788 | self.waitUntilSettled() |
| 4789 | |
| 4790 | job_A = None |
| 4791 | for job in self.builds: |
| 4792 | if 'project-merge' in job.name: |
| 4793 | job_A = job |
| 4794 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4795 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4796 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4797 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4798 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4799 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4800 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4801 | repo = git.Repo(path) |
| 4802 | repo_messages = [c.message.strip() |
| 4803 | for c in repo.iter_commits(ref_A)] |
| 4804 | repo_messages.reverse() |
| 4805 | correct_messages = [ |
| 4806 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4807 | self.assertEqual(repo_messages, correct_messages) |
| 4808 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4809 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4810 | self.waitUntilSettled() |
| 4811 | |
| 4812 | job_B = None |
| 4813 | for job in self.builds: |
| 4814 | if 'project-merge' in job.name: |
| 4815 | job_B = job |
| 4816 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4817 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4818 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4819 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4820 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4821 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4822 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4823 | repo = git.Repo(path) |
| 4824 | repo_messages = [c.message.strip() |
| 4825 | for c in repo.iter_commits(ref_B)] |
| 4826 | repo_messages.reverse() |
| 4827 | correct_messages = [ |
| 4828 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4829 | self.assertEqual(repo_messages, correct_messages) |
| 4830 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4831 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4832 | self.waitUntilSettled() |
| 4833 | |
| 4834 | job_C = None |
| 4835 | for job in self.builds: |
| 4836 | if 'project-merge' in job.name: |
| 4837 | job_C = job |
| 4838 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4839 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4840 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4841 | 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] | 4842 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4843 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4844 | repo = git.Repo(path) |
| 4845 | repo_messages = [c.message.strip() |
| 4846 | for c in repo.iter_commits(ref_C)] |
| 4847 | |
| 4848 | repo_messages.reverse() |
| 4849 | correct_messages = [ |
| 4850 | 'initial commit', 'add content from fixture', |
| 4851 | 'A-1', 'C-1'] |
| 4852 | # Ensure the right commits are in the history for this ref |
| 4853 | self.assertEqual(repo_messages, correct_messages) |
| 4854 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4855 | self.executor_server.hold_jobs_in_build = False |
| 4856 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4857 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 4858 | |
| 4859 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 4860 | class TestSemaphore(ZuulTestCase): |
| 4861 | tenant_config_file = 'config/semaphore/main.yaml' |
| 4862 | |
| 4863 | def test_semaphore_one(self): |
| 4864 | "Test semaphores with max=1 (mutex)" |
| 4865 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4866 | |
| 4867 | self.executor_server.hold_jobs_in_build = True |
| 4868 | |
| 4869 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4870 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4871 | self.assertFalse('test-semaphore' in |
| 4872 | tenant.semaphore_handler.semaphores) |
| 4873 | |
| 4874 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4875 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4876 | self.waitUntilSettled() |
| 4877 | |
| 4878 | self.assertEqual(len(self.builds), 3) |
| 4879 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4880 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 4881 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4882 | |
| 4883 | self.executor_server.release('semaphore-one-test1') |
| 4884 | self.waitUntilSettled() |
| 4885 | |
| 4886 | self.assertEqual(len(self.builds), 3) |
| 4887 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4888 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4889 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4890 | self.assertTrue('test-semaphore' in |
| 4891 | tenant.semaphore_handler.semaphores) |
| 4892 | |
| 4893 | self.executor_server.release('semaphore-one-test2') |
| 4894 | self.waitUntilSettled() |
| 4895 | |
| 4896 | self.assertEqual(len(self.builds), 3) |
| 4897 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4898 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4899 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 4900 | self.assertTrue('test-semaphore' in |
| 4901 | tenant.semaphore_handler.semaphores) |
| 4902 | |
| 4903 | self.executor_server.release('semaphore-one-test1') |
| 4904 | self.waitUntilSettled() |
| 4905 | |
| 4906 | self.assertEqual(len(self.builds), 3) |
| 4907 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4908 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4909 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4910 | self.assertTrue('test-semaphore' in |
| 4911 | tenant.semaphore_handler.semaphores) |
| 4912 | |
| 4913 | self.executor_server.release('semaphore-one-test2') |
| 4914 | self.waitUntilSettled() |
| 4915 | |
| 4916 | self.assertEqual(len(self.builds), 2) |
| 4917 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4918 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4919 | self.assertFalse('test-semaphore' in |
| 4920 | tenant.semaphore_handler.semaphores) |
| 4921 | |
| 4922 | self.executor_server.hold_jobs_in_build = False |
| 4923 | self.executor_server.release() |
| 4924 | |
| 4925 | self.waitUntilSettled() |
| 4926 | self.assertEqual(len(self.builds), 0) |
| 4927 | |
| 4928 | self.assertEqual(A.reported, 1) |
| 4929 | self.assertEqual(B.reported, 1) |
| 4930 | self.assertFalse('test-semaphore' in |
| 4931 | tenant.semaphore_handler.semaphores) |
| 4932 | |
| 4933 | def test_semaphore_two(self): |
| 4934 | "Test semaphores with max>1" |
| 4935 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4936 | |
| 4937 | self.executor_server.hold_jobs_in_build = True |
| 4938 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4939 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4940 | self.assertFalse('test-semaphore-two' in |
| 4941 | tenant.semaphore_handler.semaphores) |
| 4942 | |
| 4943 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4944 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4945 | self.waitUntilSettled() |
| 4946 | |
| 4947 | self.assertEqual(len(self.builds), 4) |
| 4948 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4949 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 4950 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4951 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 4952 | self.assertTrue('test-semaphore-two' in |
| 4953 | tenant.semaphore_handler.semaphores) |
| 4954 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4955 | 'test-semaphore-two', [])), 2) |
| 4956 | |
| 4957 | self.executor_server.release('semaphore-two-test1') |
| 4958 | self.waitUntilSettled() |
| 4959 | |
| 4960 | self.assertEqual(len(self.builds), 4) |
| 4961 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4962 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 4963 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4964 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 4965 | self.assertTrue('test-semaphore-two' in |
| 4966 | tenant.semaphore_handler.semaphores) |
| 4967 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4968 | 'test-semaphore-two', [])), 2) |
| 4969 | |
| 4970 | self.executor_server.release('semaphore-two-test2') |
| 4971 | self.waitUntilSettled() |
| 4972 | |
| 4973 | self.assertEqual(len(self.builds), 4) |
| 4974 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4975 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4976 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 4977 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 4978 | self.assertTrue('test-semaphore-two' in |
| 4979 | tenant.semaphore_handler.semaphores) |
| 4980 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4981 | 'test-semaphore-two', [])), 2) |
| 4982 | |
| 4983 | self.executor_server.release('semaphore-two-test1') |
| 4984 | self.waitUntilSettled() |
| 4985 | |
| 4986 | self.assertEqual(len(self.builds), 3) |
| 4987 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4988 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4989 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 4990 | self.assertTrue('test-semaphore-two' in |
| 4991 | tenant.semaphore_handler.semaphores) |
| 4992 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 4993 | 'test-semaphore-two', [])), 1) |
| 4994 | |
| 4995 | self.executor_server.release('semaphore-two-test2') |
| 4996 | self.waitUntilSettled() |
| 4997 | |
| 4998 | self.assertEqual(len(self.builds), 2) |
| 4999 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5000 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5001 | self.assertFalse('test-semaphore-two' in |
| 5002 | tenant.semaphore_handler.semaphores) |
| 5003 | |
| 5004 | self.executor_server.hold_jobs_in_build = False |
| 5005 | self.executor_server.release() |
| 5006 | |
| 5007 | self.waitUntilSettled() |
| 5008 | self.assertEqual(len(self.builds), 0) |
| 5009 | |
| 5010 | self.assertEqual(A.reported, 1) |
| 5011 | self.assertEqual(B.reported, 1) |
| 5012 | |
| 5013 | def test_semaphore_abandon(self): |
| 5014 | "Test abandon with job semaphores" |
| 5015 | self.executor_server.hold_jobs_in_build = True |
| 5016 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5017 | check_pipeline = tenant.layout.pipelines['check'] |
| 5018 | |
| 5019 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5020 | self.assertFalse('test-semaphore' in |
| 5021 | tenant.semaphore_handler.semaphores) |
| 5022 | |
| 5023 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5024 | self.waitUntilSettled() |
| 5025 | |
| 5026 | self.assertTrue('test-semaphore' in |
| 5027 | tenant.semaphore_handler.semaphores) |
| 5028 | |
| 5029 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5030 | self.waitUntilSettled() |
| 5031 | |
| 5032 | # The check pipeline should be empty |
| 5033 | items = check_pipeline.getAllItems() |
| 5034 | self.assertEqual(len(items), 0) |
| 5035 | |
| 5036 | # The semaphore should be released |
| 5037 | self.assertFalse('test-semaphore' in |
| 5038 | tenant.semaphore_handler.semaphores) |
| 5039 | |
| 5040 | self.executor_server.hold_jobs_in_build = False |
| 5041 | self.executor_server.release() |
| 5042 | self.waitUntilSettled() |
| 5043 | |
| 5044 | def test_semaphore_reconfigure(self): |
| 5045 | "Test reconfigure with job semaphores" |
| 5046 | self.executor_server.hold_jobs_in_build = True |
| 5047 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5048 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5049 | self.assertFalse('test-semaphore' in |
| 5050 | tenant.semaphore_handler.semaphores) |
| 5051 | |
| 5052 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5053 | self.waitUntilSettled() |
| 5054 | |
| 5055 | self.assertTrue('test-semaphore' in |
| 5056 | tenant.semaphore_handler.semaphores) |
| 5057 | |
| 5058 | # reconfigure without layout change |
| 5059 | self.sched.reconfigure(self.config) |
| 5060 | self.waitUntilSettled() |
| 5061 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5062 | |
| 5063 | # semaphore still must be held |
| 5064 | self.assertTrue('test-semaphore' in |
| 5065 | tenant.semaphore_handler.semaphores) |
| 5066 | |
| 5067 | self.commitConfigUpdate( |
| 5068 | 'common-config', |
| 5069 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5070 | self.sched.reconfigure(self.config) |
| 5071 | self.waitUntilSettled() |
| 5072 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5073 | |
| 5074 | self.executor_server.release('project-test1') |
| 5075 | self.waitUntilSettled() |
| 5076 | |
| 5077 | # There should be no builds anymore |
| 5078 | self.assertEqual(len(self.builds), 0) |
| 5079 | |
| 5080 | # The semaphore should be released |
| 5081 | self.assertFalse('test-semaphore' in |
| 5082 | tenant.semaphore_handler.semaphores) |
| 5083 | |
| 5084 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5085 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5086 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5087 | |
| 5088 | def test_semaphore_tenant_isolation(self): |
| 5089 | "Test semaphores in multiple tenants" |
| 5090 | |
| 5091 | self.waitUntilSettled() |
| 5092 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5093 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5094 | |
| 5095 | self.executor_server.hold_jobs_in_build = True |
| 5096 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5097 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5098 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5099 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5100 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5101 | self.assertFalse('test-semaphore' in |
| 5102 | tenant_one.semaphore_handler.semaphores) |
| 5103 | self.assertFalse('test-semaphore' in |
| 5104 | tenant_two.semaphore_handler.semaphores) |
| 5105 | |
| 5106 | # add patches to project1 of tenant-one |
| 5107 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5108 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5109 | self.waitUntilSettled() |
| 5110 | |
| 5111 | # one build of project1-test1 must run |
| 5112 | # semaphore of tenant-one must be acquired once |
| 5113 | # semaphore of tenant-two must not be acquired |
| 5114 | self.assertEqual(len(self.builds), 1) |
| 5115 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5116 | self.assertTrue('test-semaphore' in |
| 5117 | tenant_one.semaphore_handler.semaphores) |
| 5118 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5119 | 'test-semaphore', [])), 1) |
| 5120 | self.assertFalse('test-semaphore' in |
| 5121 | tenant_two.semaphore_handler.semaphores) |
| 5122 | |
| 5123 | # add patches to project2 of tenant-two |
| 5124 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5125 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5126 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5127 | self.waitUntilSettled() |
| 5128 | |
| 5129 | # one build of project1-test1 must run |
| 5130 | # two builds of project2-test1 must run |
| 5131 | # semaphore of tenant-one must be acquired once |
| 5132 | # semaphore of tenant-two must be acquired twice |
| 5133 | self.assertEqual(len(self.builds), 3) |
| 5134 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5135 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5136 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5137 | self.assertTrue('test-semaphore' in |
| 5138 | tenant_one.semaphore_handler.semaphores) |
| 5139 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5140 | 'test-semaphore', [])), 1) |
| 5141 | self.assertTrue('test-semaphore' in |
| 5142 | tenant_two.semaphore_handler.semaphores) |
| 5143 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5144 | 'test-semaphore', [])), 2) |
| 5145 | |
| 5146 | self.executor_server.release('project1-test1') |
| 5147 | self.waitUntilSettled() |
| 5148 | |
| 5149 | # one build of project1-test1 must run |
| 5150 | # two builds of project2-test1 must run |
| 5151 | # semaphore of tenant-one must be acquired once |
| 5152 | # semaphore of tenant-two must be acquired twice |
| 5153 | self.assertEqual(len(self.builds), 3) |
| 5154 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5155 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5156 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5157 | self.assertTrue('test-semaphore' in |
| 5158 | tenant_one.semaphore_handler.semaphores) |
| 5159 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5160 | 'test-semaphore', [])), 1) |
| 5161 | self.assertTrue('test-semaphore' in |
| 5162 | tenant_two.semaphore_handler.semaphores) |
| 5163 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5164 | 'test-semaphore', [])), 2) |
| 5165 | |
| 5166 | self.executor_server.release('project2-test1') |
| 5167 | self.waitUntilSettled() |
| 5168 | |
| 5169 | # one build of project1-test1 must run |
| 5170 | # one build of project2-test1 must run |
| 5171 | # semaphore of tenant-one must be acquired once |
| 5172 | # semaphore of tenant-two must be acquired once |
| 5173 | self.assertEqual(len(self.builds), 2) |
| 5174 | self.assertTrue('test-semaphore' in |
| 5175 | tenant_one.semaphore_handler.semaphores) |
| 5176 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5177 | 'test-semaphore', [])), 1) |
| 5178 | self.assertTrue('test-semaphore' in |
| 5179 | tenant_two.semaphore_handler.semaphores) |
| 5180 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5181 | 'test-semaphore', [])), 1) |
| 5182 | |
| 5183 | self.executor_server.hold_jobs_in_build = False |
| 5184 | self.executor_server.release() |
| 5185 | |
| 5186 | self.waitUntilSettled() |
| 5187 | |
| 5188 | # no build must run |
| 5189 | # semaphore of tenant-one must not be acquired |
| 5190 | # semaphore of tenant-two must not be acquired |
| 5191 | self.assertEqual(len(self.builds), 0) |
| 5192 | self.assertFalse('test-semaphore' in |
| 5193 | tenant_one.semaphore_handler.semaphores) |
| 5194 | self.assertFalse('test-semaphore' in |
| 5195 | tenant_two.semaphore_handler.semaphores) |
| 5196 | |
| 5197 | self.assertEqual(A.reported, 1) |
| 5198 | self.assertEqual(B.reported, 1) |
| 5199 | |
| 5200 | |
| 5201 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5202 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5203 | |
| 5204 | def test_semaphore_in_repo(self): |
| 5205 | "Test semaphores in repo config" |
| 5206 | |
| 5207 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5208 | # max value should not be evaluated dynamically but must be updated |
| 5209 | # after the change lands. |
| 5210 | |
| 5211 | self.waitUntilSettled() |
| 5212 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5213 | |
| 5214 | in_repo_conf = textwrap.dedent( |
| 5215 | """ |
| 5216 | - job: |
| 5217 | name: project-test2 |
| 5218 | semaphore: test-semaphore |
| 5219 | |
| 5220 | - project: |
| 5221 | name: org/project |
| 5222 | tenant-one-gate: |
| 5223 | jobs: |
| 5224 | - project-test2 |
| 5225 | |
| 5226 | # the max value in dynamic layout must be ignored |
| 5227 | - semaphore: |
| 5228 | name: test-semaphore |
| 5229 | max: 2 |
| 5230 | """) |
| 5231 | |
| 5232 | in_repo_playbook = textwrap.dedent( |
| 5233 | """ |
| 5234 | - hosts: all |
| 5235 | tasks: [] |
| 5236 | """) |
| 5237 | |
| 5238 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5239 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5240 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5241 | files=file_dict) |
| 5242 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5243 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5244 | B.setDependsOn(A, 1) |
| 5245 | C.setDependsOn(A, 1) |
| 5246 | |
| 5247 | self.executor_server.hold_jobs_in_build = True |
| 5248 | |
| 5249 | A.addApproval('code-review', 2) |
| 5250 | B.addApproval('code-review', 2) |
| 5251 | C.addApproval('code-review', 2) |
| 5252 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5253 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5254 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5255 | self.waitUntilSettled() |
| 5256 | |
| 5257 | # check that the layout in a queue item still has max value of 1 |
| 5258 | # for test-semaphore |
| 5259 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5260 | queue = None |
| 5261 | for queue_candidate in pipeline.queues: |
| 5262 | if queue_candidate.name == 'org/project': |
| 5263 | queue = queue_candidate |
| 5264 | break |
| 5265 | queue_item = queue.queue[0] |
| 5266 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5267 | dynamic_test_semaphore = \ |
| 5268 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5269 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5270 | |
| 5271 | # one build must be in queue, one semaphores acquired |
| 5272 | self.assertEqual(len(self.builds), 1) |
| 5273 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5274 | self.assertTrue('test-semaphore' in |
| 5275 | tenant.semaphore_handler.semaphores) |
| 5276 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5277 | 'test-semaphore', [])), 1) |
| 5278 | |
| 5279 | self.executor_server.release('project-test2') |
| 5280 | self.waitUntilSettled() |
| 5281 | |
| 5282 | # change A must be merged |
| 5283 | self.assertEqual(A.data['status'], 'MERGED') |
| 5284 | self.assertEqual(A.reported, 2) |
| 5285 | |
| 5286 | # send change-merged event as the gerrit mock doesn't send it |
| 5287 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5288 | self.waitUntilSettled() |
| 5289 | |
| 5290 | # now that change A was merged, the new semaphore max must be effective |
| 5291 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5292 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5293 | |
| 5294 | # two builds must be in queue, two semaphores acquired |
| 5295 | self.assertEqual(len(self.builds), 2) |
| 5296 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5297 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5298 | self.assertTrue('test-semaphore' in |
| 5299 | tenant.semaphore_handler.semaphores) |
| 5300 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5301 | 'test-semaphore', [])), 2) |
| 5302 | |
| 5303 | self.executor_server.release('project-test2') |
| 5304 | self.waitUntilSettled() |
| 5305 | |
| 5306 | self.assertEqual(len(self.builds), 0) |
| 5307 | self.assertFalse('test-semaphore' in |
| 5308 | tenant.semaphore_handler.semaphores) |
| 5309 | |
| 5310 | self.executor_server.hold_jobs_in_build = False |
| 5311 | self.executor_server.release() |
| 5312 | |
| 5313 | self.waitUntilSettled() |
| 5314 | self.assertEqual(len(self.builds), 0) |
| 5315 | |
| 5316 | self.assertEqual(A.reported, 2) |
| 5317 | self.assertEqual(B.reported, 2) |
| 5318 | self.assertEqual(C.reported, 2) |