James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
Monty Taylor | b934c1a | 2017-06-16 19:31:47 -0500 | [diff] [blame] | 29 | import urllib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 35 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 36 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 38 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 39 | ZuulTestCase, |
| 40 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 41 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 42 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 45 | class TestSchedulerSSL(SSLZuulTestCase): |
| 46 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 47 | |
| 48 | def test_jobs_executed(self): |
| 49 | "Test that jobs are executed and a change is merged" |
| 50 | |
| 51 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 52 | A.addApproval('Code-Review', 2) |
| 53 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 54 | self.waitUntilSettled() |
| 55 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 60 | 'SUCCESS') |
| 61 | self.assertEqual(A.data['status'], 'MERGED') |
| 62 | self.assertEqual(A.reported, 2) |
| 63 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 64 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 65 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 66 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 67 | |
| 68 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 69 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 70 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 71 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 72 | def test_jobs_executed(self): |
| 73 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 74 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 75 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 76 | A.addApproval('Code-Review', 2) |
| 77 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 78 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 79 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 80 | 'SUCCESS') |
| 81 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 82 | 'SUCCESS') |
| 83 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 84 | 'SUCCESS') |
| 85 | self.assertEqual(A.data['status'], 'MERGED') |
| 86 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 88 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 89 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 90 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 91 | |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 92 | for stat in self.statsd.stats: |
| 93 | k, v = stat.decode('utf-8').split(':') |
| 94 | self.log.debug('stat %s:%s', k, v) |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 95 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 96 | # Per-driver |
| 97 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 98 | # Per-driver per-connection |
| 99 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 100 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 101 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 102 | 'zuul.tenant.tenant-one.pipeline.gate.current_changes', |
| 103 | value='1|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 104 | self.assertReportedStat( |
James E. Blair | 80ac158 | 2017-10-09 07:02:40 -0700 | [diff] [blame] | 105 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 106 | 'org_project.master.job.project-merge.SUCCESS', kind='ms') |
| 107 | self.assertReportedStat( |
| 108 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 109 | 'org_project.master.job.project-merge.SUCCESS', value='1|c') |
| 110 | self.assertReportedStat( |
| 111 | 'zuul.tenant.tenant-one.pipeline.gate.resident_time', kind='ms') |
| 112 | self.assertReportedStat( |
| 113 | 'zuul.tenant.tenant-one.pipeline.gate.total_changes', value='1|c') |
| 114 | self.assertReportedStat( |
| 115 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 116 | 'org_project.master.resident_time', kind='ms') |
| 117 | self.assertReportedStat( |
| 118 | 'zuul.tenant.tenant-one.pipeline.gate.project.review_example_com.' |
| 119 | 'org_project.master.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 120 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 121 | for build in self.history: |
| 122 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 123 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 124 | def test_initial_pipeline_gauges(self): |
| 125 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 126 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 127 | value='0|g') |
| 128 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 129 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 130 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 131 | def test_job_branch(self): |
| 132 | "Test the correct variant of a job runs on a branch" |
| 133 | self.create_branch('org/project', 'stable') |
| 134 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 135 | A.addApproval('Code-Review', 2) |
| 136 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 137 | self.waitUntilSettled() |
| 138 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 139 | 'SUCCESS') |
| 140 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 141 | 'SUCCESS') |
| 142 | self.assertEqual(A.data['status'], 'MERGED') |
| 143 | self.assertEqual(A.reported, 2, |
| 144 | "A should report start and success") |
| 145 | self.assertIn('gate', A.messages[1], |
| 146 | "A should transit gate") |
| 147 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 148 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 149 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 150 | def test_parallel_changes(self): |
| 151 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 152 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 153 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 154 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 155 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 156 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 157 | A.addApproval('Code-Review', 2) |
| 158 | B.addApproval('Code-Review', 2) |
| 159 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 161 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 162 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 163 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 164 | |
| 165 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(len(self.builds), 1) |
| 167 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 168 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 169 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 170 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 171 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 172 | self.assertEqual(len(self.builds), 3) |
| 173 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 174 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 175 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 176 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 178 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 179 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 180 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(len(self.builds), 5) |
| 183 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 184 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 185 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 186 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 187 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 188 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 189 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 190 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 191 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 192 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 193 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 194 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 195 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 196 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 198 | self.assertEqual(len(self.builds), 6) |
| 199 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 200 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 201 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 202 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 203 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 204 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 205 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 206 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 207 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 208 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 209 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 210 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 211 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 212 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 213 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 214 | self.executor_server.hold_jobs_in_build = False |
| 215 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 216 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 217 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 218 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 219 | self.assertEqual(len(self.history), 9) |
| 220 | self.assertEqual(A.data['status'], 'MERGED') |
| 221 | self.assertEqual(B.data['status'], 'MERGED') |
| 222 | self.assertEqual(C.data['status'], 'MERGED') |
| 223 | self.assertEqual(A.reported, 2) |
| 224 | self.assertEqual(B.reported, 2) |
| 225 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | |
| 227 | def test_failed_changes(self): |
| 228 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 229 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 230 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 231 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 232 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 233 | A.addApproval('Code-Review', 2) |
| 234 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 235 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 236 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 237 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 238 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 239 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 240 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 241 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 242 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 243 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 244 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 245 | # A/project-merge is complete |
| 246 | self.assertBuilds([ |
| 247 | dict(name='project-test1', changes='1,1'), |
| 248 | dict(name='project-test2', changes='1,1'), |
| 249 | dict(name='project-merge', changes='1,1 2,1'), |
| 250 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 251 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 252 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 253 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 254 | # A/project-merge is complete |
| 255 | # B/project-merge is complete |
| 256 | self.assertBuilds([ |
| 257 | dict(name='project-test1', changes='1,1'), |
| 258 | dict(name='project-test2', changes='1,1'), |
| 259 | dict(name='project-test1', changes='1,1 2,1'), |
| 260 | dict(name='project-test2', changes='1,1 2,1'), |
| 261 | ]) |
| 262 | |
| 263 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 264 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 265 | self.builds[0].release() |
| 266 | self.waitUntilSettled() |
| 267 | |
| 268 | self.orderedRelease() |
| 269 | self.assertHistory([ |
| 270 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 271 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 272 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 273 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 274 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 275 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 276 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 277 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 278 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 279 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 280 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 281 | self.assertEqual(A.data['status'], 'NEW') |
| 282 | self.assertEqual(B.data['status'], 'MERGED') |
| 283 | self.assertEqual(A.reported, 2) |
| 284 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 285 | |
| 286 | def test_independent_queues(self): |
| 287 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 288 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 289 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 290 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 291 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 292 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 293 | A.addApproval('Code-Review', 2) |
| 294 | B.addApproval('Code-Review', 2) |
| 295 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 296 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 297 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 298 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 299 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 300 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 301 | self.waitUntilSettled() |
| 302 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 303 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 304 | self.waitUntilSettled() |
| 305 | |
| 306 | # 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] | 307 | self.assertBuilds([ |
| 308 | dict(name='project-merge', changes='1,1'), |
| 309 | dict(name='project-merge', changes='2,1'), |
| 310 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 311 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 312 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 313 | self.builds[0].release() |
| 314 | self.waitUntilSettled() |
| 315 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 316 | self.waitUntilSettled() |
| 317 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 318 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 319 | self.waitUntilSettled() |
| 320 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 321 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 322 | self.assertBuilds([ |
| 323 | dict(name='project-test1', changes='1,1'), |
| 324 | dict(name='project-test2', changes='1,1'), |
| 325 | dict(name='project-test1', changes='2,1'), |
| 326 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 327 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 328 | dict(name='project-test1', changes='2,1 3,1'), |
| 329 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 330 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 331 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 332 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 333 | self.orderedRelease() |
| 334 | self.assertHistory([ |
| 335 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 336 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 337 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 338 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 339 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 340 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 341 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 342 | dict( |
| 343 | name='project1-project2-integration', |
| 344 | result='SUCCESS', |
| 345 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 346 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 347 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 348 | dict(name='project1-project2-integration', |
| 349 | result='SUCCESS', |
| 350 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 351 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 352 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 353 | self.assertEqual(A.data['status'], 'MERGED') |
| 354 | self.assertEqual(B.data['status'], 'MERGED') |
| 355 | self.assertEqual(C.data['status'], 'MERGED') |
| 356 | self.assertEqual(A.reported, 2) |
| 357 | self.assertEqual(B.reported, 2) |
| 358 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 359 | |
| 360 | def test_failed_change_at_head(self): |
| 361 | "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] | 362 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 363 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 364 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 365 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 366 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 367 | A.addApproval('Code-Review', 2) |
| 368 | B.addApproval('Code-Review', 2) |
| 369 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 370 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 371 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 372 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 373 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 374 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 375 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 376 | |
| 377 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 378 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 379 | self.assertBuilds([ |
| 380 | dict(name='project-merge', changes='1,1'), |
| 381 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 382 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 383 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 384 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 385 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 386 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 387 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 388 | self.waitUntilSettled() |
| 389 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 390 | self.assertBuilds([ |
| 391 | dict(name='project-test1', changes='1,1'), |
| 392 | dict(name='project-test2', changes='1,1'), |
| 393 | dict(name='project-test1', changes='1,1 2,1'), |
| 394 | dict(name='project-test2', changes='1,1 2,1'), |
| 395 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 396 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 397 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 398 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 399 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 400 | self.waitUntilSettled() |
| 401 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 402 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 403 | self.assertBuilds([ |
| 404 | dict(name='project-test2', changes='1,1'), |
| 405 | dict(name='project-merge', changes='2,1'), |
| 406 | ]) |
| 407 | # Unordered history comparison because the aborts can finish |
| 408 | # in any order. |
| 409 | self.assertHistory([ |
| 410 | dict(name='project-merge', result='SUCCESS', |
| 411 | changes='1,1'), |
| 412 | dict(name='project-merge', result='SUCCESS', |
| 413 | changes='1,1 2,1'), |
| 414 | dict(name='project-merge', result='SUCCESS', |
| 415 | changes='1,1 2,1 3,1'), |
| 416 | dict(name='project-test1', result='FAILURE', |
| 417 | changes='1,1'), |
| 418 | dict(name='project-test1', result='ABORTED', |
| 419 | changes='1,1 2,1'), |
| 420 | dict(name='project-test2', result='ABORTED', |
| 421 | changes='1,1 2,1'), |
| 422 | dict(name='project-test1', result='ABORTED', |
| 423 | changes='1,1 2,1 3,1'), |
| 424 | dict(name='project-test2', result='ABORTED', |
| 425 | changes='1,1 2,1 3,1'), |
| 426 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 427 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 428 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 429 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 430 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 431 | self.waitUntilSettled() |
| 432 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 433 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 434 | self.assertBuilds([]) |
| 435 | self.assertHistory([ |
| 436 | dict(name='project-merge', result='SUCCESS', |
| 437 | changes='1,1'), |
| 438 | dict(name='project-merge', result='SUCCESS', |
| 439 | changes='1,1 2,1'), |
| 440 | dict(name='project-merge', result='SUCCESS', |
| 441 | changes='1,1 2,1 3,1'), |
| 442 | dict(name='project-test1', result='FAILURE', |
| 443 | changes='1,1'), |
| 444 | dict(name='project-test1', result='ABORTED', |
| 445 | changes='1,1 2,1'), |
| 446 | dict(name='project-test2', result='ABORTED', |
| 447 | changes='1,1 2,1'), |
| 448 | dict(name='project-test1', result='ABORTED', |
| 449 | changes='1,1 2,1 3,1'), |
| 450 | dict(name='project-test2', result='ABORTED', |
| 451 | changes='1,1 2,1 3,1'), |
| 452 | dict(name='project-merge', result='SUCCESS', |
| 453 | changes='2,1'), |
| 454 | dict(name='project-merge', result='SUCCESS', |
| 455 | changes='2,1 3,1'), |
| 456 | dict(name='project-test2', result='SUCCESS', |
| 457 | changes='1,1'), |
| 458 | dict(name='project-test1', result='SUCCESS', |
| 459 | changes='2,1'), |
| 460 | dict(name='project-test2', result='SUCCESS', |
| 461 | changes='2,1'), |
| 462 | dict(name='project-test1', result='SUCCESS', |
| 463 | changes='2,1 3,1'), |
| 464 | dict(name='project-test2', result='SUCCESS', |
| 465 | changes='2,1 3,1'), |
| 466 | ], ordered=False) |
| 467 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 468 | self.assertEqual(A.data['status'], 'NEW') |
| 469 | self.assertEqual(B.data['status'], 'MERGED') |
| 470 | self.assertEqual(C.data['status'], 'MERGED') |
| 471 | self.assertEqual(A.reported, 2) |
| 472 | self.assertEqual(B.reported, 2) |
| 473 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 474 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 475 | def test_failed_change_in_middle(self): |
| 476 | "Test a failed change in the middle of the queue" |
| 477 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 478 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 479 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 480 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 481 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 482 | A.addApproval('Code-Review', 2) |
| 483 | B.addApproval('Code-Review', 2) |
| 484 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 485 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 486 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 487 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 488 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 489 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 490 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 491 | |
| 492 | self.waitUntilSettled() |
| 493 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 494 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 495 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 496 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 497 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 498 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 499 | self.waitUntilSettled() |
| 500 | |
| 501 | self.assertEqual(len(self.builds), 6) |
| 502 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 503 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 504 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 505 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 506 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 507 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 508 | |
| 509 | self.release(self.builds[2]) |
| 510 | self.waitUntilSettled() |
| 511 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 512 | # project-test1 and project-test2 for A |
| 513 | # project-test2 for B |
| 514 | # project-merge for C (without B) |
| 515 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 516 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 517 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 518 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 519 | self.waitUntilSettled() |
| 520 | |
| 521 | # project-test1 and project-test2 for A |
| 522 | # project-test2 for B |
| 523 | # project-test1 and project-test2 for C |
| 524 | self.assertEqual(len(self.builds), 5) |
| 525 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 526 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 527 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 528 | builds = items[0].current_build_set.getBuilds() |
| 529 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 530 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 531 | builds = items[1].current_build_set.getBuilds() |
| 532 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 533 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 534 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 535 | builds = items[2].current_build_set.getBuilds() |
| 536 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 537 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 538 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 539 | self.executor_server.hold_jobs_in_build = False |
| 540 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 541 | self.waitUntilSettled() |
| 542 | |
| 543 | self.assertEqual(len(self.builds), 0) |
| 544 | self.assertEqual(len(self.history), 12) |
| 545 | self.assertEqual(A.data['status'], 'MERGED') |
| 546 | self.assertEqual(B.data['status'], 'NEW') |
| 547 | self.assertEqual(C.data['status'], 'MERGED') |
| 548 | self.assertEqual(A.reported, 2) |
| 549 | self.assertEqual(B.reported, 2) |
| 550 | self.assertEqual(C.reported, 2) |
| 551 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 552 | def test_failed_change_at_head_with_queue(self): |
| 553 | "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] | 554 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 555 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 556 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 557 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 558 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 559 | A.addApproval('Code-Review', 2) |
| 560 | B.addApproval('Code-Review', 2) |
| 561 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 562 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 563 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 564 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 565 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 566 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 567 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 568 | |
| 569 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 570 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 571 | self.assertEqual(len(self.builds), 0) |
| 572 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 573 | self.assertEqual(queue[0].name, b'executor:execute') |
| 574 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 575 | self.assertEqual(job_args['job'], 'project-merge') |
| 576 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
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.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 579 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 580 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 581 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 582 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 583 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 584 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 585 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 586 | self.assertEqual(len(self.builds), 0) |
| 587 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 588 | |
| 589 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 590 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 591 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 592 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 593 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 594 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 595 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 596 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 597 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 598 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 599 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 600 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 601 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 602 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 603 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 604 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 605 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 606 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 607 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 608 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 609 | self.waitUntilSettled() |
| 610 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 611 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 612 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 613 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 614 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 615 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 616 | self.gearman_server.hold_jobs_in_queue = False |
| 617 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 618 | self.waitUntilSettled() |
| 619 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 620 | self.assertEqual(len(self.builds), 0) |
| 621 | self.assertEqual(len(self.history), 11) |
| 622 | self.assertEqual(A.data['status'], 'NEW') |
| 623 | self.assertEqual(B.data['status'], 'MERGED') |
| 624 | self.assertEqual(C.data['status'], 'MERGED') |
| 625 | self.assertEqual(A.reported, 2) |
| 626 | self.assertEqual(B.reported, 2) |
| 627 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 628 | |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 629 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 630 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 631 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 632 | A.addApproval('Code-Review', 2) |
| 633 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 634 | self.waitUntilSettled() |
| 635 | time.sleep(2) |
| 636 | |
James E. Blair | ae0f23c | 2017-09-13 10:55:15 -0600 | [diff] [blame] | 637 | data = json.loads(self.sched.formatStatusJSON('tenant-one')) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 638 | found_job = None |
| 639 | for pipeline in data['pipelines']: |
| 640 | if pipeline['name'] != 'gate': |
| 641 | continue |
| 642 | for queue in pipeline['change_queues']: |
| 643 | for head in queue['heads']: |
| 644 | for item in head: |
| 645 | for job in item['jobs']: |
| 646 | if job['name'] == 'project-merge': |
| 647 | found_job = job |
| 648 | break |
| 649 | |
| 650 | self.assertIsNotNone(found_job) |
| 651 | if iteration == 1: |
| 652 | self.assertIsNotNone(found_job['estimated_time']) |
| 653 | self.assertIsNone(found_job['remaining_time']) |
| 654 | else: |
| 655 | self.assertIsNotNone(found_job['estimated_time']) |
| 656 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 657 | self.assertIsNotNone(found_job['remaining_time']) |
| 658 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 659 | self.executor_server.hold_jobs_in_build = False |
| 660 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 661 | self.waitUntilSettled() |
| 662 | |
| 663 | def test_time_database(self): |
| 664 | "Test the time database" |
| 665 | |
| 666 | self._test_time_database(1) |
| 667 | self._test_time_database(2) |
| 668 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 669 | def test_two_failed_changes_at_head(self): |
| 670 | "Test that changes are reparented correctly if 2 fail at head" |
| 671 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 672 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 673 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 674 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 675 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 676 | A.addApproval('Code-Review', 2) |
| 677 | B.addApproval('Code-Review', 2) |
| 678 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 680 | self.executor_server.failJob('project-test1', A) |
| 681 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 683 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 684 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 685 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 686 | self.waitUntilSettled() |
| 687 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 688 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 689 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 690 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 691 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 692 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 693 | self.waitUntilSettled() |
| 694 | |
| 695 | self.assertEqual(len(self.builds), 6) |
| 696 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 697 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 698 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 699 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 700 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 701 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 702 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 703 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 704 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 705 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 706 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 707 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 708 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 709 | |
| 710 | # Fail change B first |
| 711 | self.release(self.builds[2]) |
| 712 | self.waitUntilSettled() |
| 713 | |
| 714 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 715 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 716 | self.waitUntilSettled() |
| 717 | |
| 718 | self.assertEqual(len(self.builds), 5) |
| 719 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 720 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 721 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 722 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 723 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 724 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 725 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 726 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 727 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 728 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 729 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 730 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 731 | |
| 732 | # Finish running all passing jobs for change A |
| 733 | self.release(self.builds[1]) |
| 734 | self.waitUntilSettled() |
| 735 | # Fail and report change A |
| 736 | self.release(self.builds[0]) |
| 737 | self.waitUntilSettled() |
| 738 | |
| 739 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 740 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 741 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 742 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 743 | self.waitUntilSettled() |
| 744 | |
| 745 | self.assertEqual(len(self.builds), 4) |
| 746 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 747 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 748 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 749 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 750 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 751 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 752 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 753 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 754 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 755 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 756 | # After A failed and B and C restarted, B should be back in |
| 757 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 758 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 759 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 760 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 761 | self.executor_server.hold_jobs_in_build = False |
| 762 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 763 | self.waitUntilSettled() |
| 764 | |
| 765 | self.assertEqual(len(self.builds), 0) |
| 766 | self.assertEqual(len(self.history), 21) |
| 767 | self.assertEqual(A.data['status'], 'NEW') |
| 768 | self.assertEqual(B.data['status'], 'NEW') |
| 769 | self.assertEqual(C.data['status'], 'MERGED') |
| 770 | self.assertEqual(A.reported, 2) |
| 771 | self.assertEqual(B.reported, 2) |
| 772 | self.assertEqual(C.reported, 2) |
| 773 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 774 | def test_patch_order(self): |
| 775 | "Test that dependent patches are tested in the right order" |
| 776 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 777 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 778 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 779 | A.addApproval('Code-Review', 2) |
| 780 | B.addApproval('Code-Review', 2) |
| 781 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 782 | |
| 783 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 784 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 785 | M2.setMerged() |
| 786 | M1.setMerged() |
| 787 | |
| 788 | # C -> B -> A -> M1 -> M2 |
| 789 | # M2 is here to make sure it is never queried. If it is, it |
| 790 | # means zuul is walking down the entire history of merged |
| 791 | # changes. |
| 792 | |
| 793 | C.setDependsOn(B, 1) |
| 794 | B.setDependsOn(A, 1) |
| 795 | A.setDependsOn(M1, 1) |
| 796 | M1.setDependsOn(M2, 1) |
| 797 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 798 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 799 | |
| 800 | self.waitUntilSettled() |
| 801 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 802 | self.assertEqual(A.data['status'], 'NEW') |
| 803 | self.assertEqual(B.data['status'], 'NEW') |
| 804 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 805 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 806 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 807 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 808 | |
| 809 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 810 | self.assertEqual(M2.queried, 0) |
| 811 | self.assertEqual(A.data['status'], 'MERGED') |
| 812 | self.assertEqual(B.data['status'], 'MERGED') |
| 813 | self.assertEqual(C.data['status'], 'MERGED') |
| 814 | self.assertEqual(A.reported, 2) |
| 815 | self.assertEqual(B.reported, 2) |
| 816 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 817 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 818 | def test_needed_changes_enqueue(self): |
| 819 | "Test that a needed change is enqueued ahead" |
| 820 | # A Given a git tree like this, if we enqueue |
| 821 | # / \ change C, we should walk up and down the tree |
| 822 | # B G and enqueue changes in the order ABCDEFG. |
| 823 | # /|\ This is also the order that you would get if |
| 824 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 825 | # / the ordering is stable across re-enqueue events. |
| 826 | # D |
| 827 | |
| 828 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 829 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 830 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 831 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 832 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 833 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 834 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 835 | B.setDependsOn(A, 1) |
| 836 | C.setDependsOn(B, 1) |
| 837 | D.setDependsOn(C, 1) |
| 838 | E.setDependsOn(B, 1) |
| 839 | F.setDependsOn(B, 1) |
| 840 | G.setDependsOn(A, 1) |
| 841 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 842 | A.addApproval('Code-Review', 2) |
| 843 | B.addApproval('Code-Review', 2) |
| 844 | C.addApproval('Code-Review', 2) |
| 845 | D.addApproval('Code-Review', 2) |
| 846 | E.addApproval('Code-Review', 2) |
| 847 | F.addApproval('Code-Review', 2) |
| 848 | G.addApproval('Code-Review', 2) |
| 849 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 850 | |
| 851 | self.waitUntilSettled() |
| 852 | |
| 853 | self.assertEqual(A.data['status'], 'NEW') |
| 854 | self.assertEqual(B.data['status'], 'NEW') |
| 855 | self.assertEqual(C.data['status'], 'NEW') |
| 856 | self.assertEqual(D.data['status'], 'NEW') |
| 857 | self.assertEqual(E.data['status'], 'NEW') |
| 858 | self.assertEqual(F.data['status'], 'NEW') |
| 859 | self.assertEqual(G.data['status'], 'NEW') |
| 860 | |
| 861 | # We're about to add approvals to changes without adding the |
| 862 | # triggering events to Zuul, so that we can be sure that it is |
| 863 | # enqueing the changes based on dependencies, not because of |
| 864 | # triggering events. Since it will have the changes cached |
| 865 | # already (without approvals), we need to clear the cache |
| 866 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 867 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 868 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 869 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 870 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 871 | A.addApproval('Approved', 1) |
| 872 | B.addApproval('Approved', 1) |
| 873 | D.addApproval('Approved', 1) |
| 874 | E.addApproval('Approved', 1) |
| 875 | F.addApproval('Approved', 1) |
| 876 | G.addApproval('Approved', 1) |
| 877 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 878 | |
| 879 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 880 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 881 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 882 | self.executor_server.hold_jobs_in_build = False |
| 883 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 884 | self.waitUntilSettled() |
| 885 | |
| 886 | self.assertEqual(A.data['status'], 'MERGED') |
| 887 | self.assertEqual(B.data['status'], 'MERGED') |
| 888 | self.assertEqual(C.data['status'], 'MERGED') |
| 889 | self.assertEqual(D.data['status'], 'MERGED') |
| 890 | self.assertEqual(E.data['status'], 'MERGED') |
| 891 | self.assertEqual(F.data['status'], 'MERGED') |
| 892 | self.assertEqual(G.data['status'], 'MERGED') |
| 893 | self.assertEqual(A.reported, 2) |
| 894 | self.assertEqual(B.reported, 2) |
| 895 | self.assertEqual(C.reported, 2) |
| 896 | self.assertEqual(D.reported, 2) |
| 897 | self.assertEqual(E.reported, 2) |
| 898 | self.assertEqual(F.reported, 2) |
| 899 | self.assertEqual(G.reported, 2) |
| 900 | self.assertEqual(self.history[6].changes, |
| 901 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 902 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 903 | def test_source_cache(self): |
| 904 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 905 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 906 | |
| 907 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 908 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 909 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 910 | A.addApproval('Code-Review', 2) |
| 911 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 912 | |
| 913 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 914 | M1.setMerged() |
| 915 | |
| 916 | B.setDependsOn(A, 1) |
| 917 | A.setDependsOn(M1, 1) |
| 918 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 919 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 920 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 921 | |
| 922 | self.waitUntilSettled() |
| 923 | |
| 924 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 925 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 926 | build.release() |
| 927 | self.waitUntilSettled() |
| 928 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 929 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 930 | build.release() |
| 931 | self.waitUntilSettled() |
| 932 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 933 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 934 | self.waitUntilSettled() |
| 935 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 936 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 937 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 938 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 939 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 940 | self.executor_server.hold_jobs_in_build = False |
| 941 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 942 | self.waitUntilSettled() |
| 943 | |
| 944 | self.assertEqual(A.data['status'], 'MERGED') |
| 945 | self.assertEqual(B.data['status'], 'MERGED') |
| 946 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 947 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 948 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 949 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 950 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 951 | # TODO: move to test_gerrit (this is a unit test!) |
| 952 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 953 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 954 | (trusted, project) = tenant.getProject('org/project') |
| 955 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 956 | |
| 957 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 958 | # it easier for users to create events for testing. |
| 959 | event = zuul.model.TriggerEvent() |
| 960 | event.trigger_name = 'gerrit' |
| 961 | event.change_number = '1' |
| 962 | event.patch_number = '2' |
| 963 | |
| 964 | a = source.getChange(event) |
| 965 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 966 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 967 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 968 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 969 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 970 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 971 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 972 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 973 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 974 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 975 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 976 | def test_project_merge_conflict(self): |
| 977 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 978 | |
| 979 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 980 | A = self.fake_gerrit.addFakeChange('org/project', |
| 981 | 'master', 'A', |
| 982 | files={'conflict': 'foo'}) |
| 983 | B = self.fake_gerrit.addFakeChange('org/project', |
| 984 | 'master', 'B', |
| 985 | files={'conflict': 'bar'}) |
| 986 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 987 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 988 | A.addApproval('Code-Review', 2) |
| 989 | B.addApproval('Code-Review', 2) |
| 990 | C.addApproval('Code-Review', 2) |
| 991 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 992 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 993 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 994 | self.waitUntilSettled() |
| 995 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 996 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 997 | self.assertEqual(C.reported, 1) |
| 998 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 999 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1000 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1001 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1002 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1003 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1004 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1005 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1006 | self.gearman_server.hold_jobs_in_queue = False |
| 1007 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1008 | self.waitUntilSettled() |
| 1009 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1010 | self.assertEqual(A.data['status'], 'MERGED') |
| 1011 | self.assertEqual(B.data['status'], 'NEW') |
| 1012 | self.assertEqual(C.data['status'], 'MERGED') |
| 1013 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1014 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1015 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1016 | |
| 1017 | self.assertHistory([ |
| 1018 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1019 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1020 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1021 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1022 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1023 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1024 | ], ordered=False) |
| 1025 | |
| 1026 | def test_delayed_merge_conflict(self): |
| 1027 | "Test that delayed check merge conflicts are handled properly" |
| 1028 | |
| 1029 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1030 | # the executor sucesfully merges a change based on an old |
| 1031 | # repo state (frozen by the scheduler) which would otherwise |
| 1032 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1033 | self.gearman_server.hold_jobs_in_queue = True |
| 1034 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1035 | 'master', 'A', |
| 1036 | files={'conflict': 'foo'}) |
| 1037 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1038 | 'master', 'B', |
| 1039 | files={'conflict': 'bar'}) |
| 1040 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1041 | 'master', 'C') |
| 1042 | C.setDependsOn(B, 1) |
| 1043 | |
| 1044 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1045 | A.addApproval('Code-Review', 2) |
| 1046 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1047 | self.waitUntilSettled() |
| 1048 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1049 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1050 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1051 | self.waitUntilSettled() |
| 1052 | |
| 1053 | self.assertEqual(A.reported, 1) |
| 1054 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1055 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1056 | |
| 1057 | # A merges while B and C are queued in check |
| 1058 | # Release A project-merge |
| 1059 | queue = self.gearman_server.getQueue() |
| 1060 | self.release(queue[0]) |
| 1061 | self.waitUntilSettled() |
| 1062 | |
| 1063 | # Release A project-test* |
| 1064 | # gate has higher precedence, so A's test jobs are added in |
| 1065 | # front of the merge jobs for B and C |
| 1066 | queue = self.gearman_server.getQueue() |
| 1067 | self.release(queue[0]) |
| 1068 | self.release(queue[1]) |
| 1069 | self.waitUntilSettled() |
| 1070 | |
| 1071 | self.assertEqual(A.data['status'], 'MERGED') |
| 1072 | self.assertEqual(B.data['status'], 'NEW') |
| 1073 | self.assertEqual(C.data['status'], 'NEW') |
| 1074 | self.assertEqual(A.reported, 2) |
| 1075 | self.assertEqual(B.reported, 0) |
| 1076 | self.assertEqual(C.reported, 0) |
| 1077 | self.assertHistory([ |
| 1078 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1079 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1080 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1081 | ], ordered=False) |
| 1082 | |
| 1083 | # B and C report merge conflicts |
| 1084 | # Release B project-merge |
| 1085 | queue = self.gearman_server.getQueue() |
| 1086 | self.release(queue[0]) |
| 1087 | self.waitUntilSettled() |
| 1088 | |
| 1089 | # Release C |
| 1090 | self.gearman_server.hold_jobs_in_queue = False |
| 1091 | self.gearman_server.release() |
| 1092 | self.waitUntilSettled() |
| 1093 | |
| 1094 | self.assertEqual(A.data['status'], 'MERGED') |
| 1095 | self.assertEqual(B.data['status'], 'NEW') |
| 1096 | self.assertEqual(C.data['status'], 'NEW') |
| 1097 | self.assertEqual(A.reported, 2) |
| 1098 | self.assertEqual(B.reported, 1) |
| 1099 | self.assertEqual(C.reported, 1) |
| 1100 | |
| 1101 | self.assertHistory([ |
| 1102 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1103 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1104 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1105 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1106 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1107 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1108 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1109 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1110 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1111 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1112 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1113 | def test_post(self): |
| 1114 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1115 | p = "review.example.com/org/project" |
| 1116 | upstream = self.getUpstreamRepos([p]) |
| 1117 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1118 | A.setMerged() |
| 1119 | A_commit = str(upstream[p].commit('master')) |
| 1120 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1121 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1122 | e = { |
| 1123 | "type": "ref-updated", |
| 1124 | "submitter": { |
| 1125 | "name": "User Name", |
| 1126 | }, |
| 1127 | "refUpdate": { |
| 1128 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1129 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1130 | "refName": "master", |
| 1131 | "project": "org/project", |
| 1132 | } |
| 1133 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1134 | self.fake_gerrit.addEvent(e) |
| 1135 | self.waitUntilSettled() |
| 1136 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1137 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1138 | self.assertEqual(len(self.history), 1) |
| 1139 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1140 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1141 | def test_post_ignore_deletes(self): |
| 1142 | "Test that deleting refs does not trigger post jobs" |
| 1143 | |
| 1144 | e = { |
| 1145 | "type": "ref-updated", |
| 1146 | "submitter": { |
| 1147 | "name": "User Name", |
| 1148 | }, |
| 1149 | "refUpdate": { |
| 1150 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1151 | "newRev": "0000000000000000000000000000000000000000", |
| 1152 | "refName": "master", |
| 1153 | "project": "org/project", |
| 1154 | } |
| 1155 | } |
| 1156 | self.fake_gerrit.addEvent(e) |
| 1157 | self.waitUntilSettled() |
| 1158 | |
| 1159 | job_names = [x.name for x in self.history] |
| 1160 | self.assertEqual(len(self.history), 0) |
| 1161 | self.assertNotIn('project-post', job_names) |
| 1162 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1163 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1164 | def test_post_ignore_deletes_negative(self): |
| 1165 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1166 | e = { |
| 1167 | "type": "ref-updated", |
| 1168 | "submitter": { |
| 1169 | "name": "User Name", |
| 1170 | }, |
| 1171 | "refUpdate": { |
| 1172 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1173 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1174 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1175 | "project": "org/project", |
| 1176 | } |
| 1177 | } |
| 1178 | self.fake_gerrit.addEvent(e) |
| 1179 | self.waitUntilSettled() |
| 1180 | |
| 1181 | job_names = [x.name for x in self.history] |
| 1182 | self.assertEqual(len(self.history), 1) |
| 1183 | self.assertIn('project-post', job_names) |
| 1184 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1185 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1186 | def test_build_configuration_branch_interaction(self): |
| 1187 | "Test that switching between branches works" |
| 1188 | self.test_build_configuration() |
| 1189 | self.test_build_configuration_branch() |
| 1190 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1191 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1192 | repo = git.Repo(path) |
| 1193 | repo.heads.master.commit = repo.commit('init') |
| 1194 | self.test_build_configuration() |
| 1195 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1196 | def test_dependent_changes_rebase(self): |
| 1197 | # Test that no errors occur when we walk a dependency tree |
| 1198 | # with an unused leaf node due to a rebase. |
| 1199 | # Start by constructing: C -> B -> A |
| 1200 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1201 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1202 | B.setDependsOn(A, 1) |
| 1203 | |
| 1204 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1205 | C.setDependsOn(B, 1) |
| 1206 | |
| 1207 | # Then rebase to form: D -> C -> A |
| 1208 | C.addPatchset() # C,2 |
| 1209 | C.setDependsOn(A, 1) |
| 1210 | |
| 1211 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1212 | D.setDependsOn(C, 2) |
| 1213 | |
| 1214 | # Walk the entire tree |
| 1215 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1216 | self.waitUntilSettled() |
| 1217 | self.assertEqual(len(self.history), 3) |
| 1218 | |
| 1219 | # Verify that walking just part of the tree still works |
| 1220 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1221 | self.waitUntilSettled() |
| 1222 | self.assertEqual(len(self.history), 6) |
| 1223 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1224 | def test_dependent_changes_dequeue(self): |
| 1225 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1226 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1227 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1228 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1229 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1230 | A.addApproval('Code-Review', 2) |
| 1231 | B.addApproval('Code-Review', 2) |
| 1232 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1233 | |
| 1234 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1235 | M1.setMerged() |
| 1236 | |
| 1237 | # C -> B -> A -> M1 |
| 1238 | |
| 1239 | C.setDependsOn(B, 1) |
| 1240 | B.setDependsOn(A, 1) |
| 1241 | A.setDependsOn(M1, 1) |
| 1242 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1243 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1244 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1245 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1246 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1247 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1248 | |
| 1249 | self.waitUntilSettled() |
| 1250 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1251 | self.assertEqual(A.data['status'], 'NEW') |
| 1252 | self.assertEqual(A.reported, 2) |
| 1253 | self.assertEqual(B.data['status'], 'NEW') |
| 1254 | self.assertEqual(B.reported, 2) |
| 1255 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1256 | self.assertIn('This change depends on a change that failed to merge.', |
| 1257 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1258 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1259 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1260 | def test_failing_dependent_changes(self): |
| 1261 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1262 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1263 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1264 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1265 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1266 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1267 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1268 | A.addApproval('Code-Review', 2) |
| 1269 | B.addApproval('Code-Review', 2) |
| 1270 | C.addApproval('Code-Review', 2) |
| 1271 | D.addApproval('Code-Review', 2) |
| 1272 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1273 | |
| 1274 | # E, D -> C -> B, A |
| 1275 | |
| 1276 | D.setDependsOn(C, 1) |
| 1277 | C.setDependsOn(B, 1) |
| 1278 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1279 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1280 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1281 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1282 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1283 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1284 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1285 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1286 | |
| 1287 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1288 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1289 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1290 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1291 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1292 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1293 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1294 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1295 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1296 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1297 | self.waitUntilSettled() |
| 1298 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1299 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1300 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1301 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1302 | build.release() |
| 1303 | self.waitUntilSettled() |
| 1304 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1305 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1306 | self.waitUntilSettled() |
| 1307 | |
| 1308 | self.assertEqual(A.data['status'], 'MERGED') |
| 1309 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1310 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1311 | self.assertEqual(B.data['status'], 'NEW') |
| 1312 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1313 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1314 | self.assertEqual(C.data['status'], 'NEW') |
| 1315 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1316 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1317 | self.assertEqual(D.data['status'], 'NEW') |
| 1318 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1319 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1320 | self.assertEqual(E.data['status'], 'MERGED') |
| 1321 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1322 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1323 | self.assertEqual(len(self.history), 18) |
| 1324 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1325 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1326 | "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] | 1327 | # If it's dequeued more than once, we should see extra |
| 1328 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1329 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1330 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1331 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1332 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1333 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1334 | A.addApproval('Code-Review', 2) |
| 1335 | B.addApproval('Code-Review', 2) |
| 1336 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1338 | self.executor_server.failJob('project-test1', A) |
| 1339 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1340 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1341 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1342 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1343 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1344 | |
| 1345 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1346 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1347 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1348 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1349 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1350 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1351 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1352 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1353 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1354 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1355 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | self.waitUntilSettled() |
| 1357 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1358 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1359 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1360 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1361 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1362 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1363 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1364 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1365 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1366 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1367 | self.waitUntilSettled() |
| 1368 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1369 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1370 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1371 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1372 | self.executor_server.hold_jobs_in_build = False |
| 1373 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1374 | self.waitUntilSettled() |
| 1375 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1376 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1377 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1378 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1379 | self.assertEqual(A.data['status'], 'NEW') |
| 1380 | self.assertEqual(B.data['status'], 'MERGED') |
| 1381 | self.assertEqual(C.data['status'], 'MERGED') |
| 1382 | self.assertEqual(A.reported, 2) |
| 1383 | self.assertEqual(B.reported, 2) |
| 1384 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1385 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1386 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1387 | def test_nonvoting_job(self): |
| 1388 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1389 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1390 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1391 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1392 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1393 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1394 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1395 | |
| 1396 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1397 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1398 | self.assertEqual(A.data['status'], 'MERGED') |
| 1399 | self.assertEqual(A.reported, 2) |
| 1400 | self.assertEqual( |
| 1401 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1402 | 'SUCCESS') |
| 1403 | self.assertEqual( |
| 1404 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1405 | 'SUCCESS') |
| 1406 | self.assertEqual( |
| 1407 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1408 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1409 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1410 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1411 | parameters['zuul']['voting']) |
| 1412 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1413 | parameters['zuul']['voting']) |
| 1414 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1415 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1416 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1417 | def test_check_queue_success(self): |
| 1418 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1419 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1420 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1421 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1422 | |
| 1423 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1424 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1425 | self.assertEqual(A.data['status'], 'NEW') |
| 1426 | self.assertEqual(A.reported, 1) |
| 1427 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1428 | 'SUCCESS') |
| 1429 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1430 | 'SUCCESS') |
| 1431 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1432 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1433 | |
| 1434 | def test_check_queue_failure(self): |
| 1435 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1436 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1437 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1438 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1439 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1440 | |
| 1441 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1442 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1443 | self.assertEqual(A.data['status'], 'NEW') |
| 1444 | self.assertEqual(A.reported, 1) |
| 1445 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1446 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1447 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1448 | 'SUCCESS') |
| 1449 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1450 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1451 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1452 | @simple_layout('layouts/autohold.yaml') |
| 1453 | def test_autohold(self): |
| 1454 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1455 | |
| 1456 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1457 | self.gearman_server.port) |
| 1458 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1459 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1460 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1461 | self.assertTrue(r) |
| 1462 | |
| 1463 | self.executor_server.failJob('project-test2', A) |
| 1464 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1465 | |
| 1466 | self.waitUntilSettled() |
| 1467 | |
| 1468 | self.assertEqual(A.data['status'], 'NEW') |
| 1469 | self.assertEqual(A.reported, 1) |
| 1470 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1471 | 'FAILURE') |
| 1472 | |
| 1473 | # Check nodepool for a held node |
| 1474 | held_node = None |
| 1475 | for node in self.fake_nodepool.getNodes(): |
| 1476 | if node['state'] == zuul.model.STATE_HOLD: |
| 1477 | held_node = node |
| 1478 | break |
| 1479 | self.assertIsNotNone(held_node) |
| 1480 | |
| 1481 | # Validate node has recorded the failed job |
| 1482 | self.assertEqual( |
| 1483 | held_node['hold_job'], |
| 1484 | " ".join(['tenant-one', |
| 1485 | 'review.example.com/org/project', |
| 1486 | 'project-test2']) |
| 1487 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1488 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1489 | |
| 1490 | # Another failed change should not hold any more nodes |
| 1491 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1492 | self.executor_server.failJob('project-test2', B) |
| 1493 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1494 | self.waitUntilSettled() |
| 1495 | self.assertEqual(B.data['status'], 'NEW') |
| 1496 | self.assertEqual(B.reported, 1) |
| 1497 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1498 | 'FAILURE') |
| 1499 | |
| 1500 | held_nodes = 0 |
| 1501 | for node in self.fake_nodepool.getNodes(): |
| 1502 | if node['state'] == zuul.model.STATE_HOLD: |
| 1503 | held_nodes += 1 |
| 1504 | self.assertEqual(held_nodes, 1) |
| 1505 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1506 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1507 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1508 | # This particular test does a large amount of merges and needs a little |
| 1509 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1510 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1511 | "test that dependent changes behind dequeued changes work" |
| 1512 | # This complicated test is a reproduction of a real life bug |
| 1513 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1514 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1515 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1516 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1517 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1518 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1519 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1520 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1521 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1522 | D.setDependsOn(C, 1) |
| 1523 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1524 | A.addApproval('Code-Review', 2) |
| 1525 | B.addApproval('Code-Review', 2) |
| 1526 | C.addApproval('Code-Review', 2) |
| 1527 | D.addApproval('Code-Review', 2) |
| 1528 | E.addApproval('Code-Review', 2) |
| 1529 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1530 | |
| 1531 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1532 | |
| 1533 | # Change object re-use in the gerrit trigger is hidden if |
| 1534 | # changes are added in quick succession; waiting makes it more |
| 1535 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1536 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1537 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1538 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1539 | self.waitUntilSettled() |
| 1540 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1541 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1542 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1543 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1544 | self.waitUntilSettled() |
| 1545 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1546 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1547 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1548 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1549 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1550 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1551 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1552 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1553 | self.waitUntilSettled() |
| 1554 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1555 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1556 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1557 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1558 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1559 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1560 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1561 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1562 | self.waitUntilSettled() |
| 1563 | |
| 1564 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1565 | |
| 1566 | # Grab pointers to the jobs we want to release before |
| 1567 | # releasing any, because list indexes may change as |
| 1568 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1569 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1570 | a.release() |
| 1571 | b.release() |
| 1572 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1573 | self.waitUntilSettled() |
| 1574 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1575 | self.executor_server.hold_jobs_in_build = False |
| 1576 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1577 | self.waitUntilSettled() |
| 1578 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1579 | self.assertEqual(A.data['status'], 'NEW') |
| 1580 | self.assertEqual(B.data['status'], 'MERGED') |
| 1581 | self.assertEqual(C.data['status'], 'MERGED') |
| 1582 | self.assertEqual(D.data['status'], 'MERGED') |
| 1583 | self.assertEqual(E.data['status'], 'MERGED') |
| 1584 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1585 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1586 | self.assertEqual(A.reported, 2) |
| 1587 | self.assertEqual(B.reported, 2) |
| 1588 | self.assertEqual(C.reported, 2) |
| 1589 | self.assertEqual(D.reported, 2) |
| 1590 | self.assertEqual(E.reported, 2) |
| 1591 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1592 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1593 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1594 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1595 | |
| 1596 | def test_merger_repack(self): |
| 1597 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1598 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1599 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1600 | A.addApproval('Code-Review', 2) |
| 1601 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1602 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1603 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1604 | 'SUCCESS') |
| 1605 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1606 | 'SUCCESS') |
| 1607 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1608 | 'SUCCESS') |
| 1609 | self.assertEqual(A.data['status'], 'MERGED') |
| 1610 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1611 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1612 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1613 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1614 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1615 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1616 | if os.path.exists(path): |
| 1617 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1618 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1619 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1620 | if os.path.exists(path): |
| 1621 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1622 | |
| 1623 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1624 | A.addApproval('Code-Review', 2) |
| 1625 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1626 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1627 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1628 | 'SUCCESS') |
| 1629 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1630 | 'SUCCESS') |
| 1631 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1632 | 'SUCCESS') |
| 1633 | self.assertEqual(A.data['status'], 'MERGED') |
| 1634 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1635 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1636 | def test_merger_repack_large_change(self): |
| 1637 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1638 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1639 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1640 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1641 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1642 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1643 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1644 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1645 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1646 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1647 | # TODOv3(jeblair): add hostname to upstream root |
| 1648 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1649 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1650 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1651 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1652 | if os.path.exists(path): |
| 1653 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1654 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1655 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1656 | if os.path.exists(path): |
| 1657 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1658 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1659 | A.addApproval('Code-Review', 2) |
| 1660 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1661 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1662 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1663 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1664 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1665 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1666 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1667 | 'SUCCESS') |
| 1668 | self.assertEqual(A.data['status'], 'MERGED') |
| 1669 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1670 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1671 | def test_new_patchset_dequeues_old(self): |
| 1672 | "Test that a new patchset causes the old to be dequeued" |
| 1673 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1674 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1675 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1676 | M.setMerged() |
| 1677 | |
| 1678 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1679 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1680 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1681 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1682 | A.addApproval('Code-Review', 2) |
| 1683 | B.addApproval('Code-Review', 2) |
| 1684 | C.addApproval('Code-Review', 2) |
| 1685 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1686 | |
| 1687 | C.setDependsOn(B, 1) |
| 1688 | B.setDependsOn(A, 1) |
| 1689 | A.setDependsOn(M, 1) |
| 1690 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1691 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1692 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1693 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1694 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1695 | self.waitUntilSettled() |
| 1696 | |
| 1697 | B.addPatchset() |
| 1698 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1699 | self.waitUntilSettled() |
| 1700 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1701 | self.executor_server.hold_jobs_in_build = False |
| 1702 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1703 | self.waitUntilSettled() |
| 1704 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1705 | self.assertEqual(A.data['status'], 'MERGED') |
| 1706 | self.assertEqual(A.reported, 2) |
| 1707 | self.assertEqual(B.data['status'], 'NEW') |
| 1708 | self.assertEqual(B.reported, 2) |
| 1709 | self.assertEqual(C.data['status'], 'NEW') |
| 1710 | self.assertEqual(C.reported, 2) |
| 1711 | self.assertEqual(D.data['status'], 'MERGED') |
| 1712 | self.assertEqual(D.reported, 2) |
| 1713 | 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] | 1714 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1715 | def test_new_patchset_check(self): |
| 1716 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1717 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1718 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1719 | |
| 1720 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1721 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1722 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1723 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1724 | |
| 1725 | # Add two git-dependent changes |
| 1726 | B.setDependsOn(A, 1) |
| 1727 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1728 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1729 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1730 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1731 | |
| 1732 | # A live item, and a non-live/live pair |
| 1733 | items = check_pipeline.getAllItems() |
| 1734 | self.assertEqual(len(items), 3) |
| 1735 | |
| 1736 | self.assertEqual(items[0].change.number, '1') |
| 1737 | self.assertEqual(items[0].change.patchset, '1') |
| 1738 | self.assertFalse(items[0].live) |
| 1739 | |
| 1740 | self.assertEqual(items[1].change.number, '2') |
| 1741 | self.assertEqual(items[1].change.patchset, '1') |
| 1742 | self.assertTrue(items[1].live) |
| 1743 | |
| 1744 | self.assertEqual(items[2].change.number, '1') |
| 1745 | self.assertEqual(items[2].change.patchset, '1') |
| 1746 | self.assertTrue(items[2].live) |
| 1747 | |
| 1748 | # Add a new patchset to A |
| 1749 | A.addPatchset() |
| 1750 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1751 | self.waitUntilSettled() |
| 1752 | |
| 1753 | # The live copy of A,1 should be gone, but the non-live and B |
| 1754 | # should continue, and we should have a new A,2 |
| 1755 | items = check_pipeline.getAllItems() |
| 1756 | self.assertEqual(len(items), 3) |
| 1757 | |
| 1758 | self.assertEqual(items[0].change.number, '1') |
| 1759 | self.assertEqual(items[0].change.patchset, '1') |
| 1760 | self.assertFalse(items[0].live) |
| 1761 | |
| 1762 | self.assertEqual(items[1].change.number, '2') |
| 1763 | self.assertEqual(items[1].change.patchset, '1') |
| 1764 | self.assertTrue(items[1].live) |
| 1765 | |
| 1766 | self.assertEqual(items[2].change.number, '1') |
| 1767 | self.assertEqual(items[2].change.patchset, '2') |
| 1768 | self.assertTrue(items[2].live) |
| 1769 | |
| 1770 | # Add a new patchset to B |
| 1771 | B.addPatchset() |
| 1772 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1773 | self.waitUntilSettled() |
| 1774 | |
| 1775 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1776 | # but we should have a new B,2 (still based on A,1) |
| 1777 | items = check_pipeline.getAllItems() |
| 1778 | self.assertEqual(len(items), 3) |
| 1779 | |
| 1780 | self.assertEqual(items[0].change.number, '1') |
| 1781 | self.assertEqual(items[0].change.patchset, '2') |
| 1782 | self.assertTrue(items[0].live) |
| 1783 | |
| 1784 | self.assertEqual(items[1].change.number, '1') |
| 1785 | self.assertEqual(items[1].change.patchset, '1') |
| 1786 | self.assertFalse(items[1].live) |
| 1787 | |
| 1788 | self.assertEqual(items[2].change.number, '2') |
| 1789 | self.assertEqual(items[2].change.patchset, '2') |
| 1790 | self.assertTrue(items[2].live) |
| 1791 | |
| 1792 | self.builds[0].release() |
| 1793 | self.waitUntilSettled() |
| 1794 | self.builds[0].release() |
| 1795 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1796 | self.executor_server.hold_jobs_in_build = False |
| 1797 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1798 | self.waitUntilSettled() |
| 1799 | |
| 1800 | self.assertEqual(A.reported, 1) |
| 1801 | self.assertEqual(B.reported, 1) |
| 1802 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1803 | self.assertEqual(self.history[0].changes, '1,1') |
| 1804 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1805 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1806 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1807 | self.assertEqual(self.history[2].changes, '1,2') |
| 1808 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1809 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1810 | |
| 1811 | def test_abandoned_gate(self): |
| 1812 | "Test that an abandoned change is dequeued from gate" |
| 1813 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1814 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1815 | |
| 1816 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1817 | A.addApproval('Code-Review', 2) |
| 1818 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1819 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1820 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1821 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1822 | |
| 1823 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1824 | self.waitUntilSettled() |
| 1825 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1826 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1827 | self.waitUntilSettled() |
| 1828 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1829 | self.assertBuilds([]) |
| 1830 | self.assertHistory([ |
| 1831 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1832 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1833 | self.assertEqual(A.reported, 1, |
| 1834 | "Abandoned gate change should report only start") |
| 1835 | |
| 1836 | def test_abandoned_check(self): |
| 1837 | "Test that an abandoned change is dequeued from check" |
| 1838 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1839 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1840 | |
| 1841 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1842 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1843 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1844 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1845 | |
| 1846 | # Add two git-dependent changes |
| 1847 | B.setDependsOn(A, 1) |
| 1848 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1849 | self.waitUntilSettled() |
| 1850 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1851 | self.waitUntilSettled() |
| 1852 | # A live item, and a non-live/live pair |
| 1853 | items = check_pipeline.getAllItems() |
| 1854 | self.assertEqual(len(items), 3) |
| 1855 | |
| 1856 | self.assertEqual(items[0].change.number, '1') |
| 1857 | self.assertFalse(items[0].live) |
| 1858 | |
| 1859 | self.assertEqual(items[1].change.number, '2') |
| 1860 | self.assertTrue(items[1].live) |
| 1861 | |
| 1862 | self.assertEqual(items[2].change.number, '1') |
| 1863 | self.assertTrue(items[2].live) |
| 1864 | |
| 1865 | # Abandon A |
| 1866 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1867 | self.waitUntilSettled() |
| 1868 | |
| 1869 | # The live copy of A should be gone, but the non-live and B |
| 1870 | # should continue |
| 1871 | items = check_pipeline.getAllItems() |
| 1872 | self.assertEqual(len(items), 2) |
| 1873 | |
| 1874 | self.assertEqual(items[0].change.number, '1') |
| 1875 | self.assertFalse(items[0].live) |
| 1876 | |
| 1877 | self.assertEqual(items[1].change.number, '2') |
| 1878 | self.assertTrue(items[1].live) |
| 1879 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1880 | self.executor_server.hold_jobs_in_build = False |
| 1881 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1882 | self.waitUntilSettled() |
| 1883 | |
| 1884 | self.assertEqual(len(self.history), 4) |
| 1885 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1886 | 'Build should have been aborted') |
| 1887 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1888 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1889 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1890 | def test_abandoned_not_timer(self): |
| 1891 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1892 | # This test can not use simple_layout because it must start |
| 1893 | # with a configuration which does not include a |
| 1894 | # timer-triggered job so that we have an opportunity to set |
| 1895 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1896 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1897 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1898 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1899 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1900 | # The pipeline triggers every second, so we should have seen |
| 1901 | # several by now. |
| 1902 | time.sleep(5) |
| 1903 | self.waitUntilSettled() |
| 1904 | # Stop queuing timer triggered jobs so that the assertions |
| 1905 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1906 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1907 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1908 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1909 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1910 | # If APScheduler is in mid-event when we remove the job, we |
| 1911 | # can end up with one more event firing, so give it an extra |
| 1912 | # second to settle. |
| 1913 | time.sleep(1) |
| 1914 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1915 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1916 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1917 | |
| 1918 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1919 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1920 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1921 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1922 | |
| 1923 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1924 | self.waitUntilSettled() |
| 1925 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1926 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1927 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1928 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1929 | self.waitUntilSettled() |
| 1930 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1931 | def test_new_patchset_dequeues_old_on_head(self): |
| 1932 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1933 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1934 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1935 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1936 | M.setMerged() |
| 1937 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1938 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1939 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1940 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1941 | A.addApproval('Code-Review', 2) |
| 1942 | B.addApproval('Code-Review', 2) |
| 1943 | C.addApproval('Code-Review', 2) |
| 1944 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1945 | |
| 1946 | C.setDependsOn(B, 1) |
| 1947 | B.setDependsOn(A, 1) |
| 1948 | A.setDependsOn(M, 1) |
| 1949 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1950 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1951 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1952 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1953 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1954 | self.waitUntilSettled() |
| 1955 | |
| 1956 | A.addPatchset() |
| 1957 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1958 | self.waitUntilSettled() |
| 1959 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1960 | self.executor_server.hold_jobs_in_build = False |
| 1961 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1962 | self.waitUntilSettled() |
| 1963 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1964 | self.assertEqual(A.data['status'], 'NEW') |
| 1965 | self.assertEqual(A.reported, 2) |
| 1966 | self.assertEqual(B.data['status'], 'NEW') |
| 1967 | self.assertEqual(B.reported, 2) |
| 1968 | self.assertEqual(C.data['status'], 'NEW') |
| 1969 | self.assertEqual(C.reported, 2) |
| 1970 | self.assertEqual(D.data['status'], 'MERGED') |
| 1971 | self.assertEqual(D.reported, 2) |
| 1972 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1973 | |
| 1974 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1975 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1976 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1977 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1978 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1979 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1980 | A.addApproval('Code-Review', 2) |
| 1981 | B.addApproval('Code-Review', 2) |
| 1982 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1983 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1984 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1985 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1986 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1987 | self.waitUntilSettled() |
| 1988 | |
| 1989 | B.addPatchset() |
| 1990 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1991 | self.waitUntilSettled() |
| 1992 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1993 | self.executor_server.hold_jobs_in_build = False |
| 1994 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1995 | self.waitUntilSettled() |
| 1996 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1997 | self.assertEqual(A.data['status'], 'MERGED') |
| 1998 | self.assertEqual(A.reported, 2) |
| 1999 | self.assertEqual(B.data['status'], 'NEW') |
| 2000 | self.assertEqual(B.reported, 2) |
| 2001 | self.assertEqual(C.data['status'], 'MERGED') |
| 2002 | self.assertEqual(C.reported, 2) |
| 2003 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2004 | |
| 2005 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2006 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2007 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2008 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2009 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2010 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2011 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2012 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2013 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2014 | self.waitUntilSettled() |
| 2015 | |
| 2016 | B.addPatchset() |
| 2017 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2018 | self.waitUntilSettled() |
| 2019 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2020 | self.executor_server.hold_jobs_in_build = False |
| 2021 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2022 | self.waitUntilSettled() |
| 2023 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2024 | self.assertEqual(A.data['status'], 'NEW') |
| 2025 | self.assertEqual(A.reported, 1) |
| 2026 | self.assertEqual(B.data['status'], 'NEW') |
| 2027 | self.assertEqual(B.reported, 1) |
| 2028 | self.assertEqual(C.data['status'], 'NEW') |
| 2029 | self.assertEqual(C.reported, 1) |
| 2030 | self.assertEqual(len(self.history), 10) |
| 2031 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2032 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2033 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2034 | def test_noop_job(self): |
| 2035 | "Test that the internal noop job works" |
| 2036 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2037 | A.addApproval('Code-Review', 2) |
| 2038 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2039 | self.waitUntilSettled() |
| 2040 | |
| 2041 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2042 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2043 | self.assertEqual(len(self.history), 0) |
| 2044 | self.assertEqual(A.data['status'], 'MERGED') |
| 2045 | self.assertEqual(A.reported, 2) |
| 2046 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2047 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2048 | def test_no_job_project(self): |
| 2049 | "Test that reports with no jobs don't get sent" |
| 2050 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2051 | 'master', 'A') |
| 2052 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2053 | self.waitUntilSettled() |
| 2054 | |
| 2055 | # Change wasn't reported to |
| 2056 | self.assertEqual(A.reported, False) |
| 2057 | |
| 2058 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2059 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2060 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2061 | items = check_pipeline.getAllItems() |
| 2062 | self.assertEqual(len(items), 0) |
| 2063 | |
| 2064 | self.assertEqual(len(self.history), 0) |
| 2065 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2066 | def test_zuul_refs(self): |
| 2067 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2068 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2069 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2070 | M1.setMerged() |
| 2071 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2072 | M2.setMerged() |
| 2073 | |
| 2074 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2075 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2076 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2077 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2078 | A.addApproval('Code-Review', 2) |
| 2079 | B.addApproval('Code-Review', 2) |
| 2080 | C.addApproval('Code-Review', 2) |
| 2081 | D.addApproval('Code-Review', 2) |
| 2082 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2083 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2084 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2085 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2086 | |
| 2087 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2088 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2089 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2090 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2091 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2092 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2093 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2094 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2095 | self.waitUntilSettled() |
| 2096 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2097 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2098 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2099 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2100 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2101 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2102 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2103 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2104 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2105 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2106 | d_build = x |
| 2107 | if a_build and b_build and c_build and d_build: |
| 2108 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2109 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2110 | # should have a, not b, and should not be in project2 |
| 2111 | self.assertTrue(a_build.hasChanges(A)) |
| 2112 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2113 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2114 | # should have a and b, and should not be in project2 |
| 2115 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2116 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2117 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2118 | # should have a and b in 1, c in 2 |
| 2119 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2120 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2121 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2122 | # should have a and b in 1, c and d in 2 |
| 2123 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2124 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2125 | self.executor_server.hold_jobs_in_build = False |
| 2126 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2127 | self.waitUntilSettled() |
| 2128 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 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) |
| 2133 | self.assertEqual(C.data['status'], 'MERGED') |
| 2134 | self.assertEqual(C.reported, 2) |
| 2135 | self.assertEqual(D.data['status'], 'MERGED') |
| 2136 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2137 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2138 | def test_rerun_on_error(self): |
| 2139 | "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] | 2140 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2141 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2142 | A.addApproval('Code-Review', 2) |
| 2143 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2144 | self.waitUntilSettled() |
| 2145 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2146 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2147 | self.executor_server.hold_jobs_in_build = False |
| 2148 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2149 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2150 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2151 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2152 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2153 | def test_statsd(self): |
| 2154 | "Test each of the statsd methods used in the scheduler" |
James E. Blair | ded241e | 2017-10-10 13:22:40 -0700 | [diff] [blame] | 2155 | statsd = self.sched.statsd |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2156 | statsd.incr('test-incr') |
| 2157 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2158 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2159 | self.assertReportedStat('test-incr', '1|c') |
| 2160 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2161 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2162 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2163 | def test_stuck_job_cleanup(self): |
| 2164 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2165 | |
| 2166 | # 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] | 2167 | self.gearman_server.hold_jobs_in_queue = True |
| 2168 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2169 | A.addApproval('Code-Review', 2) |
| 2170 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2171 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2172 | # 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] | 2173 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2174 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2175 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2176 | self.sched.reconfigure(self.config) |
| 2177 | self.waitUntilSettled() |
| 2178 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2179 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2180 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2181 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2182 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2183 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2184 | |
| 2185 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2186 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2187 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2188 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2189 | def test_file_head(self): |
| 2190 | # This is a regression test for an observed bug. A change |
| 2191 | # with a file named "HEAD" in the root directory of the repo |
| 2192 | # was processed by a merger. It then was unable to reset the |
| 2193 | # repo because of: |
| 2194 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2195 | # with exit code 128 |
| 2196 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2197 | # and filename |
| 2198 | # Use '--' to separate filenames from revisions' |
| 2199 | |
| 2200 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2201 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2202 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2203 | |
| 2204 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2205 | self.waitUntilSettled() |
| 2206 | |
| 2207 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2208 | self.waitUntilSettled() |
| 2209 | |
| 2210 | self.assertIn('Build succeeded', A.messages[0]) |
| 2211 | self.assertIn('Build succeeded', B.messages[0]) |
| 2212 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2213 | def test_file_jobs(self): |
| 2214 | "Test that file jobs run only when appropriate" |
| 2215 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2216 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2217 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2218 | A.addApproval('Code-Review', 2) |
| 2219 | B.addApproval('Code-Review', 2) |
| 2220 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2221 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2222 | self.waitUntilSettled() |
| 2223 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2224 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2225 | if x.name == 'project-testfile'] |
| 2226 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2227 | self.assertEqual(len(testfile_jobs), 1) |
| 2228 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2229 | self.assertEqual(A.data['status'], 'MERGED') |
| 2230 | self.assertEqual(A.reported, 2) |
| 2231 | self.assertEqual(B.data['status'], 'MERGED') |
| 2232 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2233 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2234 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2235 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2236 | if should_skip: |
| 2237 | files = {'ignoreme': 'ignored\n'} |
| 2238 | else: |
| 2239 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2240 | |
| 2241 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2242 | 'master', |
| 2243 | 'test irrelevant-files', |
| 2244 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2245 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2246 | self.waitUntilSettled() |
| 2247 | |
| 2248 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2249 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2250 | |
| 2251 | if should_skip: |
| 2252 | self.assertEqual([], tested_change_ids) |
| 2253 | else: |
| 2254 | self.assertIn(change.data['number'], tested_change_ids) |
| 2255 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2256 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2257 | def test_irrelevant_files_match_skips_job(self): |
| 2258 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2259 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2260 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2261 | def test_irrelevant_files_no_match_runs_job(self): |
| 2262 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2263 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2264 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2265 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2266 | files = {'ignoreme': 'ignored\n'} |
| 2267 | |
| 2268 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2269 | 'master', |
| 2270 | 'test irrelevant-files', |
| 2271 | files=files) |
| 2272 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2273 | self.waitUntilSettled() |
| 2274 | |
| 2275 | run_jobs = set([build.name for build in self.history]) |
| 2276 | |
| 2277 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2278 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2279 | |
James E. Blair | af8b208 | 2017-10-03 15:38:27 -0700 | [diff] [blame] | 2280 | @simple_layout('layouts/job-vars.yaml') |
| 2281 | def test_inherited_job_variables(self): |
| 2282 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2283 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2284 | self.waitUntilSettled() |
| 2285 | self.assertHistory([ |
| 2286 | dict(name='parentjob', result='SUCCESS'), |
| 2287 | dict(name='child1', result='SUCCESS'), |
| 2288 | dict(name='child2', result='SUCCESS'), |
| 2289 | dict(name='child3', result='SUCCESS'), |
| 2290 | ], ordered=False) |
| 2291 | j = self.getJobFromHistory('parentjob') |
| 2292 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2293 | self.assertEqual(j.parameters['vars']['override'], 0) |
| 2294 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2295 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2296 | self.assertFalse('child1' in j.parameters['vars']) |
| 2297 | self.assertFalse('child2' in j.parameters['vars']) |
| 2298 | self.assertFalse('child3' in j.parameters['vars']) |
| 2299 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2300 | 'org/project0'])) |
| 2301 | j = self.getJobFromHistory('child1') |
| 2302 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2303 | self.assertEqual(j.parameters['vars']['override'], 1) |
| 2304 | self.assertEqual(j.parameters['vars']['child1override'], 1) |
| 2305 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2306 | self.assertEqual(j.parameters['vars']['child1'], 1) |
| 2307 | self.assertFalse('child2' in j.parameters['vars']) |
| 2308 | self.assertFalse('child3' in j.parameters['vars']) |
| 2309 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2310 | 'org/project1'])) |
| 2311 | j = self.getJobFromHistory('child2') |
| 2312 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2313 | self.assertEqual(j.parameters['vars']['override'], 2) |
| 2314 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2315 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2316 | self.assertFalse('child1' in j.parameters['vars']) |
| 2317 | self.assertEqual(j.parameters['vars']['child2'], 2) |
| 2318 | self.assertFalse('child3' in j.parameters['vars']) |
| 2319 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2320 | 'org/project2'])) |
| 2321 | j = self.getJobFromHistory('child3') |
| 2322 | rp = set([p['name'] for p in j.parameters['projects']]) |
| 2323 | self.assertEqual(j.parameters['vars']['override'], 3) |
| 2324 | self.assertEqual(j.parameters['vars']['child1override'], 0) |
| 2325 | self.assertEqual(j.parameters['vars']['parent'], 0) |
| 2326 | self.assertFalse('child1' in j.parameters['vars']) |
| 2327 | self.assertFalse('child2' in j.parameters['vars']) |
| 2328 | self.assertEqual(j.parameters['vars']['child3'], 3) |
| 2329 | self.assertEqual(rp, set(['org/project', 'org/project0', |
| 2330 | 'org/project3'])) |
| 2331 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2332 | def test_queue_names(self): |
| 2333 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2334 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2335 | (trusted, project1) = tenant.getProject('org/project1') |
| 2336 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2337 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2338 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2339 | self.assertEqual(q1.name, 'integrated') |
| 2340 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2341 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2342 | def test_queue_precedence(self): |
| 2343 | "Test that queue precedence works" |
| 2344 | |
| 2345 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2346 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2347 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2348 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2349 | A.addApproval('Code-Review', 2) |
| 2350 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2351 | |
| 2352 | self.waitUntilSettled() |
| 2353 | self.gearman_server.hold_jobs_in_queue = False |
| 2354 | self.gearman_server.release() |
| 2355 | self.waitUntilSettled() |
| 2356 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2357 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2358 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2359 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2360 | self.waitUntilSettled() |
| 2361 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2362 | self.log.debug(self.history) |
| 2363 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2364 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2365 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2366 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2367 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2368 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2369 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2370 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2371 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2372 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2373 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2374 | A.addApproval('Code-Review', 2) |
| 2375 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2376 | self.waitUntilSettled() |
| 2377 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2378 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2379 | self.waitUntilSettled() |
| 2380 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2381 | port = self.webapp.server.socket.getsockname()[1] |
| 2382 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2383 | req = urllib.request.Request( |
| 2384 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2385 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2386 | headers = f.info() |
| 2387 | self.assertIn('Content-Length', headers) |
| 2388 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2389 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2390 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2391 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2392 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2393 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2394 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2395 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2396 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2397 | self.executor_server.hold_jobs_in_build = False |
| 2398 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2399 | self.waitUntilSettled() |
| 2400 | |
| 2401 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2402 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2403 | for p in data['pipelines']: |
| 2404 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2405 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2406 | self.assertEqual(q['window'], 20) |
| 2407 | else: |
| 2408 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2409 | for head in q['heads']: |
| 2410 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2411 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2412 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2413 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2414 | status_jobs.append(job) |
| 2415 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2416 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2417 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2418 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2419 | uuid=status_jobs[0]['uuid']), |
| 2420 | status_jobs[0]['url']) |
| 2421 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2422 | 'finger://{hostname}/{uuid}'.format( |
| 2423 | hostname=self.executor_server.hostname, |
| 2424 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2425 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2426 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2427 | self.assertEqual( |
| 2428 | 'finger://{hostname}/{uuid}'.format( |
| 2429 | hostname=self.executor_server.hostname, |
| 2430 | uuid=status_jobs[0]['uuid']), |
| 2431 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2432 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2433 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2434 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2435 | uuid=status_jobs[1]['uuid']), |
| 2436 | status_jobs[1]['url']) |
| 2437 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2438 | 'finger://{hostname}/{uuid}'.format( |
| 2439 | hostname=self.executor_server.hostname, |
| 2440 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2441 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2442 | self.assertEqual( |
| 2443 | 'finger://{hostname}/{uuid}'.format( |
| 2444 | hostname=self.executor_server.hostname, |
| 2445 | uuid=status_jobs[1]['uuid']), |
| 2446 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2447 | |
| 2448 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2449 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2450 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2451 | uuid=status_jobs[2]['uuid']), |
| 2452 | status_jobs[2]['url']) |
| 2453 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2454 | 'finger://{hostname}/{uuid}'.format( |
| 2455 | hostname=self.executor_server.hostname, |
| 2456 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2457 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2458 | self.assertEqual( |
| 2459 | 'finger://{hostname}/{uuid}'.format( |
| 2460 | hostname=self.executor_server.hostname, |
| 2461 | uuid=status_jobs[2]['uuid']), |
| 2462 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2463 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2464 | # check job dependencies |
| 2465 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2466 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2467 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2468 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2469 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2470 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2471 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2472 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2473 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2474 | def test_live_reconfiguration(self): |
| 2475 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2476 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2477 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2478 | A.addApproval('Code-Review', 2) |
| 2479 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2480 | self.waitUntilSettled() |
| 2481 | |
| 2482 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2483 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2484 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2485 | self.executor_server.hold_jobs_in_build = False |
| 2486 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2487 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2488 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2489 | 'SUCCESS') |
| 2490 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2491 | 'SUCCESS') |
| 2492 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2493 | 'SUCCESS') |
| 2494 | self.assertEqual(A.data['status'], 'MERGED') |
| 2495 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2496 | |
James E. Blair | 027ba99 | 2017-09-20 13:48:32 -0700 | [diff] [blame] | 2497 | def test_live_reconfiguration_abort(self): |
| 2498 | # Raise an exception during reconfiguration and verify we |
| 2499 | # still function. |
| 2500 | self.executor_server.hold_jobs_in_build = True |
| 2501 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2502 | A.addApproval('Code-Review', 2) |
| 2503 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2504 | self.waitUntilSettled() |
| 2505 | |
| 2506 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2507 | pipeline = tenant.layout.pipelines['gate'] |
| 2508 | change = pipeline.getAllItems()[0].change |
| 2509 | # Set this to an invalid value to cause an exception during |
| 2510 | # reconfiguration. |
| 2511 | change.branch = None |
| 2512 | |
| 2513 | self.sched.reconfigure(self.config) |
| 2514 | self.waitUntilSettled() |
| 2515 | |
| 2516 | self.executor_server.hold_jobs_in_build = False |
| 2517 | self.executor_server.release() |
| 2518 | |
| 2519 | self.waitUntilSettled() |
| 2520 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2521 | 'ABORTED') |
| 2522 | self.assertEqual(A.data['status'], 'NEW') |
| 2523 | # The final report fails because of the invalid value set above. |
| 2524 | self.assertEqual(A.reported, 1) |
| 2525 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2526 | def test_live_reconfiguration_merge_conflict(self): |
| 2527 | # A real-world bug: a change in a gate queue has a merge |
| 2528 | # conflict and a job is added to its project while it's |
| 2529 | # sitting in the queue. The job gets added to the change and |
| 2530 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2531 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2532 | |
| 2533 | # This change is fine. It's here to stop the queue long |
| 2534 | # enough for the next change to be subject to the |
| 2535 | # reconfiguration, as well as to provide a conflict for the |
| 2536 | # next change. This change will succeed and merge. |
| 2537 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2538 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2539 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2540 | |
| 2541 | # This change will be in merge conflict. During the |
| 2542 | # reconfiguration, we will add a job. We want to make sure |
| 2543 | # that doesn't cause it to get stuck. |
| 2544 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2545 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2546 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2547 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2548 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2549 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2550 | |
| 2551 | self.waitUntilSettled() |
| 2552 | |
| 2553 | # No jobs have run yet |
| 2554 | self.assertEqual(A.data['status'], 'NEW') |
| 2555 | self.assertEqual(A.reported, 1) |
| 2556 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2557 | self.assertEqual(len(self.history), 0) |
| 2558 | |
| 2559 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2560 | self.commitConfigUpdate('common-config', |
| 2561 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2562 | self.sched.reconfigure(self.config) |
| 2563 | self.waitUntilSettled() |
| 2564 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2565 | self.executor_server.hold_jobs_in_build = False |
| 2566 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2567 | self.waitUntilSettled() |
| 2568 | |
| 2569 | self.assertEqual(A.data['status'], 'MERGED') |
| 2570 | self.assertEqual(A.reported, 2) |
| 2571 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2572 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2573 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2574 | 'SUCCESS') |
| 2575 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2576 | 'SUCCESS') |
| 2577 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2578 | 'SUCCESS') |
| 2579 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2580 | 'SUCCESS') |
| 2581 | self.assertEqual(len(self.history), 4) |
| 2582 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2583 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2584 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2585 | # that tests a job added to a job tree with a failed root does |
| 2586 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2587 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2588 | |
| 2589 | # This change is fine. It's here to stop the queue long |
| 2590 | # enough for the next change to be subject to the |
| 2591 | # reconfiguration. This change will succeed and merge. |
| 2592 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2593 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2594 | A.addApproval('Code-Review', 2) |
| 2595 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2596 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2597 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2598 | self.waitUntilSettled() |
| 2599 | |
| 2600 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2601 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2602 | B.addApproval('Code-Review', 2) |
| 2603 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2604 | self.waitUntilSettled() |
| 2605 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2606 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2607 | self.waitUntilSettled() |
| 2608 | |
| 2609 | # Both -merge jobs have run, but no others. |
| 2610 | self.assertEqual(A.data['status'], 'NEW') |
| 2611 | self.assertEqual(A.reported, 1) |
| 2612 | self.assertEqual(B.data['status'], 'NEW') |
| 2613 | self.assertEqual(B.reported, 1) |
| 2614 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2615 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2616 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2617 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2618 | self.assertEqual(len(self.history), 2) |
| 2619 | |
| 2620 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2621 | self.commitConfigUpdate('common-config', |
| 2622 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2623 | self.sched.reconfigure(self.config) |
| 2624 | self.waitUntilSettled() |
| 2625 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2626 | self.executor_server.hold_jobs_in_build = False |
| 2627 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2628 | self.waitUntilSettled() |
| 2629 | |
| 2630 | self.assertEqual(A.data['status'], 'MERGED') |
| 2631 | self.assertEqual(A.reported, 2) |
| 2632 | self.assertEqual(B.data['status'], 'NEW') |
| 2633 | self.assertEqual(B.reported, 2) |
| 2634 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2635 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2636 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2637 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2638 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2639 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2640 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2641 | self.assertEqual(len(self.history), 5) |
| 2642 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2643 | def test_live_reconfiguration_failed_job(self): |
| 2644 | # Test that a change with a removed failing job does not |
| 2645 | # disrupt reconfiguration. If a change has a failed job and |
| 2646 | # that job is removed during a reconfiguration, we observed a |
| 2647 | # bug where the code to re-set build statuses would run on |
| 2648 | # that build and raise an exception because the job no longer |
| 2649 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2650 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2651 | |
| 2652 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2653 | |
| 2654 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2655 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2656 | |
| 2657 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2658 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2659 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2660 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2661 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2662 | self.waitUntilSettled() |
| 2663 | |
| 2664 | self.assertEqual(A.data['status'], 'NEW') |
| 2665 | self.assertEqual(A.reported, 0) |
| 2666 | |
| 2667 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2668 | 'SUCCESS') |
| 2669 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2670 | 'FAILURE') |
| 2671 | self.assertEqual(len(self.history), 2) |
| 2672 | |
| 2673 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2674 | self.commitConfigUpdate('common-config', |
| 2675 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2676 | self.sched.reconfigure(self.config) |
| 2677 | self.waitUntilSettled() |
| 2678 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2679 | self.executor_server.hold_jobs_in_build = False |
| 2680 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2681 | self.waitUntilSettled() |
| 2682 | |
| 2683 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2684 | 'SUCCESS') |
| 2685 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2686 | 'SUCCESS') |
| 2687 | self.assertEqual(len(self.history), 4) |
| 2688 | |
| 2689 | self.assertEqual(A.data['status'], 'NEW') |
| 2690 | self.assertEqual(A.reported, 1) |
| 2691 | self.assertIn('Build succeeded', A.messages[0]) |
| 2692 | # Ensure the removed job was not included in the report. |
| 2693 | self.assertNotIn('project-test1', A.messages[0]) |
| 2694 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2695 | def test_live_reconfiguration_shared_queue(self): |
| 2696 | # Test that a change with a failing job which was removed from |
| 2697 | # this project but otherwise still exists in the system does |
| 2698 | # not disrupt reconfiguration. |
| 2699 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2700 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2701 | |
| 2702 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2703 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2704 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2705 | |
| 2706 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2707 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2708 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2709 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2710 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2711 | self.waitUntilSettled() |
| 2712 | |
| 2713 | self.assertEqual(A.data['status'], 'NEW') |
| 2714 | self.assertEqual(A.reported, 0) |
| 2715 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2716 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2717 | 'SUCCESS') |
| 2718 | self.assertEqual(self.getJobFromHistory( |
| 2719 | 'project1-project2-integration').result, 'FAILURE') |
| 2720 | self.assertEqual(len(self.history), 2) |
| 2721 | |
| 2722 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2723 | self.commitConfigUpdate( |
| 2724 | 'common-config', |
| 2725 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2726 | self.sched.reconfigure(self.config) |
| 2727 | self.waitUntilSettled() |
| 2728 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2729 | self.executor_server.hold_jobs_in_build = False |
| 2730 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2731 | self.waitUntilSettled() |
| 2732 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2733 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2734 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2735 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2736 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2737 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2738 | 'SUCCESS') |
| 2739 | self.assertEqual(self.getJobFromHistory( |
| 2740 | 'project1-project2-integration').result, 'FAILURE') |
| 2741 | self.assertEqual(len(self.history), 4) |
| 2742 | |
| 2743 | self.assertEqual(A.data['status'], 'NEW') |
| 2744 | self.assertEqual(A.reported, 1) |
| 2745 | self.assertIn('Build succeeded', A.messages[0]) |
| 2746 | # Ensure the removed job was not included in the report. |
| 2747 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2748 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2749 | def test_double_live_reconfiguration_shared_queue(self): |
| 2750 | # This was a real-world regression. A change is added to |
| 2751 | # gate; a reconfigure happens, a second change which depends |
| 2752 | # on the first is added, and a second reconfiguration happens. |
| 2753 | # Ensure that both changes merge. |
| 2754 | |
| 2755 | # A failure may indicate incorrect caching or cleaning up of |
| 2756 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2757 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2758 | |
| 2759 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2760 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2761 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2762 | A.addApproval('Code-Review', 2) |
| 2763 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2764 | |
| 2765 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2766 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2767 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2768 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2769 | self.waitUntilSettled() |
| 2770 | |
| 2771 | # Reconfigure (with only one change in the pipeline). |
| 2772 | self.sched.reconfigure(self.config) |
| 2773 | self.waitUntilSettled() |
| 2774 | |
| 2775 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2776 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2777 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2778 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2779 | self.waitUntilSettled() |
| 2780 | |
| 2781 | # Reconfigure (with both in the pipeline). |
| 2782 | self.sched.reconfigure(self.config) |
| 2783 | self.waitUntilSettled() |
| 2784 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2785 | self.executor_server.hold_jobs_in_build = False |
| 2786 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2787 | self.waitUntilSettled() |
| 2788 | |
| 2789 | self.assertEqual(len(self.history), 8) |
| 2790 | |
| 2791 | self.assertEqual(A.data['status'], 'MERGED') |
| 2792 | self.assertEqual(A.reported, 2) |
| 2793 | self.assertEqual(B.data['status'], 'MERGED') |
| 2794 | self.assertEqual(B.reported, 2) |
| 2795 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2796 | def test_live_reconfiguration_del_project(self): |
| 2797 | # Test project deletion from layout |
| 2798 | # while changes are enqueued |
| 2799 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2800 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2801 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2802 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2803 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2804 | |
| 2805 | # A Depends-On: B |
| 2806 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2807 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2808 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2809 | |
| 2810 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2811 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2812 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2813 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2814 | self.waitUntilSettled() |
| 2815 | self.assertEqual(len(self.builds), 5) |
| 2816 | |
| 2817 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2818 | self.commitConfigUpdate( |
| 2819 | 'common-config', |
| 2820 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2821 | self.sched.reconfigure(self.config) |
| 2822 | self.waitUntilSettled() |
| 2823 | |
| 2824 | # Builds for C aborted, builds for A succeed, |
| 2825 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2826 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2827 | self.assertEqual(job_c.changes, '3,1') |
| 2828 | self.assertEqual(job_c.result, 'ABORTED') |
| 2829 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2830 | self.executor_server.hold_jobs_in_build = False |
| 2831 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2832 | self.waitUntilSettled() |
| 2833 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2834 | self.assertEqual( |
| 2835 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2836 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2837 | |
| 2838 | self.assertEqual(A.data['status'], 'NEW') |
| 2839 | self.assertEqual(B.data['status'], 'NEW') |
| 2840 | self.assertEqual(C.data['status'], 'NEW') |
| 2841 | self.assertEqual(A.reported, 1) |
| 2842 | self.assertEqual(B.reported, 0) |
| 2843 | self.assertEqual(C.reported, 0) |
| 2844 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2845 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2846 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2847 | self.assertIn('Build succeeded', A.messages[0]) |
| 2848 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2849 | def test_delayed_repo_init(self): |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2850 | self.init_repo("org/new-project") |
Clint Byrum | 627ba36 | 2017-08-14 13:20:40 -0700 | [diff] [blame] | 2851 | files = {'README': ''} |
| 2852 | self.addCommitToRepo("org/new-project", 'Initial commit', |
| 2853 | files=files, tag='init') |
| 2854 | self.newTenantConfig('tenants/delayed-repo-init.yaml') |
| 2855 | self.commitConfigUpdate( |
| 2856 | 'common-config', |
| 2857 | 'layouts/delayed-repo-init.yaml') |
| 2858 | self.sched.reconfigure(self.config) |
| 2859 | self.waitUntilSettled() |
| 2860 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2861 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2862 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2863 | A.addApproval('Code-Review', 2) |
| 2864 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2865 | self.waitUntilSettled() |
| 2866 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2867 | 'SUCCESS') |
| 2868 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2869 | 'SUCCESS') |
| 2870 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2871 | 'SUCCESS') |
| 2872 | self.assertEqual(A.data['status'], 'MERGED') |
| 2873 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2874 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2875 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2876 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2877 | self.init_repo("org/delete-project") |
| 2878 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2879 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2880 | A.addApproval('Code-Review', 2) |
| 2881 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2882 | self.waitUntilSettled() |
| 2883 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2884 | 'SUCCESS') |
| 2885 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2886 | 'SUCCESS') |
| 2887 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2888 | 'SUCCESS') |
| 2889 | self.assertEqual(A.data['status'], 'MERGED') |
| 2890 | self.assertEqual(A.reported, 2) |
| 2891 | |
| 2892 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2893 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2894 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2895 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2896 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2897 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2898 | |
| 2899 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2900 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2901 | B.addApproval('Code-Review', 2) |
| 2902 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2903 | self.waitUntilSettled() |
| 2904 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2905 | 'SUCCESS') |
| 2906 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2907 | 'SUCCESS') |
| 2908 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2909 | 'SUCCESS') |
| 2910 | self.assertEqual(B.data['status'], 'MERGED') |
| 2911 | self.assertEqual(B.reported, 2) |
| 2912 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2913 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 2914 | def test_untrusted_secrets(self): |
| 2915 | "Test untrusted secrets" |
| 2916 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2917 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2918 | self.waitUntilSettled() |
| 2919 | |
| 2920 | self.assertHistory([]) |
| 2921 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
James E. Blair | 8eb564a | 2017-08-10 09:21:41 -0700 | [diff] [blame] | 2922 | self.assertIn('does not allow post-review job', |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2923 | A.messages[0]) |
| 2924 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2925 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2926 | def test_tags(self): |
| 2927 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2928 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2929 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2930 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2931 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2932 | self.waitUntilSettled() |
| 2933 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2934 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2935 | |
| 2936 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2937 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2938 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2939 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2940 | |
| 2941 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2942 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2943 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2944 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2945 | def test_timer(self): |
| 2946 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2947 | # This test can not use simple_layout because it must start |
| 2948 | # with a configuration which does not include a |
| 2949 | # timer-triggered job so that we have an opportunity to set |
| 2950 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2951 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2952 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2953 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2954 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2955 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2956 | # The pipeline triggers every second, so we should have seen |
| 2957 | # several by now. |
| 2958 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2959 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2960 | |
| 2961 | self.assertEqual(len(self.builds), 2) |
| 2962 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2963 | port = self.webapp.server.socket.getsockname()[1] |
| 2964 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2965 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2966 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2967 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2968 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2969 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2970 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2971 | # Stop queuing timer triggered jobs so that the assertions |
| 2972 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2973 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2974 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2975 | self.waitUntilSettled() |
| 2976 | # If APScheduler is in mid-event when we remove the job, we |
| 2977 | # can end up with one more event firing, so give it an extra |
| 2978 | # second to settle. |
| 2979 | time.sleep(1) |
| 2980 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2981 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2982 | self.waitUntilSettled() |
| 2983 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2984 | self.assertHistory([ |
| 2985 | dict(name='project-bitrot', result='SUCCESS', |
| 2986 | ref='refs/heads/master'), |
| 2987 | dict(name='project-bitrot', result='SUCCESS', |
| 2988 | ref='refs/heads/stable'), |
| 2989 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2990 | |
| 2991 | data = json.loads(data) |
| 2992 | status_jobs = set() |
| 2993 | for p in data['pipelines']: |
| 2994 | for q in p['change_queues']: |
| 2995 | for head in q['heads']: |
| 2996 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2997 | for job in change['jobs']: |
| 2998 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2999 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3000 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3001 | def test_idle(self): |
| 3002 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3003 | # This test can not use simple_layout because it must start |
| 3004 | # with a configuration which does not include a |
| 3005 | # timer-triggered job so that we have an opportunity to set |
| 3006 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3007 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3008 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3009 | for x in range(1, 3): |
| 3010 | # Test that timer triggers periodic jobs even across |
| 3011 | # layout config reloads. |
| 3012 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3013 | self.commitConfigUpdate('common-config', |
| 3014 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3015 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3016 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3017 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3018 | # The pipeline triggers every second, so we should have seen |
| 3019 | # several by now. |
| 3020 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3021 | |
| 3022 | # Stop queuing timer triggered jobs so that the assertions |
| 3023 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3024 | self.commitConfigUpdate('common-config', |
| 3025 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3026 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3027 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3028 | # If APScheduler is in mid-event when we remove the job, |
| 3029 | # we can end up with one more event firing, so give it an |
| 3030 | # extra second to settle. |
| 3031 | time.sleep(1) |
| 3032 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3033 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 3034 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3035 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3036 | self.waitUntilSettled() |
| 3037 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 3038 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3039 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3040 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3041 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3042 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3043 | self.waitUntilSettled() |
| 3044 | |
| 3045 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3046 | self.waitUntilSettled() |
| 3047 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3048 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3049 | |
| 3050 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3051 | # work on the knowledge of what the first message should be as |
| 3052 | # it is only configured to go to SMTP. |
| 3053 | |
| 3054 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3055 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3056 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3057 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3058 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3059 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3060 | |
| 3061 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3062 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3063 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3064 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3065 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3066 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3067 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3068 | def test_timer_smtp(self): |
| 3069 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3070 | # This test can not use simple_layout because it must start |
| 3071 | # with a configuration which does not include a |
| 3072 | # timer-triggered job so that we have an opportunity to set |
| 3073 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3074 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3075 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3076 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3077 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3078 | # The pipeline triggers every second, so we should have seen |
| 3079 | # several by now. |
| 3080 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3081 | self.waitUntilSettled() |
| 3082 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3083 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3084 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3085 | self.waitUntilSettled() |
| 3086 | self.assertEqual(len(self.history), 2) |
| 3087 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3088 | self.assertEqual(self.getJobFromHistory( |
| 3089 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3090 | self.assertEqual(self.getJobFromHistory( |
| 3091 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3092 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3093 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3094 | |
| 3095 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3096 | # work on the knowledge of what the first message should be as |
| 3097 | # it is only configured to go to SMTP. |
| 3098 | |
| 3099 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3100 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3101 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3102 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3103 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3104 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3105 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3106 | # Stop queuing timer triggered jobs and let any that may have |
| 3107 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3108 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3109 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3110 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3111 | # If APScheduler is in mid-event when we remove the job, we |
| 3112 | # can end up with one more event firing, so give it an extra |
| 3113 | # second to settle. |
| 3114 | time.sleep(1) |
| 3115 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3116 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3117 | self.waitUntilSettled() |
| 3118 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3119 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3120 | def test_timer_sshkey(self): |
| 3121 | "Test that a periodic job can setup SSH key authentication" |
| 3122 | self.worker.hold_jobs_in_build = True |
| 3123 | self.config.set('zuul', 'layout_config', |
| 3124 | 'tests/fixtures/layout-timer.yaml') |
| 3125 | self.sched.reconfigure(self.config) |
| 3126 | self.registerJobs() |
| 3127 | |
| 3128 | # The pipeline triggers every second, so we should have seen |
| 3129 | # several by now. |
| 3130 | time.sleep(5) |
| 3131 | self.waitUntilSettled() |
| 3132 | |
| 3133 | self.assertEqual(len(self.builds), 2) |
| 3134 | |
| 3135 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3136 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3137 | with open(ssh_wrapper) as f: |
| 3138 | ssh_wrapper_content = f.read() |
| 3139 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3140 | # In the unit tests Merger runs in the same process, |
| 3141 | # so we see its' environment variables |
| 3142 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3143 | |
| 3144 | self.worker.release('.*') |
| 3145 | self.waitUntilSettled() |
| 3146 | self.assertEqual(len(self.history), 2) |
| 3147 | |
| 3148 | self.assertEqual(self.getJobFromHistory( |
| 3149 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3150 | self.assertEqual(self.getJobFromHistory( |
| 3151 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3152 | |
| 3153 | # Stop queuing timer triggered jobs and let any that may have |
| 3154 | # queued through so that end of test assertions pass. |
| 3155 | self.config.set('zuul', 'layout_config', |
| 3156 | 'tests/fixtures/layout-no-timer.yaml') |
| 3157 | self.sched.reconfigure(self.config) |
| 3158 | self.registerJobs() |
| 3159 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3160 | # If APScheduler is in mid-event when we remove the job, we |
| 3161 | # can end up with one more event firing, so give it an extra |
| 3162 | # second to settle. |
| 3163 | time.sleep(1) |
| 3164 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3165 | self.worker.release('.*') |
| 3166 | self.waitUntilSettled() |
| 3167 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3168 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3169 | "Test that the RPC client can enqueue a change" |
| 3170 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3171 | A.addApproval('Code-Review', 2) |
| 3172 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3173 | |
| 3174 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3175 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3176 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3177 | r = client.enqueue(tenant='tenant-one', |
| 3178 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3179 | project='org/project', |
| 3180 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3181 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3182 | self.waitUntilSettled() |
| 3183 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3184 | 'SUCCESS') |
| 3185 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3186 | 'SUCCESS') |
| 3187 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3188 | 'SUCCESS') |
| 3189 | self.assertEqual(A.data['status'], 'MERGED') |
| 3190 | self.assertEqual(A.reported, 2) |
| 3191 | self.assertEqual(r, True) |
| 3192 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3193 | def test_client_enqueue_ref(self): |
| 3194 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3195 | p = "review.example.com/org/project" |
| 3196 | upstream = self.getUpstreamRepos([p]) |
| 3197 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3198 | A.setMerged() |
| 3199 | A_commit = str(upstream[p].commit('master')) |
| 3200 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3201 | |
| 3202 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3203 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3204 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3205 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3207 | pipeline='post', |
| 3208 | project='org/project', |
| 3209 | trigger='gerrit', |
| 3210 | ref='master', |
| 3211 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3212 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3213 | self.waitUntilSettled() |
| 3214 | job_names = [x.name for x in self.history] |
| 3215 | self.assertEqual(len(self.history), 1) |
| 3216 | self.assertIn('project-post', job_names) |
| 3217 | self.assertEqual(r, True) |
| 3218 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3219 | def test_client_enqueue_negative(self): |
| 3220 | "Test that the RPC client returns errors" |
| 3221 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3222 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3223 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3224 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3225 | "Invalid tenant"): |
| 3226 | r = client.enqueue(tenant='tenant-foo', |
| 3227 | pipeline='gate', |
| 3228 | project='org/project', |
| 3229 | trigger='gerrit', |
| 3230 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3231 | self.assertEqual(r, False) |
| 3232 | |
| 3233 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3234 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3235 | r = client.enqueue(tenant='tenant-one', |
| 3236 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3237 | project='project-does-not-exist', |
| 3238 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3239 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3240 | self.assertEqual(r, False) |
| 3241 | |
| 3242 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3243 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3244 | r = client.enqueue(tenant='tenant-one', |
| 3245 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3246 | project='org/project', |
| 3247 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3248 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3249 | self.assertEqual(r, False) |
| 3250 | |
| 3251 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3252 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3253 | r = client.enqueue(tenant='tenant-one', |
| 3254 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3255 | project='org/project', |
| 3256 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3258 | self.assertEqual(r, False) |
| 3259 | |
| 3260 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3261 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3262 | r = client.enqueue(tenant='tenant-one', |
| 3263 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3264 | project='org/project', |
| 3265 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3266 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3267 | self.assertEqual(r, False) |
| 3268 | |
| 3269 | self.waitUntilSettled() |
| 3270 | self.assertEqual(len(self.history), 0) |
| 3271 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3272 | |
| 3273 | def test_client_promote(self): |
| 3274 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3275 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3276 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3277 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3278 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3279 | A.addApproval('Code-Review', 2) |
| 3280 | B.addApproval('Code-Review', 2) |
| 3281 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3282 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3283 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3284 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3285 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3286 | |
| 3287 | self.waitUntilSettled() |
| 3288 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3289 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3290 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3291 | enqueue_times = {} |
| 3292 | for item in items: |
| 3293 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3294 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3295 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3296 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3297 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3298 | r = client.promote(tenant='tenant-one', |
| 3299 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3300 | change_ids=['2,1', '3,1']) |
| 3301 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3302 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3303 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3304 | for item in items: |
| 3305 | self.assertEqual( |
| 3306 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3307 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3308 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3309 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3310 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3311 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3312 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3313 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3314 | self.waitUntilSettled() |
| 3315 | |
| 3316 | self.assertEqual(len(self.builds), 6) |
| 3317 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3318 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3319 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3320 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3321 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3322 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3323 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3324 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3325 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3326 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3327 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3328 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3329 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3330 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3331 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3332 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3333 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3334 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3335 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3336 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3337 | self.waitUntilSettled() |
| 3338 | |
| 3339 | self.assertEqual(A.data['status'], 'MERGED') |
| 3340 | self.assertEqual(A.reported, 2) |
| 3341 | self.assertEqual(B.data['status'], 'MERGED') |
| 3342 | self.assertEqual(B.reported, 2) |
| 3343 | self.assertEqual(C.data['status'], 'MERGED') |
| 3344 | self.assertEqual(C.reported, 2) |
| 3345 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3346 | self.assertEqual(r, True) |
| 3347 | |
| 3348 | def test_client_promote_dependent(self): |
| 3349 | "Test that the RPC client can promote a dependent change" |
| 3350 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3351 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3352 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3354 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3355 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3356 | |
| 3357 | C.setDependsOn(B, 1) |
| 3358 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3359 | A.addApproval('Code-Review', 2) |
| 3360 | B.addApproval('Code-Review', 2) |
| 3361 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3362 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3363 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3364 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3365 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3366 | |
| 3367 | self.waitUntilSettled() |
| 3368 | |
| 3369 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3370 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3371 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3372 | r = client.promote(tenant='tenant-one', |
| 3373 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3374 | change_ids=['3,1']) |
| 3375 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3376 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3377 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3378 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3379 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3380 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3381 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3382 | self.waitUntilSettled() |
| 3383 | |
| 3384 | self.assertEqual(len(self.builds), 6) |
| 3385 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3386 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3387 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3388 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3389 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3390 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3391 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3392 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3393 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3394 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3395 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3396 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3397 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3398 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3399 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3400 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3401 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3402 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3403 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3404 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3405 | self.waitUntilSettled() |
| 3406 | |
| 3407 | self.assertEqual(A.data['status'], 'MERGED') |
| 3408 | self.assertEqual(A.reported, 2) |
| 3409 | self.assertEqual(B.data['status'], 'MERGED') |
| 3410 | self.assertEqual(B.reported, 2) |
| 3411 | self.assertEqual(C.data['status'], 'MERGED') |
| 3412 | self.assertEqual(C.reported, 2) |
| 3413 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3414 | self.assertEqual(r, True) |
| 3415 | |
| 3416 | def test_client_promote_negative(self): |
| 3417 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3418 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3419 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3420 | A.addApproval('Code-Review', 2) |
| 3421 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3422 | self.waitUntilSettled() |
| 3423 | |
| 3424 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3425 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3426 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3427 | |
| 3428 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3429 | r = client.promote(tenant='tenant-one', |
| 3430 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3431 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3432 | self.assertEqual(r, False) |
| 3433 | |
| 3434 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3435 | r = client.promote(tenant='tenant-one', |
| 3436 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3437 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3438 | self.assertEqual(r, False) |
| 3439 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3440 | self.executor_server.hold_jobs_in_build = False |
| 3441 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3442 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3443 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3444 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3445 | def test_queue_rate_limiting(self): |
| 3446 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3447 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3448 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3449 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3450 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3451 | |
| 3452 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3453 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3454 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3455 | A.addApproval('Code-Review', 2) |
| 3456 | B.addApproval('Code-Review', 2) |
| 3457 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3458 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3459 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3460 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3461 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3462 | self.waitUntilSettled() |
| 3463 | |
| 3464 | # Only A and B will have their merge jobs queued because |
| 3465 | # window is 2. |
| 3466 | self.assertEqual(len(self.builds), 2) |
| 3467 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3468 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3469 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3470 | # Release the merge jobs one at a time. |
| 3471 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3472 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3473 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3474 | self.waitUntilSettled() |
| 3475 | |
| 3476 | # Only A and B will have their test jobs queued because |
| 3477 | # window is 2. |
| 3478 | self.assertEqual(len(self.builds), 4) |
| 3479 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3480 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3481 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3482 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3483 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3484 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | self.waitUntilSettled() |
| 3486 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3487 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3488 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3489 | # A failed so window is reduced by 1 to 1. |
| 3490 | self.assertEqual(queue.window, 1) |
| 3491 | self.assertEqual(queue.window_floor, 1) |
| 3492 | self.assertEqual(A.data['status'], 'NEW') |
| 3493 | |
| 3494 | # Gate is reset and only B's merge job is queued because |
| 3495 | # window shrunk to 1. |
| 3496 | self.assertEqual(len(self.builds), 1) |
| 3497 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3498 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3499 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3500 | self.waitUntilSettled() |
| 3501 | |
| 3502 | # Only B's test jobs are queued because window is still 1. |
| 3503 | self.assertEqual(len(self.builds), 2) |
| 3504 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3505 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3506 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3507 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3508 | self.waitUntilSettled() |
| 3509 | |
| 3510 | # B was successfully merged so window is increased to 2. |
| 3511 | self.assertEqual(queue.window, 2) |
| 3512 | self.assertEqual(queue.window_floor, 1) |
| 3513 | self.assertEqual(B.data['status'], 'MERGED') |
| 3514 | |
| 3515 | # Only C is left and its merge job is queued. |
| 3516 | self.assertEqual(len(self.builds), 1) |
| 3517 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3518 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3519 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3520 | self.waitUntilSettled() |
| 3521 | |
| 3522 | # After successful merge job the test jobs for C are queued. |
| 3523 | self.assertEqual(len(self.builds), 2) |
| 3524 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3525 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3526 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3527 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3528 | self.waitUntilSettled() |
| 3529 | |
| 3530 | # C successfully merged so window is bumped to 3. |
| 3531 | self.assertEqual(queue.window, 3) |
| 3532 | self.assertEqual(queue.window_floor, 1) |
| 3533 | self.assertEqual(C.data['status'], 'MERGED') |
| 3534 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3535 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3536 | def test_queue_rate_limiting_dependent(self): |
| 3537 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3538 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3539 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3540 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3541 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3542 | |
| 3543 | B.setDependsOn(A, 1) |
| 3544 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3545 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3546 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3547 | A.addApproval('Code-Review', 2) |
| 3548 | B.addApproval('Code-Review', 2) |
| 3549 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3550 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3551 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3552 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3553 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3554 | self.waitUntilSettled() |
| 3555 | |
| 3556 | # Only A and B will have their merge jobs queued because |
| 3557 | # window is 2. |
| 3558 | self.assertEqual(len(self.builds), 2) |
| 3559 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3560 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3561 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3562 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3563 | |
| 3564 | # Only A and B will have their test jobs queued because |
| 3565 | # window is 2. |
| 3566 | self.assertEqual(len(self.builds), 4) |
| 3567 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3568 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3569 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3570 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3571 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3572 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3573 | self.waitUntilSettled() |
| 3574 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3575 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3576 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3577 | # A failed so window is reduced by 1 to 1. |
| 3578 | self.assertEqual(queue.window, 1) |
| 3579 | self.assertEqual(queue.window_floor, 1) |
| 3580 | self.assertEqual(A.data['status'], 'NEW') |
| 3581 | self.assertEqual(B.data['status'], 'NEW') |
| 3582 | |
| 3583 | # Gate is reset and only C's merge job is queued because |
| 3584 | # window shrunk to 1 and A and B were dequeued. |
| 3585 | self.assertEqual(len(self.builds), 1) |
| 3586 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3587 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3588 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3589 | |
| 3590 | # Only C's test jobs are queued because window is still 1. |
| 3591 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3592 | builds = self.getSortedBuilds() |
| 3593 | self.assertEqual(builds[0].name, 'project-test1') |
| 3594 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3595 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3596 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3597 | self.waitUntilSettled() |
| 3598 | |
| 3599 | # C was successfully merged so window is increased to 2. |
| 3600 | self.assertEqual(queue.window, 2) |
| 3601 | self.assertEqual(queue.window_floor, 1) |
| 3602 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3603 | |
| 3604 | def test_worker_update_metadata(self): |
| 3605 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3606 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3607 | |
| 3608 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3609 | A.addApproval('Code-Review', 2) |
| 3610 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3611 | self.waitUntilSettled() |
| 3612 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3613 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3614 | |
| 3615 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3616 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3617 | |
| 3618 | start = time.time() |
| 3619 | while True: |
| 3620 | if time.time() - start > 10: |
| 3621 | raise Exception("Timeout waiting for gearman server to report " |
| 3622 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3623 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3624 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3625 | break |
| 3626 | else: |
| 3627 | time.sleep(0) |
| 3628 | |
| 3629 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3630 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3631 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3632 | self.executor_server.hold_jobs_in_build = False |
| 3633 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3634 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3635 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3636 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3637 | def test_footer_message(self): |
| 3638 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3639 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3640 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3641 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3642 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3643 | self.waitUntilSettled() |
| 3644 | |
| 3645 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3646 | B.addApproval('Code-Review', 2) |
| 3647 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3648 | self.waitUntilSettled() |
| 3649 | |
| 3650 | self.assertEqual(2, len(self.smtp_messages)) |
| 3651 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3652 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3653 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3654 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3655 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3656 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3657 | For CI problems and help debugging, contact ci@example.org""" |
| 3658 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3659 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3660 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3661 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3662 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3663 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3664 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3665 | def test_unmanaged_project_start_message(self): |
| 3666 | "Test start reporting is not done for unmanaged projects." |
| 3667 | self.init_repo("org/project", tag='init') |
| 3668 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3669 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3670 | self.waitUntilSettled() |
| 3671 | |
| 3672 | self.assertEqual(0, len(A.messages)) |
| 3673 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3674 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3675 | def test_merge_failure_reporters(self): |
| 3676 | """Check that the config is set up correctly""" |
| 3677 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3678 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3679 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3680 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3681 | "dependencies was unable to be automatically merged with the " |
| 3682 | "current state of its repository. Please rebase the change and " |
| 3683 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3684 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3685 | self.assertEqual( |
| 3686 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3687 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3688 | |
| 3689 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3690 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3691 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3692 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3693 | |
| 3694 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3695 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3696 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3697 | |
| 3698 | self.assertTrue( |
| 3699 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3700 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3701 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3702 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3703 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3704 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3705 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3706 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3707 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3708 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3709 | gerritreporter.GerritReporter) and |
| 3710 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3711 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3712 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3713 | ) |
| 3714 | ) |
| 3715 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3716 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3717 | def test_merge_failure_reports(self): |
| 3718 | """Check that when a change fails to merge the correct message is sent |
| 3719 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3720 | self.updateConfigLayout( |
| 3721 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3722 | self.sched.reconfigure(self.config) |
| 3723 | self.registerJobs() |
| 3724 | |
| 3725 | # Check a test failure isn't reported to SMTP |
| 3726 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3727 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3728 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3729 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3730 | self.waitUntilSettled() |
| 3731 | |
| 3732 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3733 | self.assertEqual(0, len(self.smtp_messages)) |
| 3734 | |
| 3735 | # Check a merge failure is reported to SMTP |
| 3736 | # B should be merged, but C will conflict with B |
| 3737 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3738 | B.addPatchset(['conflict']) |
| 3739 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3740 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3741 | B.addApproval('Code-Review', 2) |
| 3742 | C.addApproval('Code-Review', 2) |
| 3743 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3744 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3745 | self.waitUntilSettled() |
| 3746 | |
| 3747 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3748 | self.assertEqual(1, len(self.smtp_messages)) |
| 3749 | self.assertEqual('The merge failed! For more information...', |
| 3750 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3751 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3752 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3753 | def test_default_merge_failure_reports(self): |
| 3754 | """Check that the default merge failure reports are correct.""" |
| 3755 | |
| 3756 | # A should report success, B should report merge failure. |
| 3757 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3758 | A.addPatchset(['conflict']) |
| 3759 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3760 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3761 | A.addApproval('Code-Review', 2) |
| 3762 | B.addApproval('Code-Review', 2) |
| 3763 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3764 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3765 | self.waitUntilSettled() |
| 3766 | |
| 3767 | self.assertEqual(3, len(self.history)) # A jobs |
| 3768 | self.assertEqual(A.reported, 2) |
| 3769 | self.assertEqual(B.reported, 2) |
| 3770 | self.assertEqual(A.data['status'], 'MERGED') |
| 3771 | self.assertEqual(B.data['status'], 'NEW') |
| 3772 | self.assertIn('Build succeeded', A.messages[1]) |
| 3773 | self.assertIn('Merge Failed', B.messages[1]) |
| 3774 | self.assertIn('automatically merged', B.messages[1]) |
| 3775 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3776 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3777 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3778 | def test_client_get_running_jobs(self): |
| 3779 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3780 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3781 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3782 | A.addApproval('Code-Review', 2) |
| 3783 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3784 | self.waitUntilSettled() |
| 3785 | |
| 3786 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3787 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3788 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3789 | |
| 3790 | # Wait for gearman server to send the initial workData back to zuul |
| 3791 | start = time.time() |
| 3792 | while True: |
| 3793 | if time.time() - start > 10: |
| 3794 | raise Exception("Timeout waiting for gearman server to report " |
| 3795 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3796 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3797 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3798 | break |
| 3799 | else: |
| 3800 | time.sleep(0) |
| 3801 | |
| 3802 | running_items = client.get_running_jobs() |
| 3803 | |
| 3804 | self.assertEqual(1, len(running_items)) |
| 3805 | running_item = running_items[0] |
| 3806 | self.assertEqual([], running_item['failing_reasons']) |
| 3807 | self.assertEqual([], running_item['items_behind']) |
| 3808 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3809 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3810 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3811 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3812 | self.assertEqual(True, running_item['active']) |
| 3813 | self.assertEqual('1,1', running_item['id']) |
| 3814 | |
| 3815 | self.assertEqual(3, len(running_item['jobs'])) |
| 3816 | for job in running_item['jobs']: |
| 3817 | if job['name'] == 'project-merge': |
| 3818 | self.assertEqual('project-merge', job['name']) |
| 3819 | self.assertEqual('gate', job['pipeline']) |
| 3820 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3821 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3822 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3823 | .format(uuid=job['uuid']), job['url']) |
| 3824 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3825 | 'finger://{hostname}/{uuid}'.format( |
| 3826 | hostname=self.executor_server.hostname, |
| 3827 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3828 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3829 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3830 | self.assertEqual(False, job['canceled']) |
| 3831 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3832 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3833 | self.assertEqual('gate', job['pipeline']) |
| 3834 | break |
| 3835 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3836 | self.executor_server.hold_jobs_in_build = False |
| 3837 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3838 | self.waitUntilSettled() |
| 3839 | |
| 3840 | running_items = client.get_running_jobs() |
| 3841 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3842 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3843 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3844 | def test_nonvoting_pipeline(self): |
| 3845 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3846 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3847 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3848 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3849 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3850 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3851 | |
| 3852 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3853 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3854 | self.assertEqual( |
| 3855 | self.getJobFromHistory('experimental-project-test').result, |
| 3856 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3857 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3858 | |
| 3859 | def test_crd_gate(self): |
| 3860 | "Test cross-repo dependencies" |
| 3861 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3862 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3863 | A.addApproval('Code-Review', 2) |
| 3864 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3865 | |
| 3866 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3867 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3868 | AM2.setMerged() |
| 3869 | AM1.setMerged() |
| 3870 | |
| 3871 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3872 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3873 | BM2.setMerged() |
| 3874 | BM1.setMerged() |
| 3875 | |
| 3876 | # A -> AM1 -> AM2 |
| 3877 | # B -> BM1 -> BM2 |
| 3878 | # A Depends-On: B |
| 3879 | # M2 is here to make sure it is never queried. If it is, it |
| 3880 | # means zuul is walking down the entire history of merged |
| 3881 | # changes. |
| 3882 | |
| 3883 | B.setDependsOn(BM1, 1) |
| 3884 | BM1.setDependsOn(BM2, 1) |
| 3885 | |
| 3886 | A.setDependsOn(AM1, 1) |
| 3887 | AM1.setDependsOn(AM2, 1) |
| 3888 | |
| 3889 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3890 | A.subject, B.data['id']) |
| 3891 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3892 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3893 | self.waitUntilSettled() |
| 3894 | |
| 3895 | self.assertEqual(A.data['status'], 'NEW') |
| 3896 | self.assertEqual(B.data['status'], 'NEW') |
| 3897 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3898 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3899 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3900 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3901 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3902 | B.addApproval('Approved', 1) |
| 3903 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3904 | self.waitUntilSettled() |
| 3905 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3906 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3907 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3908 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3909 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3910 | self.executor_server.hold_jobs_in_build = False |
| 3911 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3912 | self.waitUntilSettled() |
| 3913 | |
| 3914 | self.assertEqual(AM2.queried, 0) |
| 3915 | self.assertEqual(BM2.queried, 0) |
| 3916 | self.assertEqual(A.data['status'], 'MERGED') |
| 3917 | self.assertEqual(B.data['status'], 'MERGED') |
| 3918 | self.assertEqual(A.reported, 2) |
| 3919 | self.assertEqual(B.reported, 2) |
| 3920 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3921 | changes = self.getJobFromHistory( |
| 3922 | 'project-merge', 'org/project1').changes |
| 3923 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3924 | |
| 3925 | def test_crd_branch(self): |
| 3926 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3927 | |
| 3928 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3929 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3930 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3931 | C1 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C1') |
| 3932 | C2 = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C2', |
| 3933 | status='ABANDONED') |
| 3934 | C1.data['id'] = B.data['id'] |
| 3935 | C2.data['id'] = B.data['id'] |
| 3936 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3937 | A.addApproval('Code-Review', 2) |
| 3938 | B.addApproval('Code-Review', 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3939 | C1.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3940 | |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3941 | # A Depends-On: B+C1 |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3942 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3943 | A.subject, B.data['id']) |
| 3944 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3945 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3946 | B.addApproval('Approved', 1) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3947 | C1.addApproval('Approved', 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3948 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3949 | self.waitUntilSettled() |
| 3950 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3951 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3952 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3953 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3954 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3955 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3956 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3957 | self.executor_server.hold_jobs_in_build = False |
| 3958 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3959 | self.waitUntilSettled() |
| 3960 | |
| 3961 | self.assertEqual(A.data['status'], 'MERGED') |
| 3962 | self.assertEqual(B.data['status'], 'MERGED') |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3963 | self.assertEqual(C1.data['status'], 'MERGED') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3964 | self.assertEqual(A.reported, 2) |
| 3965 | self.assertEqual(B.reported, 2) |
K Jonathan Harker | d1d51d2 | 2017-08-23 11:57:40 -0400 | [diff] [blame] | 3966 | self.assertEqual(C1.reported, 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3967 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3968 | changes = self.getJobFromHistory( |
| 3969 | 'project-merge', 'org/project1').changes |
| 3970 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3971 | |
| 3972 | def test_crd_multiline(self): |
| 3973 | "Test multiple depends-on lines in commit" |
| 3974 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3975 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3976 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3977 | A.addApproval('Code-Review', 2) |
| 3978 | B.addApproval('Code-Review', 2) |
| 3979 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3980 | |
| 3981 | # A Depends-On: B+C |
| 3982 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3983 | A.subject, B.data['id'], C.data['id']) |
| 3984 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3985 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3986 | B.addApproval('Approved', 1) |
| 3987 | C.addApproval('Approved', 1) |
| 3988 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3989 | self.waitUntilSettled() |
| 3990 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3991 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3992 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3993 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3994 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3995 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3996 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3997 | self.executor_server.hold_jobs_in_build = False |
| 3998 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3999 | self.waitUntilSettled() |
| 4000 | |
| 4001 | self.assertEqual(A.data['status'], 'MERGED') |
| 4002 | self.assertEqual(B.data['status'], 'MERGED') |
| 4003 | self.assertEqual(C.data['status'], 'MERGED') |
| 4004 | self.assertEqual(A.reported, 2) |
| 4005 | self.assertEqual(B.reported, 2) |
| 4006 | self.assertEqual(C.reported, 2) |
| 4007 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4008 | changes = self.getJobFromHistory( |
| 4009 | 'project-merge', 'org/project1').changes |
| 4010 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4011 | |
| 4012 | def test_crd_unshared_gate(self): |
| 4013 | "Test cross-repo dependencies in unshared gate queues" |
| 4014 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4015 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4016 | A.addApproval('Code-Review', 2) |
| 4017 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4018 | |
| 4019 | # A Depends-On: B |
| 4020 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4021 | A.subject, B.data['id']) |
| 4022 | |
| 4023 | # A and B do not share a queue, make sure that A is unable to |
| 4024 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4025 | B.addApproval('Approved', 1) |
| 4026 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4027 | self.waitUntilSettled() |
| 4028 | |
| 4029 | self.assertEqual(A.data['status'], 'NEW') |
| 4030 | self.assertEqual(B.data['status'], 'NEW') |
| 4031 | self.assertEqual(A.reported, 0) |
| 4032 | self.assertEqual(B.reported, 0) |
| 4033 | self.assertEqual(len(self.history), 0) |
| 4034 | |
| 4035 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4036 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4037 | self.waitUntilSettled() |
| 4038 | |
| 4039 | self.assertEqual(B.data['status'], 'MERGED') |
| 4040 | self.assertEqual(B.reported, 2) |
| 4041 | |
| 4042 | # Now that B is merged, A should be able to be enqueued and |
| 4043 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4044 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4045 | self.waitUntilSettled() |
| 4046 | |
| 4047 | self.assertEqual(A.data['status'], 'MERGED') |
| 4048 | self.assertEqual(A.reported, 2) |
| 4049 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4050 | def test_crd_gate_reverse(self): |
| 4051 | "Test reverse cross-repo dependencies" |
| 4052 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4053 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4054 | A.addApproval('Code-Review', 2) |
| 4055 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4056 | |
| 4057 | # A Depends-On: B |
| 4058 | |
| 4059 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4060 | A.subject, B.data['id']) |
| 4061 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4062 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4063 | self.waitUntilSettled() |
| 4064 | |
| 4065 | self.assertEqual(A.data['status'], 'NEW') |
| 4066 | self.assertEqual(B.data['status'], 'NEW') |
| 4067 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4068 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4069 | A.addApproval('Approved', 1) |
| 4070 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4071 | self.waitUntilSettled() |
| 4072 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4073 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4074 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4075 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4076 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4077 | self.executor_server.hold_jobs_in_build = False |
| 4078 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4079 | self.waitUntilSettled() |
| 4080 | |
| 4081 | self.assertEqual(A.data['status'], 'MERGED') |
| 4082 | self.assertEqual(B.data['status'], 'MERGED') |
| 4083 | self.assertEqual(A.reported, 2) |
| 4084 | self.assertEqual(B.reported, 2) |
| 4085 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 4086 | changes = self.getJobFromHistory( |
| 4087 | 'project-merge', 'org/project1').changes |
| 4088 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4089 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4090 | def test_crd_cycle(self): |
| 4091 | "Test cross-repo dependency cycles" |
| 4092 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4093 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4094 | A.addApproval('Code-Review', 2) |
| 4095 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4096 | |
| 4097 | # A -> B -> A (via commit-depends) |
| 4098 | |
| 4099 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4100 | A.subject, B.data['id']) |
| 4101 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4102 | B.subject, A.data['id']) |
| 4103 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4104 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4105 | self.waitUntilSettled() |
| 4106 | |
| 4107 | self.assertEqual(A.reported, 0) |
| 4108 | self.assertEqual(B.reported, 0) |
| 4109 | self.assertEqual(A.data['status'], 'NEW') |
| 4110 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4111 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4112 | def test_crd_gate_unknown(self): |
| 4113 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4114 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4115 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4116 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4117 | A.addApproval('Code-Review', 2) |
| 4118 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4119 | |
| 4120 | # A Depends-On: B |
| 4121 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4122 | A.subject, B.data['id']) |
| 4123 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4124 | B.addApproval('Approved', 1) |
| 4125 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4126 | self.waitUntilSettled() |
| 4127 | |
| 4128 | # Unknown projects cannot share a queue with any other |
| 4129 | # since they don't have common jobs with any other (they have no jobs). |
| 4130 | # Changes which depend on unknown project changes |
| 4131 | # should not be processed in dependent pipeline |
| 4132 | self.assertEqual(A.data['status'], 'NEW') |
| 4133 | self.assertEqual(B.data['status'], 'NEW') |
| 4134 | self.assertEqual(A.reported, 0) |
| 4135 | self.assertEqual(B.reported, 0) |
| 4136 | self.assertEqual(len(self.history), 0) |
| 4137 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4138 | # Simulate change B being gated outside this layout Set the |
| 4139 | # change merged before submitting the event so that when the |
| 4140 | # event triggers a gerrit query to update the change, we get |
| 4141 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4142 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4143 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4144 | self.waitUntilSettled() |
| 4145 | self.assertEqual(len(self.history), 0) |
| 4146 | |
| 4147 | # Now that B is merged, A should be able to be enqueued and |
| 4148 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4149 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4150 | self.waitUntilSettled() |
| 4151 | |
| 4152 | self.assertEqual(A.data['status'], 'MERGED') |
| 4153 | self.assertEqual(A.reported, 2) |
| 4154 | self.assertEqual(B.data['status'], 'MERGED') |
| 4155 | self.assertEqual(B.reported, 0) |
| 4156 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4157 | def test_crd_check(self): |
| 4158 | "Test cross-repo dependencies in independent pipelines" |
| 4159 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4160 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4161 | self.gearman_server.hold_jobs_in_queue = True |
| 4162 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4163 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4164 | |
| 4165 | # A Depends-On: B |
| 4166 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4167 | A.subject, B.data['id']) |
| 4168 | |
| 4169 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4170 | self.waitUntilSettled() |
| 4171 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4172 | self.gearman_server.hold_jobs_in_queue = False |
| 4173 | self.gearman_server.release() |
| 4174 | self.waitUntilSettled() |
| 4175 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4176 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4177 | self.waitUntilSettled() |
| 4178 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4179 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4180 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4181 | self.executor_server.hold_jobs_in_build = False |
| 4182 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4183 | self.waitUntilSettled() |
| 4184 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4185 | self.assertEqual(A.data['status'], 'NEW') |
| 4186 | self.assertEqual(B.data['status'], 'NEW') |
| 4187 | self.assertEqual(A.reported, 1) |
| 4188 | self.assertEqual(B.reported, 0) |
| 4189 | |
| 4190 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4191 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4192 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4193 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4194 | def test_crd_check_git_depends(self): |
| 4195 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4196 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4197 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4198 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4199 | |
| 4200 | # Add two git-dependent changes and make sure they both report |
| 4201 | # success. |
| 4202 | B.setDependsOn(A, 1) |
| 4203 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4204 | self.waitUntilSettled() |
| 4205 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4206 | self.waitUntilSettled() |
| 4207 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4208 | self.orderedRelease() |
| 4209 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4210 | self.waitUntilSettled() |
| 4211 | |
| 4212 | self.assertEqual(A.data['status'], 'NEW') |
| 4213 | self.assertEqual(B.data['status'], 'NEW') |
| 4214 | self.assertEqual(A.reported, 1) |
| 4215 | self.assertEqual(B.reported, 1) |
| 4216 | |
| 4217 | self.assertEqual(self.history[0].changes, '1,1') |
| 4218 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4219 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4220 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4221 | |
| 4222 | self.assertIn('Build succeeded', A.messages[0]) |
| 4223 | self.assertIn('Build succeeded', B.messages[0]) |
| 4224 | |
| 4225 | def test_crd_check_duplicate(self): |
| 4226 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4227 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4228 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4229 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4230 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4231 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4232 | |
| 4233 | # Add two git-dependent changes... |
| 4234 | B.setDependsOn(A, 1) |
| 4235 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4236 | self.waitUntilSettled() |
| 4237 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4238 | |
| 4239 | # ...make sure the live one is not duplicated... |
| 4240 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4241 | self.waitUntilSettled() |
| 4242 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4243 | |
| 4244 | # ...but the non-live one is able to be. |
| 4245 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4246 | self.waitUntilSettled() |
| 4247 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4248 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4249 | # Release jobs in order to avoid races with change A jobs |
| 4250 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4251 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4252 | self.executor_server.hold_jobs_in_build = False |
| 4253 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4254 | self.waitUntilSettled() |
| 4255 | |
| 4256 | self.assertEqual(A.data['status'], 'NEW') |
| 4257 | self.assertEqual(B.data['status'], 'NEW') |
| 4258 | self.assertEqual(A.reported, 1) |
| 4259 | self.assertEqual(B.reported, 1) |
| 4260 | |
| 4261 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4262 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4263 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4264 | |
| 4265 | self.assertIn('Build succeeded', A.messages[0]) |
| 4266 | self.assertIn('Build succeeded', B.messages[0]) |
| 4267 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4268 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4269 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4270 | |
| 4271 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4272 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4273 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4274 | |
| 4275 | # A Depends-On: B |
| 4276 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4277 | A.subject, B.data['id']) |
| 4278 | |
| 4279 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4280 | self.waitUntilSettled() |
| 4281 | |
| 4282 | self.sched.reconfigure(self.config) |
| 4283 | |
| 4284 | # Make sure the items still share a change queue, and the |
| 4285 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4286 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4287 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4288 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4289 | first_item = queue.queue[0] |
| 4290 | for item in queue.queue: |
| 4291 | self.assertEqual(item.queue, first_item.queue) |
| 4292 | self.assertFalse(first_item.live) |
| 4293 | self.assertTrue(queue.queue[1].live) |
| 4294 | |
| 4295 | self.gearman_server.hold_jobs_in_queue = False |
| 4296 | self.gearman_server.release() |
| 4297 | self.waitUntilSettled() |
| 4298 | |
| 4299 | self.assertEqual(A.data['status'], 'NEW') |
| 4300 | self.assertEqual(B.data['status'], 'NEW') |
| 4301 | self.assertEqual(A.reported, 1) |
| 4302 | self.assertEqual(B.reported, 0) |
| 4303 | |
| 4304 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4305 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4306 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4307 | def test_crd_check_reconfiguration(self): |
| 4308 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4309 | |
| 4310 | def test_crd_undefined_project(self): |
| 4311 | """Test that undefined projects in dependencies are handled for |
| 4312 | independent pipelines""" |
| 4313 | # It's a hack for fake gerrit, |
| 4314 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4315 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4316 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4317 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4318 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4319 | def test_crd_check_ignore_dependencies(self): |
| 4320 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4321 | |
| 4322 | self.gearman_server.hold_jobs_in_queue = True |
| 4323 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4324 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4325 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4326 | |
| 4327 | # A Depends-On: B |
| 4328 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4329 | A.subject, B.data['id']) |
| 4330 | # C git-depends on B |
| 4331 | C.setDependsOn(B, 1) |
| 4332 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4333 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4334 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4335 | self.waitUntilSettled() |
| 4336 | |
| 4337 | # Make sure none of the items share a change queue, and all |
| 4338 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4339 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4340 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4341 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4342 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4343 | for item in check_pipeline.getAllItems(): |
| 4344 | self.assertTrue(item.live) |
| 4345 | |
| 4346 | self.gearman_server.hold_jobs_in_queue = False |
| 4347 | self.gearman_server.release() |
| 4348 | self.waitUntilSettled() |
| 4349 | |
| 4350 | self.assertEqual(A.data['status'], 'NEW') |
| 4351 | self.assertEqual(B.data['status'], 'NEW') |
| 4352 | self.assertEqual(C.data['status'], 'NEW') |
| 4353 | self.assertEqual(A.reported, 1) |
| 4354 | self.assertEqual(B.reported, 1) |
| 4355 | self.assertEqual(C.reported, 1) |
| 4356 | |
| 4357 | # Each job should have tested exactly one change |
| 4358 | for job in self.history: |
| 4359 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4360 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4361 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4362 | def test_crd_check_transitive(self): |
| 4363 | "Test transitive cross-repo dependencies" |
| 4364 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4365 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4366 | # and C,2 (not C,1 which would indicate stale data in the |
| 4367 | # cache for B). |
| 4368 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4369 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4370 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4371 | |
| 4372 | # A Depends-On: B |
| 4373 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4374 | A.subject, B.data['id']) |
| 4375 | |
| 4376 | # B Depends-On: C |
| 4377 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4378 | B.subject, C.data['id']) |
| 4379 | |
| 4380 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4381 | self.waitUntilSettled() |
| 4382 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4383 | |
| 4384 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4385 | self.waitUntilSettled() |
| 4386 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4387 | |
| 4388 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4389 | self.waitUntilSettled() |
| 4390 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4391 | |
| 4392 | C.addPatchset() |
| 4393 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4394 | self.waitUntilSettled() |
| 4395 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4396 | |
| 4397 | A.addPatchset() |
| 4398 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4399 | self.waitUntilSettled() |
| 4400 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4401 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4402 | def test_crd_check_unknown(self): |
| 4403 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4404 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4405 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4406 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4407 | # A Depends-On: B |
| 4408 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4409 | A.subject, B.data['id']) |
| 4410 | |
| 4411 | # Make sure zuul has seen an event on B. |
| 4412 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4413 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4414 | self.waitUntilSettled() |
| 4415 | |
| 4416 | self.assertEqual(A.data['status'], 'NEW') |
| 4417 | self.assertEqual(A.reported, 1) |
| 4418 | self.assertEqual(B.data['status'], 'NEW') |
| 4419 | self.assertEqual(B.reported, 0) |
| 4420 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4421 | def test_crd_cycle_join(self): |
| 4422 | "Test an updated change creates a cycle" |
| 4423 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4424 | |
| 4425 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4426 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4427 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4428 | |
| 4429 | # Create B->A |
| 4430 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4431 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4432 | B.subject, A.data['id']) |
| 4433 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4434 | self.waitUntilSettled() |
| 4435 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4436 | # Dep is there so zuul should have reported on B |
| 4437 | self.assertEqual(B.reported, 1) |
| 4438 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4439 | # Update A to add A->B (a cycle). |
| 4440 | A.addPatchset() |
| 4441 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4442 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4443 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4444 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4445 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4446 | # Dependency cycle injected so zuul should not have reported again on A |
| 4447 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4448 | |
| 4449 | # Now if we update B to remove the depends-on, everything |
| 4450 | # should be okay. B; A->B |
| 4451 | |
| 4452 | B.addPatchset() |
| 4453 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4454 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4455 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4456 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4457 | # Cycle was removed so now zuul should have reported again on A |
| 4458 | self.assertEqual(A.reported, 2) |
| 4459 | |
| 4460 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4461 | self.waitUntilSettled() |
| 4462 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4463 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4464 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4465 | def test_disable_at(self): |
| 4466 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4467 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4468 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4469 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4470 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4471 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4472 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4473 | |
| 4474 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4475 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4476 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4477 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4478 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4479 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4480 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4481 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4482 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4483 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4484 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4485 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4486 | self.executor_server.failJob('project-test1', A) |
| 4487 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4488 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4489 | self.executor_server.failJob('project-test1', D) |
| 4490 | self.executor_server.failJob('project-test1', E) |
| 4491 | self.executor_server.failJob('project-test1', F) |
| 4492 | self.executor_server.failJob('project-test1', G) |
| 4493 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4494 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4495 | self.executor_server.failJob('project-test1', J) |
| 4496 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4497 | |
| 4498 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4499 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4500 | self.waitUntilSettled() |
| 4501 | |
| 4502 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4503 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4504 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4505 | |
| 4506 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4507 | self.waitUntilSettled() |
| 4508 | |
| 4509 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4510 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4511 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4512 | |
| 4513 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4514 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4515 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4516 | self.waitUntilSettled() |
| 4517 | |
| 4518 | # We should be disabled now |
| 4519 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4520 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4521 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4522 | |
| 4523 | # We need to wait between each of these patches to make sure the |
| 4524 | # smtp messages come back in an expected order |
| 4525 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4526 | self.waitUntilSettled() |
| 4527 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4528 | self.waitUntilSettled() |
| 4529 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4530 | self.waitUntilSettled() |
| 4531 | |
| 4532 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4533 | # leaving a message on each change |
| 4534 | self.assertEqual(1, len(A.messages)) |
| 4535 | self.assertIn('Build failed.', A.messages[0]) |
| 4536 | self.assertEqual(1, len(B.messages)) |
| 4537 | self.assertIn('Build failed.', B.messages[0]) |
| 4538 | self.assertEqual(1, len(C.messages)) |
| 4539 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4540 | self.assertEqual(1, len(D.messages)) |
| 4541 | self.assertIn('Build failed.', D.messages[0]) |
| 4542 | self.assertEqual(1, len(E.messages)) |
| 4543 | self.assertIn('Build failed.', E.messages[0]) |
| 4544 | self.assertEqual(1, len(F.messages)) |
| 4545 | self.assertIn('Build failed.', F.messages[0]) |
| 4546 | |
| 4547 | # The last 3 (GHI) would have only reported via smtp. |
| 4548 | self.assertEqual(3, len(self.smtp_messages)) |
| 4549 | self.assertEqual(0, len(G.messages)) |
| 4550 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4551 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4552 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4553 | self.assertEqual(0, len(H.messages)) |
| 4554 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4555 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4556 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4557 | self.assertEqual(0, len(I.messages)) |
| 4558 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4559 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4560 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4561 | |
| 4562 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4563 | # comes out of disabled |
| 4564 | self.sched.reconfigure(self.config) |
| 4565 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4566 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4567 | |
| 4568 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4569 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4570 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4571 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4572 | |
| 4573 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4574 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4575 | self.waitUntilSettled() |
| 4576 | |
| 4577 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4578 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4579 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4580 | |
| 4581 | # J and K went back to gerrit |
| 4582 | self.assertEqual(1, len(J.messages)) |
| 4583 | self.assertIn('Build failed.', J.messages[0]) |
| 4584 | self.assertEqual(1, len(K.messages)) |
| 4585 | self.assertIn('Build failed.', K.messages[0]) |
| 4586 | # No more messages reported via smtp |
| 4587 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4588 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4589 | @simple_layout('layouts/one-job-project.yaml') |
| 4590 | def test_one_job_project(self): |
| 4591 | "Test that queueing works with one job" |
| 4592 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4593 | 'master', 'A') |
| 4594 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4595 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4596 | A.addApproval('Code-Review', 2) |
| 4597 | B.addApproval('Code-Review', 2) |
| 4598 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4599 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4600 | self.waitUntilSettled() |
| 4601 | |
| 4602 | self.assertEqual(A.data['status'], 'MERGED') |
| 4603 | self.assertEqual(A.reported, 2) |
| 4604 | self.assertEqual(B.data['status'], 'MERGED') |
| 4605 | self.assertEqual(B.reported, 2) |
| 4606 | |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4607 | def test_job_aborted(self): |
| 4608 | "Test that if a execute server aborts a job, it is run again" |
| 4609 | self.executor_server.hold_jobs_in_build = True |
| 4610 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4611 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4612 | self.waitUntilSettled() |
| 4613 | |
| 4614 | self.executor_server.release('.*-merge') |
| 4615 | self.waitUntilSettled() |
| 4616 | |
| 4617 | self.assertEqual(len(self.builds), 2) |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4618 | |
| 4619 | # first abort |
| 4620 | self.builds[0].aborted = True |
| 4621 | self.executor_server.release('.*-test*') |
| 4622 | self.waitUntilSettled() |
| 4623 | self.assertEqual(len(self.builds), 1) |
| 4624 | |
| 4625 | # second abort |
| 4626 | self.builds[0].aborted = True |
| 4627 | self.executor_server.release('.*-test*') |
| 4628 | self.waitUntilSettled() |
| 4629 | self.assertEqual(len(self.builds), 1) |
| 4630 | |
| 4631 | # third abort |
| 4632 | self.builds[0].aborted = True |
| 4633 | self.executor_server.release('.*-test*') |
| 4634 | self.waitUntilSettled() |
| 4635 | self.assertEqual(len(self.builds), 1) |
| 4636 | |
| 4637 | # fourth abort |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4638 | self.builds[0].aborted = True |
| 4639 | self.executor_server.release('.*-test*') |
| 4640 | self.waitUntilSettled() |
| 4641 | self.assertEqual(len(self.builds), 1) |
| 4642 | |
| 4643 | self.executor_server.hold_jobs_in_build = False |
| 4644 | self.executor_server.release() |
| 4645 | self.waitUntilSettled() |
| 4646 | |
Tobias Henkel | 26fa8a3 | 2017-10-07 07:08:36 +0000 | [diff] [blame] | 4647 | self.assertEqual(len(self.history), 7) |
| 4648 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
Paul Belanger | 3202354 | 2017-10-06 14:48:50 -0400 | [diff] [blame] | 4649 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 4650 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4651 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4652 | "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] | 4653 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4654 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4655 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4656 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4657 | self.waitUntilSettled() |
| 4658 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4659 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4660 | self.waitUntilSettled() |
| 4661 | |
| 4662 | self.assertEqual(len(self.builds), 2) |
| 4663 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4664 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4665 | self.waitUntilSettled() |
| 4666 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4667 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4668 | self.assertEqual(len(self.builds), 1, |
| 4669 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4670 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4671 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4672 | self.waitUntilSettled() |
| 4673 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4674 | self.executor_server.hold_jobs_in_build = False |
| 4675 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4676 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4677 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4678 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4679 | self.assertEqual(A.reported, 1) |
| 4680 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4681 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4682 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4683 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4684 | |
| 4685 | self.fake_nodepool.paused = True |
| 4686 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4687 | A.addApproval('Code-Review', 2) |
| 4688 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4689 | self.waitUntilSettled() |
| 4690 | |
| 4691 | self.zk.client.stop() |
| 4692 | self.zk.client.start() |
| 4693 | self.fake_nodepool.paused = False |
| 4694 | self.waitUntilSettled() |
| 4695 | |
| 4696 | self.assertEqual(A.data['status'], 'MERGED') |
| 4697 | self.assertEqual(A.reported, 2) |
| 4698 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4699 | def test_nodepool_failure(self): |
| 4700 | "Test that jobs are reported after a nodepool failure" |
| 4701 | |
| 4702 | self.fake_nodepool.paused = True |
| 4703 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4704 | A.addApproval('Code-Review', 2) |
| 4705 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4706 | self.waitUntilSettled() |
| 4707 | |
| 4708 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4709 | self.fake_nodepool.addFailRequest(req) |
| 4710 | |
| 4711 | self.fake_nodepool.paused = False |
| 4712 | self.waitUntilSettled() |
| 4713 | |
| 4714 | self.assertEqual(A.data['status'], 'NEW') |
| 4715 | self.assertEqual(A.reported, 2) |
| 4716 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4717 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4718 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4719 | |
Monty Taylor | 6dc5bc1 | 2017-09-29 15:47:31 -0500 | [diff] [blame] | 4720 | def test_nodepool_priority(self): |
| 4721 | "Test that nodes are requested at the correct priority" |
| 4722 | |
| 4723 | self.fake_nodepool.paused = True |
| 4724 | |
| 4725 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4726 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4727 | |
| 4728 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4729 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4730 | |
| 4731 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4732 | C.addApproval('Code-Review', 2) |
| 4733 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 4734 | |
| 4735 | self.waitUntilSettled() |
| 4736 | |
| 4737 | reqs = self.fake_nodepool.getNodeRequests() |
| 4738 | |
| 4739 | # The requests come back sorted by oid. Since we have three requests |
| 4740 | # for the three changes each with a different priority. |
| 4741 | # Also they get a serial number based on order they were received |
| 4742 | # so the number on the endof the oid should map to order submitted. |
| 4743 | |
| 4744 | # * gate first - high priority - change C |
| 4745 | self.assertEqual(reqs[0]['_oid'], '100-0000000002') |
| 4746 | self.assertEqual(reqs[0]['node_types'], ['label1']) |
| 4747 | # * check second - normal priority - change B |
| 4748 | self.assertEqual(reqs[1]['_oid'], '200-0000000001') |
| 4749 | self.assertEqual(reqs[1]['node_types'], ['label1']) |
| 4750 | # * post third - low priority - change A |
| 4751 | # additionally, the post job defined uses an ubuntu-xenial node, |
| 4752 | # so we include that check just as an extra verification |
| 4753 | self.assertEqual(reqs[2]['_oid'], '300-0000000000') |
| 4754 | self.assertEqual(reqs[2]['node_types'], ['ubuntu-xenial']) |
| 4755 | |
| 4756 | self.fake_nodepool.paused = False |
| 4757 | self.waitUntilSettled() |
| 4758 | |
James E. Blair | fceaf41 | 2017-09-29 13:44:57 -0700 | [diff] [blame] | 4759 | @simple_layout('layouts/multiple-templates.yaml') |
| 4760 | def test_multiple_project_templates(self): |
| 4761 | # Test that applying multiple project templates to a project |
| 4762 | # doesn't alter them when used for a second project. |
| 4763 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4764 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4765 | self.waitUntilSettled() |
| 4766 | |
| 4767 | build = self.getJobFromHistory('py27') |
| 4768 | self.assertEqual(build.parameters['zuul']['jobtags'], []) |
| 4769 | |
James E. Blair | 29c7700 | 2017-10-05 14:56:35 -0700 | [diff] [blame] | 4770 | def test_pending_merge_in_reconfig(self): |
| 4771 | # Test that if we are waiting for an outstanding merge on |
| 4772 | # reconfiguration that we continue to do so. |
| 4773 | self.gearman_server.hold_merge_jobs_in_queue = True |
| 4774 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4775 | A.setMerged() |
| 4776 | self.fake_gerrit.addEvent(A.getRefUpdatedEvent()) |
| 4777 | self.waitUntilSettled() |
| 4778 | # Reconfigure while we still have an outstanding merge job |
| 4779 | self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'], |
| 4780 | None) |
| 4781 | self.waitUntilSettled() |
| 4782 | # Verify the merge job is still running and that the item is |
| 4783 | # in the pipeline |
| 4784 | self.assertEqual(len(self.sched.merger.jobs), 1) |
| 4785 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4786 | pipeline = tenant.layout.pipelines['post'] |
| 4787 | self.assertEqual(len(pipeline.getAllItems()), 1) |
| 4788 | self.gearman_server.hold_merge_jobs_in_queue = False |
| 4789 | self.gearman_server.release() |
| 4790 | self.waitUntilSettled() |
| 4791 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4792 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4793 | class TestExecutor(ZuulTestCase): |
| 4794 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4795 | |
| 4796 | def assertFinalState(self): |
| 4797 | # In this test, we expect to shut down in a non-final state, |
| 4798 | # so skip these checks. |
| 4799 | pass |
| 4800 | |
| 4801 | def assertCleanShutdown(self): |
| 4802 | self.log.debug("Assert clean shutdown") |
| 4803 | |
| 4804 | # After shutdown, make sure no jobs are running |
| 4805 | self.assertEqual({}, self.executor_server.job_workers) |
| 4806 | |
| 4807 | # Make sure that git.Repo objects have been garbage collected. |
| 4808 | repos = [] |
| 4809 | gc.collect() |
| 4810 | for obj in gc.get_objects(): |
| 4811 | if isinstance(obj, git.Repo): |
| 4812 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4813 | repos.append(obj) |
| 4814 | self.assertEqual(len(repos), 0) |
| 4815 | |
| 4816 | def test_executor_shutdown(self): |
| 4817 | "Test that the executor can shut down with jobs running" |
| 4818 | |
| 4819 | self.executor_server.hold_jobs_in_build = True |
| 4820 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4821 | A.addApproval('Code-Review', 2) |
| 4822 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4823 | self.waitUntilSettled() |
| 4824 | |
| 4825 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4826 | class TestDependencyGraph(ZuulTestCase): |
| 4827 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4828 | |
| 4829 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4830 | "Test a job in a dependency graph is queued only once" |
| 4831 | # Job dependencies, starting with A |
| 4832 | # A |
| 4833 | # / \ |
| 4834 | # B C |
| 4835 | # / \ / \ |
| 4836 | # D F E |
| 4837 | # | |
| 4838 | # G |
| 4839 | |
| 4840 | self.executor_server.hold_jobs_in_build = True |
| 4841 | change = self.fake_gerrit.addFakeChange( |
| 4842 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4843 | change.addApproval('Code-Review', 2) |
| 4844 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4845 | |
| 4846 | self.waitUntilSettled() |
| 4847 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4848 | |
| 4849 | self.executor_server.release('A') |
| 4850 | self.waitUntilSettled() |
| 4851 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4852 | |
| 4853 | self.executor_server.release('B') |
| 4854 | self.waitUntilSettled() |
| 4855 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4856 | |
| 4857 | self.executor_server.release('D') |
| 4858 | self.waitUntilSettled() |
| 4859 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4860 | |
| 4861 | self.executor_server.release('C') |
| 4862 | self.waitUntilSettled() |
| 4863 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4864 | |
| 4865 | self.executor_server.release('F') |
| 4866 | self.waitUntilSettled() |
| 4867 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4868 | |
| 4869 | self.executor_server.release('G') |
| 4870 | self.waitUntilSettled() |
| 4871 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4872 | |
| 4873 | self.executor_server.release('E') |
| 4874 | self.waitUntilSettled() |
| 4875 | self.assertEqual(len(self.builds), 0) |
| 4876 | |
| 4877 | self.executor_server.hold_jobs_in_build = False |
| 4878 | self.executor_server.release() |
| 4879 | self.waitUntilSettled() |
| 4880 | |
| 4881 | self.assertEqual(len(self.builds), 0) |
| 4882 | self.assertEqual(len(self.history), 7) |
| 4883 | |
| 4884 | self.assertEqual(change.data['status'], 'MERGED') |
| 4885 | self.assertEqual(change.reported, 2) |
| 4886 | |
| 4887 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4888 | "Test that a job waits till all dependencies are successful" |
| 4889 | # Job dependencies, starting with A |
| 4890 | # A |
| 4891 | # / \ |
| 4892 | # B C* |
| 4893 | # / \ / \ |
| 4894 | # D F E |
| 4895 | # | |
| 4896 | # G |
| 4897 | |
| 4898 | self.executor_server.hold_jobs_in_build = True |
| 4899 | change = self.fake_gerrit.addFakeChange( |
| 4900 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4901 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4902 | |
| 4903 | self.executor_server.failJob('C', change) |
| 4904 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4905 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4906 | |
| 4907 | self.waitUntilSettled() |
| 4908 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4909 | |
| 4910 | self.executor_server.release('A') |
| 4911 | self.waitUntilSettled() |
| 4912 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4913 | |
| 4914 | self.executor_server.release('B') |
| 4915 | self.waitUntilSettled() |
| 4916 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4917 | |
| 4918 | self.executor_server.release('D') |
| 4919 | self.waitUntilSettled() |
| 4920 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4921 | |
| 4922 | self.executor_server.release('C') |
| 4923 | self.waitUntilSettled() |
| 4924 | self.assertEqual(len(self.builds), 0) |
| 4925 | |
| 4926 | self.executor_server.hold_jobs_in_build = False |
| 4927 | self.executor_server.release() |
| 4928 | self.waitUntilSettled() |
| 4929 | |
| 4930 | self.assertEqual(len(self.builds), 0) |
| 4931 | self.assertEqual(len(self.history), 4) |
| 4932 | |
| 4933 | self.assertEqual(change.data['status'], 'NEW') |
| 4934 | self.assertEqual(change.reported, 2) |
| 4935 | |
| 4936 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4937 | class TestDuplicatePipeline(ZuulTestCase): |
| 4938 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4939 | |
| 4940 | def test_duplicate_pipelines(self): |
| 4941 | "Test that a change matching multiple pipelines works" |
| 4942 | |
| 4943 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4944 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4945 | self.waitUntilSettled() |
| 4946 | |
| 4947 | self.assertHistory([ |
| 4948 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4949 | pipeline='dup1'), |
| 4950 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4951 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4952 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4953 | |
| 4954 | self.assertEqual(len(A.messages), 2) |
| 4955 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4956 | if 'dup1' in A.messages[0]: |
| 4957 | self.assertIn('dup1', A.messages[0]) |
| 4958 | self.assertNotIn('dup2', A.messages[0]) |
| 4959 | self.assertIn('project-test1', A.messages[0]) |
| 4960 | self.assertIn('dup2', A.messages[1]) |
| 4961 | self.assertNotIn('dup1', A.messages[1]) |
| 4962 | self.assertIn('project-test1', A.messages[1]) |
| 4963 | else: |
| 4964 | self.assertIn('dup1', A.messages[1]) |
| 4965 | self.assertNotIn('dup2', A.messages[1]) |
| 4966 | self.assertIn('project-test1', A.messages[1]) |
| 4967 | self.assertIn('dup2', A.messages[0]) |
| 4968 | self.assertNotIn('dup1', A.messages[0]) |
| 4969 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4970 | |
| 4971 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4972 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4973 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4974 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4975 | def test_job_from_templates_executed(self): |
| 4976 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4977 | |
| 4978 | A = self.fake_gerrit.addFakeChange( |
| 4979 | 'org/templated-project', 'master', 'A') |
| 4980 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4981 | self.waitUntilSettled() |
| 4982 | |
| 4983 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4984 | 'SUCCESS') |
| 4985 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4986 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4987 | |
| 4988 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4989 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4990 | |
| 4991 | A = self.fake_gerrit.addFakeChange( |
| 4992 | 'org/layered-project', 'master', 'A') |
| 4993 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4994 | self.waitUntilSettled() |
| 4995 | |
| 4996 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4997 | 'SUCCESS') |
| 4998 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4999 | 'SUCCESS') |
| 5000 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 5001 | ).result, 'SUCCESS') |
| 5002 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 5003 | ).result, 'SUCCESS') |
| 5004 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 5005 | ).result, 'SUCCESS') |
| 5006 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 5007 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5008 | |
James E. Blair | e74f571 | 2017-09-29 15:14:31 -0700 | [diff] [blame] | 5009 | def test_unimplied_branch_matchers(self): |
| 5010 | # This tests that there are no implied branch matchers added |
| 5011 | # by project templates. |
| 5012 | self.create_branch('org/layered-project', 'stable') |
| 5013 | |
| 5014 | A = self.fake_gerrit.addFakeChange( |
| 5015 | 'org/layered-project', 'stable', 'A') |
| 5016 | |
| 5017 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5018 | self.waitUntilSettled() |
| 5019 | |
| 5020 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5021 | 'SUCCESS') |
| 5022 | print(self.getJobFromHistory('project-test1'). |
| 5023 | parameters['zuul']['_inheritance_path']) |
| 5024 | |
| 5025 | def test_implied_branch_matchers(self): |
| 5026 | # This tests that there is an implied branch matcher when a |
| 5027 | # template is used on an in-repo project pipeline definition. |
| 5028 | self.create_branch('untrusted-config', 'stable') |
| 5029 | self.fake_gerrit.addEvent( |
| 5030 | self.fake_gerrit.getFakeBranchCreatedEvent( |
| 5031 | 'untrusted-config', 'stable')) |
| 5032 | self.waitUntilSettled() |
| 5033 | |
| 5034 | A = self.fake_gerrit.addFakeChange( |
| 5035 | 'untrusted-config', 'stable', 'A') |
| 5036 | |
| 5037 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5038 | self.waitUntilSettled() |
| 5039 | |
| 5040 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5041 | 'SUCCESS') |
| 5042 | print(self.getJobFromHistory('project-test1'). |
| 5043 | parameters['zuul']['_inheritance_path']) |
| 5044 | |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5045 | |
| 5046 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 5047 | tenant_config_file = 'config/success-url/main.yaml' |
| 5048 | |
| 5049 | def test_success_url(self): |
| 5050 | "Ensure bad build params are ignored" |
| 5051 | self.sched.reconfigure(self.config) |
| 5052 | self.init_repo('org/docs') |
| 5053 | |
| 5054 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 5055 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5056 | self.waitUntilSettled() |
| 5057 | |
| 5058 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 5059 | self.assertEqual(len(self.history), 2) |
| 5060 | |
| 5061 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 5062 | for build in self.history: |
| 5063 | if build.name == 'docs-draft-test': |
| 5064 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5065 | elif build.name == 'docs-draft-test2': |
| 5066 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5067 | |
| 5068 | # Two msgs: 'Starting...' + results |
| 5069 | self.assertEqual(len(self.smtp_messages), 2) |
| 5070 | body = self.smtp_messages[1]['body'].splitlines() |
| 5071 | self.assertEqual('Build succeeded.', body[0]) |
| 5072 | |
| 5073 | self.assertIn( |
| 5074 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 5075 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 5076 | body[2]) |
| 5077 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5078 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5079 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 5080 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 5081 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 5082 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 5083 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5084 | |
| 5085 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5086 | class TestSchedulerMerges(ZuulTestCase): |
| 5087 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5088 | |
| 5089 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5090 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5091 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5092 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5093 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 5094 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 5095 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5096 | A.addApproval('Code-Review', 2) |
| 5097 | B.addApproval('Code-Review', 2) |
| 5098 | C.addApproval('Code-Review', 2) |
| 5099 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5100 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5101 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5102 | self.waitUntilSettled() |
| 5103 | |
| 5104 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5105 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5106 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5107 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5108 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5109 | repo_messages.reverse() |
| 5110 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5111 | self.executor_server.hold_jobs_in_build = False |
| 5112 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 5113 | self.waitUntilSettled() |
| 5114 | |
| 5115 | return repo_messages |
| 5116 | |
| 5117 | def _test_merge(self, mode): |
| 5118 | us_path = os.path.join( |
| 5119 | self.upstream_root, 'org/project-%s' % mode) |
| 5120 | expected_messages = [ |
| 5121 | 'initial commit', |
| 5122 | 'add content from fixture', |
| 5123 | # the intermediate commits order is nondeterministic |
| 5124 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 5125 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 5126 | ] |
| 5127 | result = self._test_project_merge_mode(mode) |
| 5128 | self.assertEqual(result[:2], expected_messages[:2]) |
| 5129 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 5130 | |
| 5131 | def test_project_merge_mode_merge(self): |
| 5132 | self._test_merge('merge') |
| 5133 | |
| 5134 | def test_project_merge_mode_merge_resolve(self): |
| 5135 | self._test_merge('merge-resolve') |
| 5136 | |
| 5137 | def test_project_merge_mode_cherrypick(self): |
| 5138 | expected_messages = [ |
| 5139 | 'initial commit', |
| 5140 | 'add content from fixture', |
| 5141 | 'A-1', |
| 5142 | 'B-1', |
| 5143 | 'C-1'] |
| 5144 | result = self._test_project_merge_mode('cherry-pick') |
| 5145 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5146 | |
| 5147 | def test_merge_branch(self): |
| 5148 | "Test that the right commits are on alternate branches" |
| 5149 | self.create_branch('org/project-merge-branches', 'mp') |
| 5150 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5151 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5152 | A = self.fake_gerrit.addFakeChange( |
| 5153 | 'org/project-merge-branches', 'mp', 'A') |
| 5154 | B = self.fake_gerrit.addFakeChange( |
| 5155 | 'org/project-merge-branches', 'mp', 'B') |
| 5156 | C = self.fake_gerrit.addFakeChange( |
| 5157 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5158 | A.addApproval('Code-Review', 2) |
| 5159 | B.addApproval('Code-Review', 2) |
| 5160 | C.addApproval('Code-Review', 2) |
| 5161 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5162 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5163 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5164 | self.waitUntilSettled() |
| 5165 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5166 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5167 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5168 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5169 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5170 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5171 | self.waitUntilSettled() |
| 5172 | |
| 5173 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 5174 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5175 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 5176 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5177 | repo = git.Repo(path) |
| 5178 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5179 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5180 | repo_messages.reverse() |
| 5181 | correct_messages = [ |
| 5182 | 'initial commit', |
| 5183 | 'add content from fixture', |
| 5184 | 'mp commit', |
| 5185 | 'A-1', 'B-1', 'C-1'] |
| 5186 | self.assertEqual(repo_messages, correct_messages) |
| 5187 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5188 | self.executor_server.hold_jobs_in_build = False |
| 5189 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5190 | self.waitUntilSettled() |
| 5191 | |
| 5192 | def test_merge_multi_branch(self): |
| 5193 | "Test that dependent changes on multiple branches are merged" |
| 5194 | self.create_branch('org/project-merge-branches', 'mp') |
| 5195 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5196 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5197 | A = self.fake_gerrit.addFakeChange( |
| 5198 | 'org/project-merge-branches', 'master', 'A') |
| 5199 | B = self.fake_gerrit.addFakeChange( |
| 5200 | 'org/project-merge-branches', 'mp', 'B') |
| 5201 | C = self.fake_gerrit.addFakeChange( |
| 5202 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5203 | A.addApproval('Code-Review', 2) |
| 5204 | B.addApproval('Code-Review', 2) |
| 5205 | C.addApproval('Code-Review', 2) |
| 5206 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5207 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5208 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5209 | self.waitUntilSettled() |
| 5210 | |
| 5211 | job_A = None |
| 5212 | for job in self.builds: |
| 5213 | if 'project-merge' in job.name: |
| 5214 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5215 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5216 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 5217 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5218 | repo = git.Repo(path) |
| 5219 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5220 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5221 | repo_messages.reverse() |
| 5222 | correct_messages = [ |
| 5223 | 'initial commit', 'add content from fixture', 'A-1'] |
| 5224 | self.assertEqual(repo_messages, correct_messages) |
| 5225 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5226 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5227 | self.waitUntilSettled() |
| 5228 | |
| 5229 | job_B = None |
| 5230 | for job in self.builds: |
| 5231 | if 'project-merge' in job.name: |
| 5232 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5233 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5234 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 5235 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5236 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5237 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5238 | repo_messages.reverse() |
| 5239 | correct_messages = [ |
| 5240 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 5241 | self.assertEqual(repo_messages, correct_messages) |
| 5242 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5243 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5244 | self.waitUntilSettled() |
| 5245 | |
| 5246 | job_C = None |
| 5247 | for job in self.builds: |
| 5248 | if 'project-merge' in job.name: |
| 5249 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5250 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5251 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5252 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5253 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5254 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5255 | |
| 5256 | repo_messages.reverse() |
| 5257 | correct_messages = [ |
| 5258 | 'initial commit', 'add content from fixture', |
| 5259 | 'A-1', 'C-1'] |
| 5260 | # Ensure the right commits are in the history for this ref |
| 5261 | self.assertEqual(repo_messages, correct_messages) |
| 5262 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5263 | self.executor_server.hold_jobs_in_build = False |
| 5264 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5265 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5266 | |
| 5267 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5268 | class TestSemaphore(ZuulTestCase): |
| 5269 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5270 | |
| 5271 | def test_semaphore_one(self): |
| 5272 | "Test semaphores with max=1 (mutex)" |
| 5273 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5274 | |
| 5275 | self.executor_server.hold_jobs_in_build = True |
| 5276 | |
| 5277 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5278 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5279 | self.assertFalse('test-semaphore' in |
| 5280 | tenant.semaphore_handler.semaphores) |
| 5281 | |
| 5282 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5283 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5284 | self.waitUntilSettled() |
| 5285 | |
| 5286 | self.assertEqual(len(self.builds), 3) |
| 5287 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5288 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5289 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5290 | |
| 5291 | self.executor_server.release('semaphore-one-test1') |
| 5292 | self.waitUntilSettled() |
| 5293 | |
| 5294 | self.assertEqual(len(self.builds), 3) |
| 5295 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5296 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5297 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5298 | self.assertTrue('test-semaphore' in |
| 5299 | tenant.semaphore_handler.semaphores) |
| 5300 | |
| 5301 | self.executor_server.release('semaphore-one-test2') |
| 5302 | self.waitUntilSettled() |
| 5303 | |
| 5304 | self.assertEqual(len(self.builds), 3) |
| 5305 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5306 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5307 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5308 | self.assertTrue('test-semaphore' in |
| 5309 | tenant.semaphore_handler.semaphores) |
| 5310 | |
| 5311 | self.executor_server.release('semaphore-one-test1') |
| 5312 | self.waitUntilSettled() |
| 5313 | |
| 5314 | self.assertEqual(len(self.builds), 3) |
| 5315 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5316 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5317 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5318 | self.assertTrue('test-semaphore' in |
| 5319 | tenant.semaphore_handler.semaphores) |
| 5320 | |
| 5321 | self.executor_server.release('semaphore-one-test2') |
| 5322 | self.waitUntilSettled() |
| 5323 | |
| 5324 | self.assertEqual(len(self.builds), 2) |
| 5325 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5326 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5327 | self.assertFalse('test-semaphore' in |
| 5328 | tenant.semaphore_handler.semaphores) |
| 5329 | |
| 5330 | self.executor_server.hold_jobs_in_build = False |
| 5331 | self.executor_server.release() |
| 5332 | |
| 5333 | self.waitUntilSettled() |
| 5334 | self.assertEqual(len(self.builds), 0) |
| 5335 | |
| 5336 | self.assertEqual(A.reported, 1) |
| 5337 | self.assertEqual(B.reported, 1) |
| 5338 | self.assertFalse('test-semaphore' in |
| 5339 | tenant.semaphore_handler.semaphores) |
| 5340 | |
| 5341 | def test_semaphore_two(self): |
| 5342 | "Test semaphores with max>1" |
| 5343 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5344 | |
| 5345 | self.executor_server.hold_jobs_in_build = True |
| 5346 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5347 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5348 | self.assertFalse('test-semaphore-two' in |
| 5349 | tenant.semaphore_handler.semaphores) |
| 5350 | |
| 5351 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5352 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5353 | self.waitUntilSettled() |
| 5354 | |
| 5355 | self.assertEqual(len(self.builds), 4) |
| 5356 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5357 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5358 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5359 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5360 | self.assertTrue('test-semaphore-two' in |
| 5361 | tenant.semaphore_handler.semaphores) |
| 5362 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5363 | 'test-semaphore-two', [])), 2) |
| 5364 | |
| 5365 | self.executor_server.release('semaphore-two-test1') |
| 5366 | self.waitUntilSettled() |
| 5367 | |
| 5368 | self.assertEqual(len(self.builds), 4) |
| 5369 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5370 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5371 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5372 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5373 | self.assertTrue('test-semaphore-two' in |
| 5374 | tenant.semaphore_handler.semaphores) |
| 5375 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5376 | 'test-semaphore-two', [])), 2) |
| 5377 | |
| 5378 | self.executor_server.release('semaphore-two-test2') |
| 5379 | self.waitUntilSettled() |
| 5380 | |
| 5381 | self.assertEqual(len(self.builds), 4) |
| 5382 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5383 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5384 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5385 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5386 | self.assertTrue('test-semaphore-two' in |
| 5387 | tenant.semaphore_handler.semaphores) |
| 5388 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5389 | 'test-semaphore-two', [])), 2) |
| 5390 | |
| 5391 | self.executor_server.release('semaphore-two-test1') |
| 5392 | self.waitUntilSettled() |
| 5393 | |
| 5394 | self.assertEqual(len(self.builds), 3) |
| 5395 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5396 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5397 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5398 | self.assertTrue('test-semaphore-two' in |
| 5399 | tenant.semaphore_handler.semaphores) |
| 5400 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5401 | 'test-semaphore-two', [])), 1) |
| 5402 | |
| 5403 | self.executor_server.release('semaphore-two-test2') |
| 5404 | self.waitUntilSettled() |
| 5405 | |
| 5406 | self.assertEqual(len(self.builds), 2) |
| 5407 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5408 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5409 | self.assertFalse('test-semaphore-two' in |
| 5410 | tenant.semaphore_handler.semaphores) |
| 5411 | |
| 5412 | self.executor_server.hold_jobs_in_build = False |
| 5413 | self.executor_server.release() |
| 5414 | |
| 5415 | self.waitUntilSettled() |
| 5416 | self.assertEqual(len(self.builds), 0) |
| 5417 | |
| 5418 | self.assertEqual(A.reported, 1) |
| 5419 | self.assertEqual(B.reported, 1) |
| 5420 | |
| 5421 | def test_semaphore_abandon(self): |
| 5422 | "Test abandon with job semaphores" |
| 5423 | self.executor_server.hold_jobs_in_build = True |
| 5424 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5425 | check_pipeline = tenant.layout.pipelines['check'] |
| 5426 | |
| 5427 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5428 | self.assertFalse('test-semaphore' in |
| 5429 | tenant.semaphore_handler.semaphores) |
| 5430 | |
| 5431 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5432 | self.waitUntilSettled() |
| 5433 | |
| 5434 | self.assertTrue('test-semaphore' in |
| 5435 | tenant.semaphore_handler.semaphores) |
| 5436 | |
| 5437 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5438 | self.waitUntilSettled() |
| 5439 | |
| 5440 | # The check pipeline should be empty |
| 5441 | items = check_pipeline.getAllItems() |
| 5442 | self.assertEqual(len(items), 0) |
| 5443 | |
| 5444 | # The semaphore should be released |
| 5445 | self.assertFalse('test-semaphore' in |
| 5446 | tenant.semaphore_handler.semaphores) |
| 5447 | |
| 5448 | self.executor_server.hold_jobs_in_build = False |
| 5449 | self.executor_server.release() |
| 5450 | self.waitUntilSettled() |
| 5451 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5452 | def test_semaphore_new_patchset(self): |
| 5453 | "Test new patchset with job semaphores" |
| 5454 | self.executor_server.hold_jobs_in_build = True |
| 5455 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5456 | check_pipeline = tenant.layout.pipelines['check'] |
| 5457 | |
| 5458 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5459 | self.assertFalse('test-semaphore' in |
| 5460 | tenant.semaphore_handler.semaphores) |
| 5461 | |
| 5462 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5463 | self.waitUntilSettled() |
| 5464 | |
| 5465 | self.assertTrue('test-semaphore' in |
| 5466 | tenant.semaphore_handler.semaphores) |
| 5467 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5468 | self.assertEqual(len(semaphore), 1) |
| 5469 | |
| 5470 | A.addPatchset() |
| 5471 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5472 | self.waitUntilSettled() |
| 5473 | |
| 5474 | self.assertTrue('test-semaphore' in |
| 5475 | tenant.semaphore_handler.semaphores) |
| 5476 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5477 | self.assertEqual(len(semaphore), 1) |
| 5478 | |
| 5479 | items = check_pipeline.getAllItems() |
| 5480 | self.assertEqual(items[0].change.number, '1') |
| 5481 | self.assertEqual(items[0].change.patchset, '2') |
| 5482 | self.assertTrue(items[0].live) |
| 5483 | |
| 5484 | self.executor_server.hold_jobs_in_build = False |
| 5485 | self.executor_server.release() |
| 5486 | self.waitUntilSettled() |
| 5487 | |
| 5488 | # The semaphore should be released |
| 5489 | self.assertFalse('test-semaphore' in |
| 5490 | tenant.semaphore_handler.semaphores) |
| 5491 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5492 | def test_semaphore_reconfigure(self): |
| 5493 | "Test reconfigure with job semaphores" |
| 5494 | self.executor_server.hold_jobs_in_build = True |
| 5495 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5496 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5497 | self.assertFalse('test-semaphore' in |
| 5498 | tenant.semaphore_handler.semaphores) |
| 5499 | |
| 5500 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5501 | self.waitUntilSettled() |
| 5502 | |
| 5503 | self.assertTrue('test-semaphore' in |
| 5504 | tenant.semaphore_handler.semaphores) |
| 5505 | |
| 5506 | # reconfigure without layout change |
| 5507 | self.sched.reconfigure(self.config) |
| 5508 | self.waitUntilSettled() |
| 5509 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5510 | |
| 5511 | # semaphore still must be held |
| 5512 | self.assertTrue('test-semaphore' in |
| 5513 | tenant.semaphore_handler.semaphores) |
| 5514 | |
| 5515 | self.commitConfigUpdate( |
| 5516 | 'common-config', |
| 5517 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5518 | self.sched.reconfigure(self.config) |
| 5519 | self.waitUntilSettled() |
| 5520 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5521 | |
| 5522 | self.executor_server.release('project-test1') |
| 5523 | self.waitUntilSettled() |
| 5524 | |
| 5525 | # There should be no builds anymore |
| 5526 | self.assertEqual(len(self.builds), 0) |
| 5527 | |
| 5528 | # The semaphore should be released |
| 5529 | self.assertFalse('test-semaphore' in |
| 5530 | tenant.semaphore_handler.semaphores) |
| 5531 | |
| 5532 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5533 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5534 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5535 | |
| 5536 | def test_semaphore_tenant_isolation(self): |
| 5537 | "Test semaphores in multiple tenants" |
| 5538 | |
| 5539 | self.waitUntilSettled() |
| 5540 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5541 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5542 | |
| 5543 | self.executor_server.hold_jobs_in_build = True |
| 5544 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5545 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5546 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5547 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5548 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5549 | self.assertFalse('test-semaphore' in |
| 5550 | tenant_one.semaphore_handler.semaphores) |
| 5551 | self.assertFalse('test-semaphore' in |
| 5552 | tenant_two.semaphore_handler.semaphores) |
| 5553 | |
| 5554 | # add patches to project1 of tenant-one |
| 5555 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5556 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5557 | self.waitUntilSettled() |
| 5558 | |
| 5559 | # one build of project1-test1 must run |
| 5560 | # semaphore of tenant-one must be acquired once |
| 5561 | # semaphore of tenant-two must not be acquired |
| 5562 | self.assertEqual(len(self.builds), 1) |
| 5563 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5564 | self.assertTrue('test-semaphore' in |
| 5565 | tenant_one.semaphore_handler.semaphores) |
| 5566 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5567 | 'test-semaphore', [])), 1) |
| 5568 | self.assertFalse('test-semaphore' in |
| 5569 | tenant_two.semaphore_handler.semaphores) |
| 5570 | |
| 5571 | # add patches to project2 of tenant-two |
| 5572 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5573 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5574 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5575 | self.waitUntilSettled() |
| 5576 | |
| 5577 | # one build of project1-test1 must run |
| 5578 | # two builds of project2-test1 must run |
| 5579 | # semaphore of tenant-one must be acquired once |
| 5580 | # semaphore of tenant-two must be acquired twice |
| 5581 | self.assertEqual(len(self.builds), 3) |
| 5582 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5583 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5584 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5585 | self.assertTrue('test-semaphore' in |
| 5586 | tenant_one.semaphore_handler.semaphores) |
| 5587 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5588 | 'test-semaphore', [])), 1) |
| 5589 | self.assertTrue('test-semaphore' in |
| 5590 | tenant_two.semaphore_handler.semaphores) |
| 5591 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5592 | 'test-semaphore', [])), 2) |
| 5593 | |
| 5594 | self.executor_server.release('project1-test1') |
| 5595 | self.waitUntilSettled() |
| 5596 | |
| 5597 | # one build of project1-test1 must run |
| 5598 | # two builds of project2-test1 must run |
| 5599 | # semaphore of tenant-one must be acquired once |
| 5600 | # semaphore of tenant-two must be acquired twice |
| 5601 | self.assertEqual(len(self.builds), 3) |
| 5602 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5603 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5604 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5605 | self.assertTrue('test-semaphore' in |
| 5606 | tenant_one.semaphore_handler.semaphores) |
| 5607 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5608 | 'test-semaphore', [])), 1) |
| 5609 | self.assertTrue('test-semaphore' in |
| 5610 | tenant_two.semaphore_handler.semaphores) |
| 5611 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5612 | 'test-semaphore', [])), 2) |
| 5613 | |
| 5614 | self.executor_server.release('project2-test1') |
| 5615 | self.waitUntilSettled() |
| 5616 | |
| 5617 | # one build of project1-test1 must run |
| 5618 | # one build of project2-test1 must run |
| 5619 | # semaphore of tenant-one must be acquired once |
| 5620 | # semaphore of tenant-two must be acquired once |
| 5621 | self.assertEqual(len(self.builds), 2) |
| 5622 | self.assertTrue('test-semaphore' in |
| 5623 | tenant_one.semaphore_handler.semaphores) |
| 5624 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5625 | 'test-semaphore', [])), 1) |
| 5626 | self.assertTrue('test-semaphore' in |
| 5627 | tenant_two.semaphore_handler.semaphores) |
| 5628 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5629 | 'test-semaphore', [])), 1) |
| 5630 | |
| 5631 | self.executor_server.hold_jobs_in_build = False |
| 5632 | self.executor_server.release() |
| 5633 | |
| 5634 | self.waitUntilSettled() |
| 5635 | |
| 5636 | # no build must run |
| 5637 | # semaphore of tenant-one must not be acquired |
| 5638 | # semaphore of tenant-two must not be acquired |
| 5639 | self.assertEqual(len(self.builds), 0) |
| 5640 | self.assertFalse('test-semaphore' in |
| 5641 | tenant_one.semaphore_handler.semaphores) |
| 5642 | self.assertFalse('test-semaphore' in |
| 5643 | tenant_two.semaphore_handler.semaphores) |
| 5644 | |
| 5645 | self.assertEqual(A.reported, 1) |
| 5646 | self.assertEqual(B.reported, 1) |
| 5647 | |
| 5648 | |
| 5649 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5650 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5651 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5652 | |
| 5653 | def test_semaphore_in_repo(self): |
| 5654 | "Test semaphores in repo config" |
| 5655 | |
| 5656 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5657 | # max value should not be evaluated dynamically but must be updated |
| 5658 | # after the change lands. |
| 5659 | |
| 5660 | self.waitUntilSettled() |
| 5661 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5662 | |
| 5663 | in_repo_conf = textwrap.dedent( |
| 5664 | """ |
| 5665 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5666 | name: project-test1 |
| 5667 | |
| 5668 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5669 | name: project-test2 |
| 5670 | semaphore: test-semaphore |
| 5671 | |
| 5672 | - project: |
| 5673 | name: org/project |
| 5674 | tenant-one-gate: |
| 5675 | jobs: |
| 5676 | - project-test2 |
| 5677 | |
| 5678 | # the max value in dynamic layout must be ignored |
| 5679 | - semaphore: |
| 5680 | name: test-semaphore |
| 5681 | max: 2 |
| 5682 | """) |
| 5683 | |
| 5684 | in_repo_playbook = textwrap.dedent( |
| 5685 | """ |
| 5686 | - hosts: all |
| 5687 | tasks: [] |
| 5688 | """) |
| 5689 | |
| 5690 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5691 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5692 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5693 | files=file_dict) |
| 5694 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5695 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5696 | B.setDependsOn(A, 1) |
| 5697 | C.setDependsOn(A, 1) |
| 5698 | |
| 5699 | self.executor_server.hold_jobs_in_build = True |
| 5700 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5701 | A.addApproval('Code-Review', 2) |
| 5702 | B.addApproval('Code-Review', 2) |
| 5703 | C.addApproval('Code-Review', 2) |
| 5704 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5705 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5706 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5707 | self.waitUntilSettled() |
| 5708 | |
| 5709 | # check that the layout in a queue item still has max value of 1 |
| 5710 | # for test-semaphore |
| 5711 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5712 | queue = None |
| 5713 | for queue_candidate in pipeline.queues: |
| 5714 | if queue_candidate.name == 'org/project': |
| 5715 | queue = queue_candidate |
| 5716 | break |
| 5717 | queue_item = queue.queue[0] |
James E. Blair | 29a24fd | 2017-10-02 15:04:56 -0700 | [diff] [blame] | 5718 | item_dynamic_layout = queue_item.layout |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5719 | dynamic_test_semaphore = \ |
| 5720 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5721 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5722 | |
| 5723 | # one build must be in queue, one semaphores acquired |
| 5724 | self.assertEqual(len(self.builds), 1) |
| 5725 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5726 | self.assertTrue('test-semaphore' in |
| 5727 | tenant.semaphore_handler.semaphores) |
| 5728 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5729 | 'test-semaphore', [])), 1) |
| 5730 | |
| 5731 | self.executor_server.release('project-test2') |
| 5732 | self.waitUntilSettled() |
| 5733 | |
| 5734 | # change A must be merged |
| 5735 | self.assertEqual(A.data['status'], 'MERGED') |
| 5736 | self.assertEqual(A.reported, 2) |
| 5737 | |
| 5738 | # send change-merged event as the gerrit mock doesn't send it |
| 5739 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5740 | self.waitUntilSettled() |
| 5741 | |
| 5742 | # now that change A was merged, the new semaphore max must be effective |
| 5743 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5744 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5745 | |
| 5746 | # two builds must be in queue, two semaphores acquired |
| 5747 | self.assertEqual(len(self.builds), 2) |
| 5748 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5749 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5750 | self.assertTrue('test-semaphore' in |
| 5751 | tenant.semaphore_handler.semaphores) |
| 5752 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5753 | 'test-semaphore', [])), 2) |
| 5754 | |
| 5755 | self.executor_server.release('project-test2') |
| 5756 | self.waitUntilSettled() |
| 5757 | |
| 5758 | self.assertEqual(len(self.builds), 0) |
| 5759 | self.assertFalse('test-semaphore' in |
| 5760 | tenant.semaphore_handler.semaphores) |
| 5761 | |
| 5762 | self.executor_server.hold_jobs_in_build = False |
| 5763 | self.executor_server.release() |
| 5764 | |
| 5765 | self.waitUntilSettled() |
| 5766 | self.assertEqual(len(self.builds), 0) |
| 5767 | |
| 5768 | self.assertEqual(A.reported, 2) |
| 5769 | self.assertEqual(B.reported, 2) |
| 5770 | self.assertEqual(C.reported, 2) |
David Shrewsbury | f6dc176 | 2017-10-02 13:34:37 -0400 | [diff] [blame] | 5771 | |
| 5772 | |
| 5773 | class TestSchedulerBranchMatcher(ZuulTestCase): |
| 5774 | |
| 5775 | @simple_layout('layouts/matcher-test.yaml') |
| 5776 | def test_job_branch_ignored(self): |
| 5777 | ''' |
| 5778 | Test that branch matching logic works. |
| 5779 | |
| 5780 | The 'ignore-branch' job has a branch matcher that is supposed to |
| 5781 | match every branch except for the 'featureA' branch, so it should |
| 5782 | not be run on a change to that branch. |
| 5783 | ''' |
| 5784 | self.create_branch('org/project', 'featureA') |
| 5785 | A = self.fake_gerrit.addFakeChange('org/project', 'featureA', 'A') |
| 5786 | A.addApproval('Code-Review', 2) |
| 5787 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5788 | self.waitUntilSettled() |
| 5789 | self.printHistory() |
| 5790 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 5791 | 'SUCCESS') |
| 5792 | self.assertJobNotInHistory('ignore-branch') |
| 5793 | self.assertEqual(A.data['status'], 'MERGED') |
| 5794 | self.assertEqual(A.reported, 2, |
| 5795 | "A should report start and success") |
| 5796 | self.assertIn('gate', A.messages[1], |
| 5797 | "A should transit gate") |