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') |
| 52 | A.addApproval('code-review', 2) |
| 53 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 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') |
| 65 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
| 66 | |
| 67 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 68 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 69 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 70 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 71 | def test_jobs_executed(self): |
| 72 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 73 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 74 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 75 | A.addApproval('code-review', 2) |
| 76 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 77 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 78 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 79 | 'SUCCESS') |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 83 | 'SUCCESS') |
| 84 | self.assertEqual(A.data['status'], 'MERGED') |
| 85 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 86 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 87 | 'label1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 88 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 89 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 90 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 91 | # Per-driver |
| 92 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 93 | # Per-driver per-connection |
| 94 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 95 | value='1|c') |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 96 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 97 | value='1|g') |
| 98 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 99 | kind='ms') |
| 100 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 101 | value='1|c') |
| 102 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 103 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 104 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 105 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 106 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 107 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 108 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 109 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 110 | for build in self.builds: |
| 111 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 112 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 113 | def test_initial_pipeline_gauges(self): |
| 114 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 115 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 116 | value='0|g') |
| 117 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 118 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 119 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 120 | def test_job_branch(self): |
| 121 | "Test the correct variant of a job runs on a branch" |
| 122 | self.create_branch('org/project', 'stable') |
| 123 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 124 | A.addApproval('code-review', 2) |
| 125 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 126 | self.waitUntilSettled() |
| 127 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 128 | 'SUCCESS') |
| 129 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 130 | 'SUCCESS') |
| 131 | self.assertEqual(A.data['status'], 'MERGED') |
| 132 | self.assertEqual(A.reported, 2, |
| 133 | "A should report start and success") |
| 134 | self.assertIn('gate', A.messages[1], |
| 135 | "A should transit gate") |
| 136 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 137 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 138 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 139 | def test_parallel_changes(self): |
| 140 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 141 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 142 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 144 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 145 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 146 | A.addApproval('code-review', 2) |
| 147 | B.addApproval('code-review', 2) |
| 148 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 149 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 150 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 151 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 152 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | |
| 154 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 155 | self.assertEqual(len(self.builds), 1) |
| 156 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 157 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 158 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 159 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(len(self.builds), 3) |
| 162 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 169 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(len(self.builds), 5) |
| 172 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 173 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 174 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 175 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 178 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 180 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 183 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 184 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 185 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 186 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 187 | self.assertEqual(len(self.builds), 6) |
| 188 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 189 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 190 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 191 | self.assertTrue(self.builds[1].hasChanges(A)) |
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[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 194 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 198 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 199 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 200 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 201 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 203 | self.executor_server.hold_jobs_in_build = False |
| 204 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 205 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 206 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 207 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 208 | self.assertEqual(len(self.history), 9) |
| 209 | self.assertEqual(A.data['status'], 'MERGED') |
| 210 | self.assertEqual(B.data['status'], 'MERGED') |
| 211 | self.assertEqual(C.data['status'], 'MERGED') |
| 212 | self.assertEqual(A.reported, 2) |
| 213 | self.assertEqual(B.reported, 2) |
| 214 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 215 | |
| 216 | def test_failed_changes(self): |
| 217 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 218 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 219 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 220 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 221 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 222 | A.addApproval('code-review', 2) |
| 223 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 224 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 225 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 227 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 228 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 229 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 230 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 232 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 233 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 234 | # A/project-merge is complete |
| 235 | self.assertBuilds([ |
| 236 | dict(name='project-test1', changes='1,1'), |
| 237 | dict(name='project-test2', changes='1,1'), |
| 238 | dict(name='project-merge', changes='1,1 2,1'), |
| 239 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 240 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 241 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 242 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 243 | # A/project-merge is complete |
| 244 | # B/project-merge is complete |
| 245 | self.assertBuilds([ |
| 246 | dict(name='project-test1', changes='1,1'), |
| 247 | dict(name='project-test2', changes='1,1'), |
| 248 | dict(name='project-test1', changes='1,1 2,1'), |
| 249 | dict(name='project-test2', changes='1,1 2,1'), |
| 250 | ]) |
| 251 | |
| 252 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 253 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 254 | self.builds[0].release() |
| 255 | self.waitUntilSettled() |
| 256 | |
| 257 | self.orderedRelease() |
| 258 | self.assertHistory([ |
| 259 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 260 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 261 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 262 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 263 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 264 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 265 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 266 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 267 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 268 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 269 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 270 | self.assertEqual(A.data['status'], 'NEW') |
| 271 | self.assertEqual(B.data['status'], 'MERGED') |
| 272 | self.assertEqual(A.reported, 2) |
| 273 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 274 | |
| 275 | def test_independent_queues(self): |
| 276 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 277 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 278 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 280 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 281 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 282 | A.addApproval('code-review', 2) |
| 283 | B.addApproval('code-review', 2) |
| 284 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 285 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 286 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 287 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 288 | |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 289 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 290 | self.waitUntilSettled() |
| 291 | |
| 292 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 293 | self.waitUntilSettled() |
| 294 | |
| 295 | # 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] | 296 | self.assertBuilds([ |
| 297 | dict(name='project-merge', changes='1,1'), |
| 298 | dict(name='project-merge', changes='2,1'), |
| 299 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 300 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 301 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 302 | self.builds[0].release() |
| 303 | self.waitUntilSettled() |
| 304 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 305 | self.waitUntilSettled() |
| 306 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 307 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 308 | self.waitUntilSettled() |
| 309 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 310 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 311 | self.assertBuilds([ |
| 312 | dict(name='project-test1', changes='1,1'), |
| 313 | dict(name='project-test2', changes='1,1'), |
| 314 | dict(name='project-test1', changes='2,1'), |
| 315 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 316 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 317 | dict(name='project-test1', changes='2,1 3,1'), |
| 318 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 319 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 320 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 321 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 322 | self.orderedRelease() |
| 323 | self.assertHistory([ |
| 324 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 325 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 326 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 327 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 328 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 329 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 330 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 331 | dict( |
| 332 | name='project1-project2-integration', |
| 333 | result='SUCCESS', |
| 334 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 335 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 336 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 337 | dict(name='project1-project2-integration', |
| 338 | result='SUCCESS', |
| 339 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 340 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 341 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 342 | self.assertEqual(A.data['status'], 'MERGED') |
| 343 | self.assertEqual(B.data['status'], 'MERGED') |
| 344 | self.assertEqual(C.data['status'], 'MERGED') |
| 345 | self.assertEqual(A.reported, 2) |
| 346 | self.assertEqual(B.reported, 2) |
| 347 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 348 | |
| 349 | def test_failed_change_at_head(self): |
| 350 | "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] | 351 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 352 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 354 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 355 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 356 | A.addApproval('code-review', 2) |
| 357 | B.addApproval('code-review', 2) |
| 358 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 359 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 360 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 361 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 362 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 363 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 364 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 365 | |
| 366 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 367 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 368 | self.assertBuilds([ |
| 369 | dict(name='project-merge', changes='1,1'), |
| 370 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 371 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 372 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 373 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 374 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 375 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 376 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 377 | self.waitUntilSettled() |
| 378 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 379 | self.assertBuilds([ |
| 380 | dict(name='project-test1', changes='1,1'), |
| 381 | dict(name='project-test2', changes='1,1'), |
| 382 | dict(name='project-test1', changes='1,1 2,1'), |
| 383 | dict(name='project-test2', changes='1,1 2,1'), |
| 384 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 385 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 386 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 387 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 388 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 389 | self.waitUntilSettled() |
| 390 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 391 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 392 | self.assertBuilds([ |
| 393 | dict(name='project-test2', changes='1,1'), |
| 394 | dict(name='project-merge', changes='2,1'), |
| 395 | ]) |
| 396 | # Unordered history comparison because the aborts can finish |
| 397 | # in any order. |
| 398 | self.assertHistory([ |
| 399 | dict(name='project-merge', result='SUCCESS', |
| 400 | changes='1,1'), |
| 401 | dict(name='project-merge', result='SUCCESS', |
| 402 | changes='1,1 2,1'), |
| 403 | dict(name='project-merge', result='SUCCESS', |
| 404 | changes='1,1 2,1 3,1'), |
| 405 | dict(name='project-test1', result='FAILURE', |
| 406 | changes='1,1'), |
| 407 | dict(name='project-test1', result='ABORTED', |
| 408 | changes='1,1 2,1'), |
| 409 | dict(name='project-test2', result='ABORTED', |
| 410 | changes='1,1 2,1'), |
| 411 | dict(name='project-test1', result='ABORTED', |
| 412 | changes='1,1 2,1 3,1'), |
| 413 | dict(name='project-test2', result='ABORTED', |
| 414 | changes='1,1 2,1 3,1'), |
| 415 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 416 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 417 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 418 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 419 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 420 | self.waitUntilSettled() |
| 421 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 422 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 423 | self.assertBuilds([]) |
| 424 | self.assertHistory([ |
| 425 | dict(name='project-merge', result='SUCCESS', |
| 426 | changes='1,1'), |
| 427 | dict(name='project-merge', result='SUCCESS', |
| 428 | changes='1,1 2,1'), |
| 429 | dict(name='project-merge', result='SUCCESS', |
| 430 | changes='1,1 2,1 3,1'), |
| 431 | dict(name='project-test1', result='FAILURE', |
| 432 | changes='1,1'), |
| 433 | dict(name='project-test1', result='ABORTED', |
| 434 | changes='1,1 2,1'), |
| 435 | dict(name='project-test2', result='ABORTED', |
| 436 | changes='1,1 2,1'), |
| 437 | dict(name='project-test1', result='ABORTED', |
| 438 | changes='1,1 2,1 3,1'), |
| 439 | dict(name='project-test2', result='ABORTED', |
| 440 | changes='1,1 2,1 3,1'), |
| 441 | dict(name='project-merge', result='SUCCESS', |
| 442 | changes='2,1'), |
| 443 | dict(name='project-merge', result='SUCCESS', |
| 444 | changes='2,1 3,1'), |
| 445 | dict(name='project-test2', result='SUCCESS', |
| 446 | changes='1,1'), |
| 447 | dict(name='project-test1', result='SUCCESS', |
| 448 | changes='2,1'), |
| 449 | dict(name='project-test2', result='SUCCESS', |
| 450 | changes='2,1'), |
| 451 | dict(name='project-test1', result='SUCCESS', |
| 452 | changes='2,1 3,1'), |
| 453 | dict(name='project-test2', result='SUCCESS', |
| 454 | changes='2,1 3,1'), |
| 455 | ], ordered=False) |
| 456 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 457 | self.assertEqual(A.data['status'], 'NEW') |
| 458 | self.assertEqual(B.data['status'], 'MERGED') |
| 459 | self.assertEqual(C.data['status'], 'MERGED') |
| 460 | self.assertEqual(A.reported, 2) |
| 461 | self.assertEqual(B.reported, 2) |
| 462 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 463 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 464 | def test_failed_change_in_middle(self): |
| 465 | "Test a failed change in the middle of the queue" |
| 466 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 467 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 468 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 469 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 470 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 471 | A.addApproval('code-review', 2) |
| 472 | B.addApproval('code-review', 2) |
| 473 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 474 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 475 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 476 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 477 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 478 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 479 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 480 | |
| 481 | self.waitUntilSettled() |
| 482 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 483 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 484 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 485 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 486 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 487 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 488 | self.waitUntilSettled() |
| 489 | |
| 490 | self.assertEqual(len(self.builds), 6) |
| 491 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 492 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 493 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 494 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 495 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 496 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 497 | |
| 498 | self.release(self.builds[2]) |
| 499 | self.waitUntilSettled() |
| 500 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 501 | # project-test1 and project-test2 for A |
| 502 | # project-test2 for B |
| 503 | # project-merge for C (without B) |
| 504 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 505 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 506 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 507 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 508 | self.waitUntilSettled() |
| 509 | |
| 510 | # project-test1 and project-test2 for A |
| 511 | # project-test2 for B |
| 512 | # project-test1 and project-test2 for C |
| 513 | self.assertEqual(len(self.builds), 5) |
| 514 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 515 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 516 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 517 | builds = items[0].current_build_set.getBuilds() |
| 518 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 519 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 520 | builds = items[1].current_build_set.getBuilds() |
| 521 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 522 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 523 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 524 | builds = items[2].current_build_set.getBuilds() |
| 525 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 526 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 528 | self.executor_server.hold_jobs_in_build = False |
| 529 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 530 | self.waitUntilSettled() |
| 531 | |
| 532 | self.assertEqual(len(self.builds), 0) |
| 533 | self.assertEqual(len(self.history), 12) |
| 534 | self.assertEqual(A.data['status'], 'MERGED') |
| 535 | self.assertEqual(B.data['status'], 'NEW') |
| 536 | self.assertEqual(C.data['status'], 'MERGED') |
| 537 | self.assertEqual(A.reported, 2) |
| 538 | self.assertEqual(B.reported, 2) |
| 539 | self.assertEqual(C.reported, 2) |
| 540 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 541 | def test_failed_change_at_head_with_queue(self): |
| 542 | "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] | 543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 544 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 546 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 547 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 548 | A.addApproval('code-review', 2) |
| 549 | B.addApproval('code-review', 2) |
| 550 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 551 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 552 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 553 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 554 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 555 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 556 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 557 | |
| 558 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 559 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 560 | self.assertEqual(len(self.builds), 0) |
| 561 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 562 | self.assertEqual(queue[0].name, b'executor:execute') |
| 563 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 564 | self.assertEqual(job_args['job'], 'project-merge') |
| 565 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 567 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 568 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 569 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 570 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 571 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 573 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 575 | self.assertEqual(len(self.builds), 0) |
| 576 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 577 | |
| 578 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 579 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 580 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 581 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 582 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 583 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 584 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 585 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 586 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 587 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 588 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 589 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 590 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 591 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 592 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 593 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 594 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 595 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 596 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 597 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 598 | self.waitUntilSettled() |
| 599 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 600 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 601 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 602 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 603 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 604 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 605 | self.gearman_server.hold_jobs_in_queue = False |
| 606 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 607 | self.waitUntilSettled() |
| 608 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 609 | self.assertEqual(len(self.builds), 0) |
| 610 | self.assertEqual(len(self.history), 11) |
| 611 | self.assertEqual(A.data['status'], 'NEW') |
| 612 | self.assertEqual(B.data['status'], 'MERGED') |
| 613 | self.assertEqual(C.data['status'], 'MERGED') |
| 614 | self.assertEqual(A.reported, 2) |
| 615 | self.assertEqual(B.reported, 2) |
| 616 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 617 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 618 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 619 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 620 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 621 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 622 | A.addApproval('code-review', 2) |
| 623 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 624 | self.waitUntilSettled() |
| 625 | time.sleep(2) |
| 626 | |
| 627 | data = json.loads(self.sched.formatStatusJSON()) |
| 628 | found_job = None |
| 629 | for pipeline in data['pipelines']: |
| 630 | if pipeline['name'] != 'gate': |
| 631 | continue |
| 632 | for queue in pipeline['change_queues']: |
| 633 | for head in queue['heads']: |
| 634 | for item in head: |
| 635 | for job in item['jobs']: |
| 636 | if job['name'] == 'project-merge': |
| 637 | found_job = job |
| 638 | break |
| 639 | |
| 640 | self.assertIsNotNone(found_job) |
| 641 | if iteration == 1: |
| 642 | self.assertIsNotNone(found_job['estimated_time']) |
| 643 | self.assertIsNone(found_job['remaining_time']) |
| 644 | else: |
| 645 | self.assertIsNotNone(found_job['estimated_time']) |
| 646 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 647 | self.assertIsNotNone(found_job['remaining_time']) |
| 648 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 649 | self.executor_server.hold_jobs_in_build = False |
| 650 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 651 | self.waitUntilSettled() |
| 652 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 653 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 654 | def test_time_database(self): |
| 655 | "Test the time database" |
| 656 | |
| 657 | self._test_time_database(1) |
| 658 | self._test_time_database(2) |
| 659 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 660 | def test_two_failed_changes_at_head(self): |
| 661 | "Test that changes are reparented correctly if 2 fail at head" |
| 662 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 663 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 665 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 666 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 667 | A.addApproval('code-review', 2) |
| 668 | B.addApproval('code-review', 2) |
| 669 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 670 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 671 | self.executor_server.failJob('project-test1', A) |
| 672 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 673 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 674 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 675 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 676 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 677 | self.waitUntilSettled() |
| 678 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 679 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 680 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 681 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 683 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 684 | self.waitUntilSettled() |
| 685 | |
| 686 | self.assertEqual(len(self.builds), 6) |
| 687 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 688 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 689 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 690 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 691 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 692 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 693 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 694 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 695 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 696 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 697 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 698 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 699 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 700 | |
| 701 | # Fail change B first |
| 702 | self.release(self.builds[2]) |
| 703 | self.waitUntilSettled() |
| 704 | |
| 705 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 706 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | self.waitUntilSettled() |
| 708 | |
| 709 | self.assertEqual(len(self.builds), 5) |
| 710 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 711 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 712 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 713 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 714 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 715 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 716 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 717 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 718 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 719 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 720 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 721 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 722 | |
| 723 | # Finish running all passing jobs for change A |
| 724 | self.release(self.builds[1]) |
| 725 | self.waitUntilSettled() |
| 726 | # Fail and report change A |
| 727 | self.release(self.builds[0]) |
| 728 | self.waitUntilSettled() |
| 729 | |
| 730 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 731 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 732 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 733 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 734 | self.waitUntilSettled() |
| 735 | |
| 736 | self.assertEqual(len(self.builds), 4) |
| 737 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 738 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 739 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 740 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 741 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 742 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 743 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 744 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 745 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 746 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 747 | # After A failed and B and C restarted, B should be back in |
| 748 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 749 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 750 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 751 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 752 | self.executor_server.hold_jobs_in_build = False |
| 753 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 754 | self.waitUntilSettled() |
| 755 | |
| 756 | self.assertEqual(len(self.builds), 0) |
| 757 | self.assertEqual(len(self.history), 21) |
| 758 | self.assertEqual(A.data['status'], 'NEW') |
| 759 | self.assertEqual(B.data['status'], 'NEW') |
| 760 | self.assertEqual(C.data['status'], 'MERGED') |
| 761 | self.assertEqual(A.reported, 2) |
| 762 | self.assertEqual(B.reported, 2) |
| 763 | self.assertEqual(C.reported, 2) |
| 764 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 765 | def test_patch_order(self): |
| 766 | "Test that dependent patches are tested in the right order" |
| 767 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 768 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 769 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 770 | A.addApproval('code-review', 2) |
| 771 | B.addApproval('code-review', 2) |
| 772 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 773 | |
| 774 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 775 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 776 | M2.setMerged() |
| 777 | M1.setMerged() |
| 778 | |
| 779 | # C -> B -> A -> M1 -> M2 |
| 780 | # M2 is here to make sure it is never queried. If it is, it |
| 781 | # means zuul is walking down the entire history of merged |
| 782 | # changes. |
| 783 | |
| 784 | C.setDependsOn(B, 1) |
| 785 | B.setDependsOn(A, 1) |
| 786 | A.setDependsOn(M1, 1) |
| 787 | M1.setDependsOn(M2, 1) |
| 788 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 789 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 790 | |
| 791 | self.waitUntilSettled() |
| 792 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 793 | self.assertEqual(A.data['status'], 'NEW') |
| 794 | self.assertEqual(B.data['status'], 'NEW') |
| 795 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 796 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 797 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 798 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 799 | |
| 800 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 801 | self.assertEqual(M2.queried, 0) |
| 802 | self.assertEqual(A.data['status'], 'MERGED') |
| 803 | self.assertEqual(B.data['status'], 'MERGED') |
| 804 | self.assertEqual(C.data['status'], 'MERGED') |
| 805 | self.assertEqual(A.reported, 2) |
| 806 | self.assertEqual(B.reported, 2) |
| 807 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 808 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 809 | def test_needed_changes_enqueue(self): |
| 810 | "Test that a needed change is enqueued ahead" |
| 811 | # A Given a git tree like this, if we enqueue |
| 812 | # / \ change C, we should walk up and down the tree |
| 813 | # B G and enqueue changes in the order ABCDEFG. |
| 814 | # /|\ This is also the order that you would get if |
| 815 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 816 | # / the ordering is stable across re-enqueue events. |
| 817 | # D |
| 818 | |
| 819 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 820 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 821 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 822 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 823 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 824 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 825 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 826 | B.setDependsOn(A, 1) |
| 827 | C.setDependsOn(B, 1) |
| 828 | D.setDependsOn(C, 1) |
| 829 | E.setDependsOn(B, 1) |
| 830 | F.setDependsOn(B, 1) |
| 831 | G.setDependsOn(A, 1) |
| 832 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 833 | A.addApproval('code-review', 2) |
| 834 | B.addApproval('code-review', 2) |
| 835 | C.addApproval('code-review', 2) |
| 836 | D.addApproval('code-review', 2) |
| 837 | E.addApproval('code-review', 2) |
| 838 | F.addApproval('code-review', 2) |
| 839 | G.addApproval('code-review', 2) |
| 840 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 841 | |
| 842 | self.waitUntilSettled() |
| 843 | |
| 844 | self.assertEqual(A.data['status'], 'NEW') |
| 845 | self.assertEqual(B.data['status'], 'NEW') |
| 846 | self.assertEqual(C.data['status'], 'NEW') |
| 847 | self.assertEqual(D.data['status'], 'NEW') |
| 848 | self.assertEqual(E.data['status'], 'NEW') |
| 849 | self.assertEqual(F.data['status'], 'NEW') |
| 850 | self.assertEqual(G.data['status'], 'NEW') |
| 851 | |
| 852 | # We're about to add approvals to changes without adding the |
| 853 | # triggering events to Zuul, so that we can be sure that it is |
| 854 | # enqueing the changes based on dependencies, not because of |
| 855 | # triggering events. Since it will have the changes cached |
| 856 | # already (without approvals), we need to clear the cache |
| 857 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 858 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 859 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 860 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 861 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 862 | A.addApproval('approved', 1) |
| 863 | B.addApproval('approved', 1) |
| 864 | D.addApproval('approved', 1) |
| 865 | E.addApproval('approved', 1) |
| 866 | F.addApproval('approved', 1) |
| 867 | G.addApproval('approved', 1) |
| 868 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 869 | |
| 870 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 871 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 872 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 873 | self.executor_server.hold_jobs_in_build = False |
| 874 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 875 | self.waitUntilSettled() |
| 876 | |
| 877 | self.assertEqual(A.data['status'], 'MERGED') |
| 878 | self.assertEqual(B.data['status'], 'MERGED') |
| 879 | self.assertEqual(C.data['status'], 'MERGED') |
| 880 | self.assertEqual(D.data['status'], 'MERGED') |
| 881 | self.assertEqual(E.data['status'], 'MERGED') |
| 882 | self.assertEqual(F.data['status'], 'MERGED') |
| 883 | self.assertEqual(G.data['status'], 'MERGED') |
| 884 | self.assertEqual(A.reported, 2) |
| 885 | self.assertEqual(B.reported, 2) |
| 886 | self.assertEqual(C.reported, 2) |
| 887 | self.assertEqual(D.reported, 2) |
| 888 | self.assertEqual(E.reported, 2) |
| 889 | self.assertEqual(F.reported, 2) |
| 890 | self.assertEqual(G.reported, 2) |
| 891 | self.assertEqual(self.history[6].changes, |
| 892 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 893 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 894 | def test_source_cache(self): |
| 895 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 896 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 897 | |
| 898 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 899 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 900 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 901 | A.addApproval('code-review', 2) |
| 902 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 903 | |
| 904 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 905 | M1.setMerged() |
| 906 | |
| 907 | B.setDependsOn(A, 1) |
| 908 | A.setDependsOn(M1, 1) |
| 909 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 910 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 911 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 912 | |
| 913 | self.waitUntilSettled() |
| 914 | |
| 915 | for build in self.builds: |
| 916 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 917 | build.release() |
| 918 | self.waitUntilSettled() |
| 919 | for build in self.builds: |
| 920 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 921 | build.release() |
| 922 | self.waitUntilSettled() |
| 923 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 924 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 925 | self.waitUntilSettled() |
| 926 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 927 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 928 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 929 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 930 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 931 | self.executor_server.hold_jobs_in_build = False |
| 932 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 933 | self.waitUntilSettled() |
| 934 | |
| 935 | self.assertEqual(A.data['status'], 'MERGED') |
| 936 | self.assertEqual(B.data['status'], 'MERGED') |
| 937 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 938 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 939 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 940 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 941 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 942 | # TODO: move to test_gerrit (this is a unit test!) |
| 943 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 944 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 945 | (trusted, project) = tenant.getProject('org/project') |
| 946 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 947 | |
| 948 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 949 | # it easier for users to create events for testing. |
| 950 | event = zuul.model.TriggerEvent() |
| 951 | event.trigger_name = 'gerrit' |
| 952 | event.change_number = '1' |
| 953 | event.patch_number = '2' |
| 954 | |
| 955 | a = source.getChange(event) |
| 956 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 957 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 958 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 959 | A.addApproval('code-review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 960 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 961 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 962 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 963 | A.addApproval('approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 964 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 965 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 966 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 967 | def test_project_merge_conflict(self): |
| 968 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 969 | |
| 970 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 971 | A = self.fake_gerrit.addFakeChange('org/project', |
| 972 | 'master', 'A', |
| 973 | files={'conflict': 'foo'}) |
| 974 | B = self.fake_gerrit.addFakeChange('org/project', |
| 975 | 'master', 'B', |
| 976 | files={'conflict': 'bar'}) |
| 977 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 978 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 979 | A.addApproval('code-review', 2) |
| 980 | B.addApproval('code-review', 2) |
| 981 | C.addApproval('code-review', 2) |
| 982 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 983 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 984 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 985 | self.waitUntilSettled() |
| 986 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 987 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 988 | self.assertEqual(C.reported, 1) |
| 989 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 990 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 991 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 992 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 993 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 994 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 995 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 996 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 997 | self.gearman_server.hold_jobs_in_queue = False |
| 998 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 999 | self.waitUntilSettled() |
| 1000 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1001 | self.assertEqual(A.data['status'], 'MERGED') |
| 1002 | self.assertEqual(B.data['status'], 'NEW') |
| 1003 | self.assertEqual(C.data['status'], 'MERGED') |
| 1004 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1005 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1006 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1007 | |
| 1008 | self.assertHistory([ |
| 1009 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1010 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1011 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1012 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1013 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1014 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1015 | ], ordered=False) |
| 1016 | |
| 1017 | def test_delayed_merge_conflict(self): |
| 1018 | "Test that delayed check merge conflicts are handled properly" |
| 1019 | |
| 1020 | # 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] | 1021 | # the executor sucesfully merges a change based on an old |
| 1022 | # repo state (frozen by the scheduler) which would otherwise |
| 1023 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1024 | self.gearman_server.hold_jobs_in_queue = True |
| 1025 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1026 | 'master', 'A', |
| 1027 | files={'conflict': 'foo'}) |
| 1028 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1029 | 'master', 'B', |
| 1030 | files={'conflict': 'bar'}) |
| 1031 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1032 | 'master', 'C') |
| 1033 | C.setDependsOn(B, 1) |
| 1034 | |
| 1035 | # A enters the gate queue; B and C enter the check queue |
| 1036 | A.addApproval('code-review', 2) |
| 1037 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1038 | self.waitUntilSettled() |
| 1039 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1040 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1041 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1042 | self.waitUntilSettled() |
| 1043 | |
| 1044 | self.assertEqual(A.reported, 1) |
| 1045 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1046 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1047 | |
| 1048 | # A merges while B and C are queued in check |
| 1049 | # Release A project-merge |
| 1050 | queue = self.gearman_server.getQueue() |
| 1051 | self.release(queue[0]) |
| 1052 | self.waitUntilSettled() |
| 1053 | |
| 1054 | # Release A project-test* |
| 1055 | # gate has higher precedence, so A's test jobs are added in |
| 1056 | # front of the merge jobs for B and C |
| 1057 | queue = self.gearman_server.getQueue() |
| 1058 | self.release(queue[0]) |
| 1059 | self.release(queue[1]) |
| 1060 | self.waitUntilSettled() |
| 1061 | |
| 1062 | self.assertEqual(A.data['status'], 'MERGED') |
| 1063 | self.assertEqual(B.data['status'], 'NEW') |
| 1064 | self.assertEqual(C.data['status'], 'NEW') |
| 1065 | self.assertEqual(A.reported, 2) |
| 1066 | self.assertEqual(B.reported, 0) |
| 1067 | self.assertEqual(C.reported, 0) |
| 1068 | self.assertHistory([ |
| 1069 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1070 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1072 | ], ordered=False) |
| 1073 | |
| 1074 | # B and C report merge conflicts |
| 1075 | # Release B project-merge |
| 1076 | queue = self.gearman_server.getQueue() |
| 1077 | self.release(queue[0]) |
| 1078 | self.waitUntilSettled() |
| 1079 | |
| 1080 | # Release C |
| 1081 | self.gearman_server.hold_jobs_in_queue = False |
| 1082 | self.gearman_server.release() |
| 1083 | self.waitUntilSettled() |
| 1084 | |
| 1085 | self.assertEqual(A.data['status'], 'MERGED') |
| 1086 | self.assertEqual(B.data['status'], 'NEW') |
| 1087 | self.assertEqual(C.data['status'], 'NEW') |
| 1088 | self.assertEqual(A.reported, 2) |
| 1089 | self.assertEqual(B.reported, 1) |
| 1090 | self.assertEqual(C.reported, 1) |
| 1091 | |
| 1092 | self.assertHistory([ |
| 1093 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1094 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1095 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1096 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1097 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1098 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1099 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1100 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1101 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1102 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1103 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1104 | def test_post(self): |
| 1105 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1106 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1107 | e = { |
| 1108 | "type": "ref-updated", |
| 1109 | "submitter": { |
| 1110 | "name": "User Name", |
| 1111 | }, |
| 1112 | "refUpdate": { |
| 1113 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1114 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1115 | "refName": "master", |
| 1116 | "project": "org/project", |
| 1117 | } |
| 1118 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1119 | self.fake_gerrit.addEvent(e) |
| 1120 | self.waitUntilSettled() |
| 1121 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1122 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1123 | self.assertEqual(len(self.history), 1) |
| 1124 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1125 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1126 | def test_post_ignore_deletes(self): |
| 1127 | "Test that deleting refs does not trigger post jobs" |
| 1128 | |
| 1129 | e = { |
| 1130 | "type": "ref-updated", |
| 1131 | "submitter": { |
| 1132 | "name": "User Name", |
| 1133 | }, |
| 1134 | "refUpdate": { |
| 1135 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1136 | "newRev": "0000000000000000000000000000000000000000", |
| 1137 | "refName": "master", |
| 1138 | "project": "org/project", |
| 1139 | } |
| 1140 | } |
| 1141 | self.fake_gerrit.addEvent(e) |
| 1142 | self.waitUntilSettled() |
| 1143 | |
| 1144 | job_names = [x.name for x in self.history] |
| 1145 | self.assertEqual(len(self.history), 0) |
| 1146 | self.assertNotIn('project-post', job_names) |
| 1147 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1148 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1149 | def test_post_ignore_deletes_negative(self): |
| 1150 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1151 | e = { |
| 1152 | "type": "ref-updated", |
| 1153 | "submitter": { |
| 1154 | "name": "User Name", |
| 1155 | }, |
| 1156 | "refUpdate": { |
| 1157 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1158 | "newRev": "0000000000000000000000000000000000000000", |
| 1159 | "refName": "master", |
| 1160 | "project": "org/project", |
| 1161 | } |
| 1162 | } |
| 1163 | self.fake_gerrit.addEvent(e) |
| 1164 | self.waitUntilSettled() |
| 1165 | |
| 1166 | job_names = [x.name for x in self.history] |
| 1167 | self.assertEqual(len(self.history), 1) |
| 1168 | self.assertIn('project-post', job_names) |
| 1169 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1170 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1171 | def test_build_configuration_branch_interaction(self): |
| 1172 | "Test that switching between branches works" |
| 1173 | self.test_build_configuration() |
| 1174 | self.test_build_configuration_branch() |
| 1175 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1176 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1177 | repo = git.Repo(path) |
| 1178 | repo.heads.master.commit = repo.commit('init') |
| 1179 | self.test_build_configuration() |
| 1180 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1181 | def test_dependent_changes_rebase(self): |
| 1182 | # Test that no errors occur when we walk a dependency tree |
| 1183 | # with an unused leaf node due to a rebase. |
| 1184 | # Start by constructing: C -> B -> A |
| 1185 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1186 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1187 | B.setDependsOn(A, 1) |
| 1188 | |
| 1189 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1190 | C.setDependsOn(B, 1) |
| 1191 | |
| 1192 | # Then rebase to form: D -> C -> A |
| 1193 | C.addPatchset() # C,2 |
| 1194 | C.setDependsOn(A, 1) |
| 1195 | |
| 1196 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1197 | D.setDependsOn(C, 2) |
| 1198 | |
| 1199 | # Walk the entire tree |
| 1200 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1201 | self.waitUntilSettled() |
| 1202 | self.assertEqual(len(self.history), 3) |
| 1203 | |
| 1204 | # Verify that walking just part of the tree still works |
| 1205 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1206 | self.waitUntilSettled() |
| 1207 | self.assertEqual(len(self.history), 6) |
| 1208 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1209 | def test_dependent_changes_dequeue(self): |
| 1210 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1211 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1212 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1213 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1214 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1215 | A.addApproval('code-review', 2) |
| 1216 | B.addApproval('code-review', 2) |
| 1217 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1218 | |
| 1219 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1220 | M1.setMerged() |
| 1221 | |
| 1222 | # C -> B -> A -> M1 |
| 1223 | |
| 1224 | C.setDependsOn(B, 1) |
| 1225 | B.setDependsOn(A, 1) |
| 1226 | A.setDependsOn(M1, 1) |
| 1227 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1228 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1229 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1230 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1231 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1232 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1233 | |
| 1234 | self.waitUntilSettled() |
| 1235 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1236 | self.assertEqual(A.data['status'], 'NEW') |
| 1237 | self.assertEqual(A.reported, 2) |
| 1238 | self.assertEqual(B.data['status'], 'NEW') |
| 1239 | self.assertEqual(B.reported, 2) |
| 1240 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1241 | self.assertIn('This change depends on a change that failed to merge.', |
| 1242 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1243 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1244 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1245 | def test_failing_dependent_changes(self): |
| 1246 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1247 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1248 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1249 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1250 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1251 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1252 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1253 | A.addApproval('code-review', 2) |
| 1254 | B.addApproval('code-review', 2) |
| 1255 | C.addApproval('code-review', 2) |
| 1256 | D.addApproval('code-review', 2) |
| 1257 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1258 | |
| 1259 | # E, D -> C -> B, A |
| 1260 | |
| 1261 | D.setDependsOn(C, 1) |
| 1262 | C.setDependsOn(B, 1) |
| 1263 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1264 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1265 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1266 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1267 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1268 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1269 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1270 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1271 | |
| 1272 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1273 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1274 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1275 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1276 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1277 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1278 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1279 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1280 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1281 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1282 | self.waitUntilSettled() |
| 1283 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1284 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1285 | for build in self.builds: |
| 1286 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1287 | build.release() |
| 1288 | self.waitUntilSettled() |
| 1289 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1290 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1291 | self.waitUntilSettled() |
| 1292 | |
| 1293 | self.assertEqual(A.data['status'], 'MERGED') |
| 1294 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1295 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1296 | self.assertEqual(B.data['status'], 'NEW') |
| 1297 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1298 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1299 | self.assertEqual(C.data['status'], 'NEW') |
| 1300 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1301 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1302 | self.assertEqual(D.data['status'], 'NEW') |
| 1303 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1304 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1305 | self.assertEqual(E.data['status'], 'MERGED') |
| 1306 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1307 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1308 | self.assertEqual(len(self.history), 18) |
| 1309 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1310 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1311 | "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] | 1312 | # If it's dequeued more than once, we should see extra |
| 1313 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1314 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1315 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1316 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1317 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1318 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1319 | A.addApproval('code-review', 2) |
| 1320 | B.addApproval('code-review', 2) |
| 1321 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1322 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1323 | self.executor_server.failJob('project-test1', A) |
| 1324 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1325 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1326 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1327 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1328 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1329 | |
| 1330 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1331 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1332 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1333 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1334 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1335 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1336 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1338 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1340 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1341 | self.waitUntilSettled() |
| 1342 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1343 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1344 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1345 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1346 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1347 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1348 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1349 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1350 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1351 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1352 | self.waitUntilSettled() |
| 1353 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1354 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1355 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1357 | self.executor_server.hold_jobs_in_build = False |
| 1358 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1359 | self.waitUntilSettled() |
| 1360 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1361 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1362 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1363 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1364 | self.assertEqual(A.data['status'], 'NEW') |
| 1365 | self.assertEqual(B.data['status'], 'MERGED') |
| 1366 | self.assertEqual(C.data['status'], 'MERGED') |
| 1367 | self.assertEqual(A.reported, 2) |
| 1368 | self.assertEqual(B.reported, 2) |
| 1369 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1370 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1371 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1372 | def test_nonvoting_job(self): |
| 1373 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1374 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1375 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1376 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1377 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1378 | self.executor_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1379 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1380 | |
| 1381 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1382 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1383 | self.assertEqual(A.data['status'], 'MERGED') |
| 1384 | self.assertEqual(A.reported, 2) |
| 1385 | self.assertEqual( |
| 1386 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1387 | 'SUCCESS') |
| 1388 | self.assertEqual( |
| 1389 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1390 | 'SUCCESS') |
| 1391 | self.assertEqual( |
| 1392 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1393 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1394 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1395 | for build in self.builds: |
| 1396 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1397 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1398 | def test_check_queue_success(self): |
| 1399 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1400 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1401 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1402 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1403 | |
| 1404 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1405 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1406 | self.assertEqual(A.data['status'], 'NEW') |
| 1407 | self.assertEqual(A.reported, 1) |
| 1408 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1409 | 'SUCCESS') |
| 1410 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1411 | 'SUCCESS') |
| 1412 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1413 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1414 | |
| 1415 | def test_check_queue_failure(self): |
| 1416 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1417 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1418 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1419 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1420 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1421 | |
| 1422 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1423 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1424 | self.assertEqual(A.data['status'], 'NEW') |
| 1425 | self.assertEqual(A.reported, 1) |
| 1426 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1427 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1428 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1429 | 'SUCCESS') |
| 1430 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1431 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1432 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1433 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1434 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1435 | # This particular test does a large amount of merges and needs a little |
| 1436 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1437 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1438 | "test that dependent changes behind dequeued changes work" |
| 1439 | # This complicated test is a reproduction of a real life bug |
| 1440 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1441 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1442 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1443 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1444 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1445 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1446 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1447 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1448 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1449 | D.setDependsOn(C, 1) |
| 1450 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1451 | A.addApproval('code-review', 2) |
| 1452 | B.addApproval('code-review', 2) |
| 1453 | C.addApproval('code-review', 2) |
| 1454 | D.addApproval('code-review', 2) |
| 1455 | E.addApproval('code-review', 2) |
| 1456 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1457 | |
| 1458 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1459 | |
| 1460 | # Change object re-use in the gerrit trigger is hidden if |
| 1461 | # changes are added in quick succession; waiting makes it more |
| 1462 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1463 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1464 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1465 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1466 | self.waitUntilSettled() |
| 1467 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1468 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1469 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1470 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1471 | self.waitUntilSettled() |
| 1472 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1473 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1474 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1475 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1476 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1477 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1478 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1479 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1480 | self.waitUntilSettled() |
| 1481 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1482 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1483 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1484 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1485 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1486 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1487 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1488 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1489 | self.waitUntilSettled() |
| 1490 | |
| 1491 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1492 | |
| 1493 | # Grab pointers to the jobs we want to release before |
| 1494 | # releasing any, because list indexes may change as |
| 1495 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1496 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1497 | a.release() |
| 1498 | b.release() |
| 1499 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1500 | self.waitUntilSettled() |
| 1501 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1502 | self.executor_server.hold_jobs_in_build = False |
| 1503 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1504 | self.waitUntilSettled() |
| 1505 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1506 | self.assertEqual(A.data['status'], 'NEW') |
| 1507 | self.assertEqual(B.data['status'], 'MERGED') |
| 1508 | self.assertEqual(C.data['status'], 'MERGED') |
| 1509 | self.assertEqual(D.data['status'], 'MERGED') |
| 1510 | self.assertEqual(E.data['status'], 'MERGED') |
| 1511 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1512 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1513 | self.assertEqual(A.reported, 2) |
| 1514 | self.assertEqual(B.reported, 2) |
| 1515 | self.assertEqual(C.reported, 2) |
| 1516 | self.assertEqual(D.reported, 2) |
| 1517 | self.assertEqual(E.reported, 2) |
| 1518 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1519 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1520 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1521 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1522 | |
| 1523 | def test_merger_repack(self): |
| 1524 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1525 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1526 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1527 | A.addApproval('code-review', 2) |
| 1528 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1529 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1530 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1531 | 'SUCCESS') |
| 1532 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1533 | 'SUCCESS') |
| 1534 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1535 | 'SUCCESS') |
| 1536 | self.assertEqual(A.data['status'], 'MERGED') |
| 1537 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1538 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1539 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1540 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1541 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1542 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1543 | if os.path.exists(path): |
| 1544 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1545 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1546 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1547 | if os.path.exists(path): |
| 1548 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1549 | |
| 1550 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1551 | A.addApproval('code-review', 2) |
| 1552 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1553 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1554 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1555 | 'SUCCESS') |
| 1556 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1557 | 'SUCCESS') |
| 1558 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1559 | 'SUCCESS') |
| 1560 | self.assertEqual(A.data['status'], 'MERGED') |
| 1561 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1562 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1563 | def test_merger_repack_large_change(self): |
| 1564 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1565 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1566 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1567 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1568 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1569 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1570 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1571 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1572 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1573 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1574 | # TODOv3(jeblair): add hostname to upstream root |
| 1575 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1576 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1577 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1578 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1579 | if os.path.exists(path): |
| 1580 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1581 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1582 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1583 | if os.path.exists(path): |
| 1584 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1585 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1586 | A.addApproval('code-review', 2) |
| 1587 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1588 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1589 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1590 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1591 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1592 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1593 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1594 | 'SUCCESS') |
| 1595 | self.assertEqual(A.data['status'], 'MERGED') |
| 1596 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1597 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1598 | def test_new_patchset_dequeues_old(self): |
| 1599 | "Test that a new patchset causes the old to be dequeued" |
| 1600 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1601 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1602 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1603 | M.setMerged() |
| 1604 | |
| 1605 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1606 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1607 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1608 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1609 | A.addApproval('code-review', 2) |
| 1610 | B.addApproval('code-review', 2) |
| 1611 | C.addApproval('code-review', 2) |
| 1612 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1613 | |
| 1614 | C.setDependsOn(B, 1) |
| 1615 | B.setDependsOn(A, 1) |
| 1616 | A.setDependsOn(M, 1) |
| 1617 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1618 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1619 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1620 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1621 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1622 | self.waitUntilSettled() |
| 1623 | |
| 1624 | B.addPatchset() |
| 1625 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1626 | self.waitUntilSettled() |
| 1627 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1628 | self.executor_server.hold_jobs_in_build = False |
| 1629 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1630 | self.waitUntilSettled() |
| 1631 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1632 | self.assertEqual(A.data['status'], 'MERGED') |
| 1633 | self.assertEqual(A.reported, 2) |
| 1634 | self.assertEqual(B.data['status'], 'NEW') |
| 1635 | self.assertEqual(B.reported, 2) |
| 1636 | self.assertEqual(C.data['status'], 'NEW') |
| 1637 | self.assertEqual(C.reported, 2) |
| 1638 | self.assertEqual(D.data['status'], 'MERGED') |
| 1639 | self.assertEqual(D.reported, 2) |
| 1640 | 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] | 1641 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1642 | def test_new_patchset_check(self): |
| 1643 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1644 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1645 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1646 | |
| 1647 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1648 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1649 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1650 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1651 | |
| 1652 | # Add two git-dependent changes |
| 1653 | B.setDependsOn(A, 1) |
| 1654 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1655 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1656 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1657 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1658 | |
| 1659 | # A live item, and a non-live/live pair |
| 1660 | items = check_pipeline.getAllItems() |
| 1661 | self.assertEqual(len(items), 3) |
| 1662 | |
| 1663 | self.assertEqual(items[0].change.number, '1') |
| 1664 | self.assertEqual(items[0].change.patchset, '1') |
| 1665 | self.assertFalse(items[0].live) |
| 1666 | |
| 1667 | self.assertEqual(items[1].change.number, '2') |
| 1668 | self.assertEqual(items[1].change.patchset, '1') |
| 1669 | self.assertTrue(items[1].live) |
| 1670 | |
| 1671 | self.assertEqual(items[2].change.number, '1') |
| 1672 | self.assertEqual(items[2].change.patchset, '1') |
| 1673 | self.assertTrue(items[2].live) |
| 1674 | |
| 1675 | # Add a new patchset to A |
| 1676 | A.addPatchset() |
| 1677 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1678 | self.waitUntilSettled() |
| 1679 | |
| 1680 | # The live copy of A,1 should be gone, but the non-live and B |
| 1681 | # should continue, and we should have a new A,2 |
| 1682 | items = check_pipeline.getAllItems() |
| 1683 | self.assertEqual(len(items), 3) |
| 1684 | |
| 1685 | self.assertEqual(items[0].change.number, '1') |
| 1686 | self.assertEqual(items[0].change.patchset, '1') |
| 1687 | self.assertFalse(items[0].live) |
| 1688 | |
| 1689 | self.assertEqual(items[1].change.number, '2') |
| 1690 | self.assertEqual(items[1].change.patchset, '1') |
| 1691 | self.assertTrue(items[1].live) |
| 1692 | |
| 1693 | self.assertEqual(items[2].change.number, '1') |
| 1694 | self.assertEqual(items[2].change.patchset, '2') |
| 1695 | self.assertTrue(items[2].live) |
| 1696 | |
| 1697 | # Add a new patchset to B |
| 1698 | B.addPatchset() |
| 1699 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1700 | self.waitUntilSettled() |
| 1701 | |
| 1702 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1703 | # but we should have a new B,2 (still based on A,1) |
| 1704 | items = check_pipeline.getAllItems() |
| 1705 | self.assertEqual(len(items), 3) |
| 1706 | |
| 1707 | self.assertEqual(items[0].change.number, '1') |
| 1708 | self.assertEqual(items[0].change.patchset, '2') |
| 1709 | self.assertTrue(items[0].live) |
| 1710 | |
| 1711 | self.assertEqual(items[1].change.number, '1') |
| 1712 | self.assertEqual(items[1].change.patchset, '1') |
| 1713 | self.assertFalse(items[1].live) |
| 1714 | |
| 1715 | self.assertEqual(items[2].change.number, '2') |
| 1716 | self.assertEqual(items[2].change.patchset, '2') |
| 1717 | self.assertTrue(items[2].live) |
| 1718 | |
| 1719 | self.builds[0].release() |
| 1720 | self.waitUntilSettled() |
| 1721 | self.builds[0].release() |
| 1722 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1723 | self.executor_server.hold_jobs_in_build = False |
| 1724 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1725 | self.waitUntilSettled() |
| 1726 | |
| 1727 | self.assertEqual(A.reported, 1) |
| 1728 | self.assertEqual(B.reported, 1) |
| 1729 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1730 | self.assertEqual(self.history[0].changes, '1,1') |
| 1731 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1732 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1733 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1734 | self.assertEqual(self.history[2].changes, '1,2') |
| 1735 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1736 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1737 | |
| 1738 | def test_abandoned_gate(self): |
| 1739 | "Test that an abandoned change is dequeued from gate" |
| 1740 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1741 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1742 | |
| 1743 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1744 | A.addApproval('code-review', 2) |
| 1745 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1746 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1747 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1748 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1749 | |
| 1750 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1751 | self.waitUntilSettled() |
| 1752 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1753 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1754 | self.waitUntilSettled() |
| 1755 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1756 | self.assertBuilds([]) |
| 1757 | self.assertHistory([ |
| 1758 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1759 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1760 | self.assertEqual(A.reported, 1, |
| 1761 | "Abandoned gate change should report only start") |
| 1762 | |
| 1763 | def test_abandoned_check(self): |
| 1764 | "Test that an abandoned change is dequeued from check" |
| 1765 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1766 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1767 | |
| 1768 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1769 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1770 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1771 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1772 | |
| 1773 | # Add two git-dependent changes |
| 1774 | B.setDependsOn(A, 1) |
| 1775 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1776 | self.waitUntilSettled() |
| 1777 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1778 | self.waitUntilSettled() |
| 1779 | # A live item, and a non-live/live pair |
| 1780 | items = check_pipeline.getAllItems() |
| 1781 | self.assertEqual(len(items), 3) |
| 1782 | |
| 1783 | self.assertEqual(items[0].change.number, '1') |
| 1784 | self.assertFalse(items[0].live) |
| 1785 | |
| 1786 | self.assertEqual(items[1].change.number, '2') |
| 1787 | self.assertTrue(items[1].live) |
| 1788 | |
| 1789 | self.assertEqual(items[2].change.number, '1') |
| 1790 | self.assertTrue(items[2].live) |
| 1791 | |
| 1792 | # Abandon A |
| 1793 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1794 | self.waitUntilSettled() |
| 1795 | |
| 1796 | # The live copy of A should be gone, but the non-live and B |
| 1797 | # should continue |
| 1798 | items = check_pipeline.getAllItems() |
| 1799 | self.assertEqual(len(items), 2) |
| 1800 | |
| 1801 | self.assertEqual(items[0].change.number, '1') |
| 1802 | self.assertFalse(items[0].live) |
| 1803 | |
| 1804 | self.assertEqual(items[1].change.number, '2') |
| 1805 | self.assertTrue(items[1].live) |
| 1806 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1807 | self.executor_server.hold_jobs_in_build = False |
| 1808 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1809 | self.waitUntilSettled() |
| 1810 | |
| 1811 | self.assertEqual(len(self.history), 4) |
| 1812 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1813 | 'Build should have been aborted') |
| 1814 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1815 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1816 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1817 | def test_abandoned_not_timer(self): |
| 1818 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1819 | # This test can not use simple_layout because it must start |
| 1820 | # with a configuration which does not include a |
| 1821 | # timer-triggered job so that we have an opportunity to set |
| 1822 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1823 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1824 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1825 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1826 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1827 | # The pipeline triggers every second, so we should have seen |
| 1828 | # several by now. |
| 1829 | time.sleep(5) |
| 1830 | self.waitUntilSettled() |
| 1831 | # Stop queuing timer triggered jobs so that the assertions |
| 1832 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1833 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1834 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1835 | self.sched.reconfigure(self.config) |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1836 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1837 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1838 | |
| 1839 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1840 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1841 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1842 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1843 | |
| 1844 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1845 | self.waitUntilSettled() |
| 1846 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1847 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1848 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1849 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1850 | self.waitUntilSettled() |
| 1851 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1852 | def test_zuul_url_return(self): |
| 1853 | "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf" |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1854 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1855 | self.executor_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1856 | |
| 1857 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1858 | A.addApproval('code-review', 2) |
| 1859 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1860 | self.waitUntilSettled() |
| 1861 | |
| 1862 | self.assertEqual(len(self.builds), 1) |
| 1863 | for build in self.builds: |
| 1864 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 1865 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1866 | self.executor_server.hold_jobs_in_build = False |
| 1867 | self.executor_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1868 | self.waitUntilSettled() |
| 1869 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1870 | def test_new_patchset_dequeues_old_on_head(self): |
| 1871 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1872 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1873 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1874 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1875 | M.setMerged() |
| 1876 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1877 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1878 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1879 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1880 | A.addApproval('code-review', 2) |
| 1881 | B.addApproval('code-review', 2) |
| 1882 | C.addApproval('code-review', 2) |
| 1883 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1884 | |
| 1885 | C.setDependsOn(B, 1) |
| 1886 | B.setDependsOn(A, 1) |
| 1887 | A.setDependsOn(M, 1) |
| 1888 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1889 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1890 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1891 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1892 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1893 | self.waitUntilSettled() |
| 1894 | |
| 1895 | A.addPatchset() |
| 1896 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1897 | self.waitUntilSettled() |
| 1898 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1899 | self.executor_server.hold_jobs_in_build = False |
| 1900 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1901 | self.waitUntilSettled() |
| 1902 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1903 | self.assertEqual(A.data['status'], 'NEW') |
| 1904 | self.assertEqual(A.reported, 2) |
| 1905 | self.assertEqual(B.data['status'], 'NEW') |
| 1906 | self.assertEqual(B.reported, 2) |
| 1907 | self.assertEqual(C.data['status'], 'NEW') |
| 1908 | self.assertEqual(C.reported, 2) |
| 1909 | self.assertEqual(D.data['status'], 'MERGED') |
| 1910 | self.assertEqual(D.reported, 2) |
| 1911 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1912 | |
| 1913 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1914 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1915 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1916 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1917 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1918 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1919 | A.addApproval('code-review', 2) |
| 1920 | B.addApproval('code-review', 2) |
| 1921 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1922 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1923 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1924 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1925 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1926 | self.waitUntilSettled() |
| 1927 | |
| 1928 | B.addPatchset() |
| 1929 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1930 | self.waitUntilSettled() |
| 1931 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1932 | self.executor_server.hold_jobs_in_build = False |
| 1933 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1934 | self.waitUntilSettled() |
| 1935 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1936 | self.assertEqual(A.data['status'], 'MERGED') |
| 1937 | self.assertEqual(A.reported, 2) |
| 1938 | self.assertEqual(B.data['status'], 'NEW') |
| 1939 | self.assertEqual(B.reported, 2) |
| 1940 | self.assertEqual(C.data['status'], 'MERGED') |
| 1941 | self.assertEqual(C.reported, 2) |
| 1942 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1943 | |
| 1944 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1945 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1946 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1947 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1948 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1949 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1950 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1951 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1952 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1953 | self.waitUntilSettled() |
| 1954 | |
| 1955 | B.addPatchset() |
| 1956 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1957 | self.waitUntilSettled() |
| 1958 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1959 | self.executor_server.hold_jobs_in_build = False |
| 1960 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1961 | self.waitUntilSettled() |
| 1962 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1963 | self.assertEqual(A.data['status'], 'NEW') |
| 1964 | self.assertEqual(A.reported, 1) |
| 1965 | self.assertEqual(B.data['status'], 'NEW') |
| 1966 | self.assertEqual(B.reported, 1) |
| 1967 | self.assertEqual(C.data['status'], 'NEW') |
| 1968 | self.assertEqual(C.reported, 1) |
| 1969 | self.assertEqual(len(self.history), 10) |
| 1970 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 1971 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1972 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1973 | def test_noop_job(self): |
| 1974 | "Test that the internal noop job works" |
| 1975 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1976 | A.addApproval('code-review', 2) |
| 1977 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 1978 | self.waitUntilSettled() |
| 1979 | |
| 1980 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 1981 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 1982 | self.assertEqual(len(self.history), 0) |
| 1983 | self.assertEqual(A.data['status'], 'MERGED') |
| 1984 | self.assertEqual(A.reported, 2) |
| 1985 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 1986 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 1987 | def test_no_job_project(self): |
| 1988 | "Test that reports with no jobs don't get sent" |
| 1989 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 1990 | 'master', 'A') |
| 1991 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1992 | self.waitUntilSettled() |
| 1993 | |
| 1994 | # Change wasn't reported to |
| 1995 | self.assertEqual(A.reported, False) |
| 1996 | |
| 1997 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 1998 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1999 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2000 | items = check_pipeline.getAllItems() |
| 2001 | self.assertEqual(len(items), 0) |
| 2002 | |
| 2003 | self.assertEqual(len(self.history), 0) |
| 2004 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2005 | def test_zuul_refs(self): |
| 2006 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2007 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2008 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2009 | M1.setMerged() |
| 2010 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2011 | M2.setMerged() |
| 2012 | |
| 2013 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2014 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2015 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2016 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2017 | A.addApproval('code-review', 2) |
| 2018 | B.addApproval('code-review', 2) |
| 2019 | C.addApproval('code-review', 2) |
| 2020 | D.addApproval('code-review', 2) |
| 2021 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2022 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2023 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2024 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2025 | |
| 2026 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2027 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2028 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2029 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2030 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2031 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2032 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2033 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2034 | self.waitUntilSettled() |
| 2035 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2036 | a_zref = b_zref = c_zref = d_zref = None |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2037 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2038 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2039 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2040 | a_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2041 | a_build = x |
| 2042 | elif x.parameters['ZUUL_CHANGE'] == '4': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2043 | b_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2044 | b_build = x |
| 2045 | elif x.parameters['ZUUL_CHANGE'] == '5': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2046 | c_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2047 | c_build = x |
| 2048 | elif x.parameters['ZUUL_CHANGE'] == '6': |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2049 | d_zref = x.parameters['ZUUL_REF'] |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2050 | d_build = x |
| 2051 | if a_build and b_build and c_build and d_build: |
| 2052 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2053 | |
| 2054 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2055 | self.assertIsNotNone(a_zref) |
| 2056 | self.assertIsNotNone(b_zref) |
| 2057 | self.assertIsNotNone(c_zref) |
| 2058 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2059 | |
| 2060 | # And they should all be different |
| 2061 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2062 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2063 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2064 | # should have a, not b, and should not be in project2 |
| 2065 | self.assertTrue(a_build.hasChanges(A)) |
| 2066 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2067 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2068 | # should have a and b, and should not be in project2 |
| 2069 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2070 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2071 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2072 | # should have a and b in 1, c in 2 |
| 2073 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2074 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2075 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2076 | # should have a and b in 1, c and d in 2 |
| 2077 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2078 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2079 | self.executor_server.hold_jobs_in_build = False |
| 2080 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2081 | self.waitUntilSettled() |
| 2082 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2083 | self.assertEqual(A.data['status'], 'MERGED') |
| 2084 | self.assertEqual(A.reported, 2) |
| 2085 | self.assertEqual(B.data['status'], 'MERGED') |
| 2086 | self.assertEqual(B.reported, 2) |
| 2087 | self.assertEqual(C.data['status'], 'MERGED') |
| 2088 | self.assertEqual(C.reported, 2) |
| 2089 | self.assertEqual(D.data['status'], 'MERGED') |
| 2090 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2091 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2092 | def test_rerun_on_error(self): |
| 2093 | "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] | 2094 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2095 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2096 | A.addApproval('code-review', 2) |
| 2097 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2098 | self.waitUntilSettled() |
| 2099 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2100 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2101 | self.executor_server.hold_jobs_in_build = False |
| 2102 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2103 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2104 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2105 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2106 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2107 | def test_statsd(self): |
| 2108 | "Test each of the statsd methods used in the scheduler" |
| 2109 | import extras |
| 2110 | statsd = extras.try_import('statsd.statsd') |
| 2111 | statsd.incr('test-incr') |
| 2112 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2113 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2114 | self.assertReportedStat('test-incr', '1|c') |
| 2115 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2116 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2117 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2118 | def test_stuck_job_cleanup(self): |
| 2119 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2120 | |
| 2121 | # 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] | 2122 | self.gearman_server.hold_jobs_in_queue = True |
| 2123 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2124 | A.addApproval('code-review', 2) |
| 2125 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2126 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2127 | # 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] | 2128 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2129 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2130 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2131 | self.sched.reconfigure(self.config) |
| 2132 | self.waitUntilSettled() |
| 2133 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2134 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2135 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2136 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2137 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2138 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2139 | |
| 2140 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2141 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2142 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2143 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2144 | def test_file_head(self): |
| 2145 | # This is a regression test for an observed bug. A change |
| 2146 | # with a file named "HEAD" in the root directory of the repo |
| 2147 | # was processed by a merger. It then was unable to reset the |
| 2148 | # repo because of: |
| 2149 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2150 | # with exit code 128 |
| 2151 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2152 | # and filename |
| 2153 | # Use '--' to separate filenames from revisions' |
| 2154 | |
| 2155 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2156 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2157 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2158 | |
| 2159 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2160 | self.waitUntilSettled() |
| 2161 | |
| 2162 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2163 | self.waitUntilSettled() |
| 2164 | |
| 2165 | self.assertIn('Build succeeded', A.messages[0]) |
| 2166 | self.assertIn('Build succeeded', B.messages[0]) |
| 2167 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2168 | def test_file_jobs(self): |
| 2169 | "Test that file jobs run only when appropriate" |
| 2170 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2171 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2172 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2173 | A.addApproval('code-review', 2) |
| 2174 | B.addApproval('code-review', 2) |
| 2175 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2176 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2177 | self.waitUntilSettled() |
| 2178 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2179 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2180 | if x.name == 'project-testfile'] |
| 2181 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2182 | self.assertEqual(len(testfile_jobs), 1) |
| 2183 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2184 | self.assertEqual(A.data['status'], 'MERGED') |
| 2185 | self.assertEqual(A.reported, 2) |
| 2186 | self.assertEqual(B.data['status'], 'MERGED') |
| 2187 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2188 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2189 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2190 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2191 | if should_skip: |
| 2192 | files = {'ignoreme': 'ignored\n'} |
| 2193 | else: |
| 2194 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2195 | |
| 2196 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2197 | 'master', |
| 2198 | 'test irrelevant-files', |
| 2199 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2200 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2201 | self.waitUntilSettled() |
| 2202 | |
| 2203 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2204 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2205 | |
| 2206 | if should_skip: |
| 2207 | self.assertEqual([], tested_change_ids) |
| 2208 | else: |
| 2209 | self.assertIn(change.data['number'], tested_change_ids) |
| 2210 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2211 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2212 | def test_irrelevant_files_match_skips_job(self): |
| 2213 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2214 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2215 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2216 | def test_irrelevant_files_no_match_runs_job(self): |
| 2217 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2218 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2219 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2220 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2221 | files = {'ignoreme': 'ignored\n'} |
| 2222 | |
| 2223 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2224 | 'master', |
| 2225 | 'test irrelevant-files', |
| 2226 | files=files) |
| 2227 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2228 | self.waitUntilSettled() |
| 2229 | |
| 2230 | run_jobs = set([build.name for build in self.history]) |
| 2231 | |
| 2232 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2233 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2234 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2235 | def test_queue_names(self): |
| 2236 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2237 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2238 | (trusted, project1) = tenant.getProject('org/project1') |
| 2239 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2240 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2241 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2242 | self.assertEqual(q1.name, 'integrated') |
| 2243 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2244 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2245 | def test_queue_precedence(self): |
| 2246 | "Test that queue precedence works" |
| 2247 | |
| 2248 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2249 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2250 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2251 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2252 | A.addApproval('code-review', 2) |
| 2253 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2254 | |
| 2255 | self.waitUntilSettled() |
| 2256 | self.gearman_server.hold_jobs_in_queue = False |
| 2257 | self.gearman_server.release() |
| 2258 | self.waitUntilSettled() |
| 2259 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2260 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2261 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2262 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2263 | self.waitUntilSettled() |
| 2264 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2265 | self.log.debug(self.history) |
| 2266 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2267 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2268 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2269 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2270 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2271 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2272 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2273 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2274 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2275 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2276 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2277 | A.addApproval('code-review', 2) |
| 2278 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2279 | self.waitUntilSettled() |
| 2280 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2281 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2282 | self.waitUntilSettled() |
| 2283 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2284 | port = self.webapp.server.socket.getsockname()[1] |
| 2285 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2286 | req = urllib.request.Request( |
| 2287 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2288 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2289 | headers = f.info() |
| 2290 | self.assertIn('Content-Length', headers) |
| 2291 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2292 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2293 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2294 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2295 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2296 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2297 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2298 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2300 | self.executor_server.hold_jobs_in_build = False |
| 2301 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2302 | self.waitUntilSettled() |
| 2303 | |
| 2304 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2305 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2306 | for p in data['pipelines']: |
| 2307 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2308 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2309 | self.assertEqual(q['window'], 20) |
| 2310 | else: |
| 2311 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2312 | for head in q['heads']: |
| 2313 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2314 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2315 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2316 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2317 | status_jobs.append(job) |
| 2318 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2319 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2320 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2321 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2322 | uuid=status_jobs[0]['uuid']), |
| 2323 | status_jobs[0]['url']) |
| 2324 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2325 | 'finger://{hostname}/{uuid}'.format( |
| 2326 | hostname=self.executor_server.hostname, |
| 2327 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2328 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2329 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2330 | self.assertEqual( |
| 2331 | 'finger://{hostname}/{uuid}'.format( |
| 2332 | hostname=self.executor_server.hostname, |
| 2333 | uuid=status_jobs[0]['uuid']), |
| 2334 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2335 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2336 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2337 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2338 | uuid=status_jobs[1]['uuid']), |
| 2339 | status_jobs[1]['url']) |
| 2340 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2341 | 'finger://{hostname}/{uuid}'.format( |
| 2342 | hostname=self.executor_server.hostname, |
| 2343 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2344 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2345 | self.assertEqual( |
| 2346 | 'finger://{hostname}/{uuid}'.format( |
| 2347 | hostname=self.executor_server.hostname, |
| 2348 | uuid=status_jobs[1]['uuid']), |
| 2349 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2350 | |
| 2351 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2352 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2353 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2354 | uuid=status_jobs[2]['uuid']), |
| 2355 | status_jobs[2]['url']) |
| 2356 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2357 | 'finger://{hostname}/{uuid}'.format( |
| 2358 | hostname=self.executor_server.hostname, |
| 2359 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2360 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2361 | self.assertEqual( |
| 2362 | 'finger://{hostname}/{uuid}'.format( |
| 2363 | hostname=self.executor_server.hostname, |
| 2364 | uuid=status_jobs[2]['uuid']), |
| 2365 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2366 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2367 | # check job dependencies |
| 2368 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2369 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2370 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2371 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2372 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2373 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2374 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2375 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2376 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2377 | def test_live_reconfiguration(self): |
| 2378 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2379 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2380 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2381 | A.addApproval('code-review', 2) |
| 2382 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2383 | self.waitUntilSettled() |
| 2384 | |
| 2385 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2386 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2387 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2388 | self.executor_server.hold_jobs_in_build = False |
| 2389 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2390 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2391 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2392 | 'SUCCESS') |
| 2393 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2394 | 'SUCCESS') |
| 2395 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2396 | 'SUCCESS') |
| 2397 | self.assertEqual(A.data['status'], 'MERGED') |
| 2398 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2399 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2400 | def test_live_reconfiguration_merge_conflict(self): |
| 2401 | # A real-world bug: a change in a gate queue has a merge |
| 2402 | # conflict and a job is added to its project while it's |
| 2403 | # sitting in the queue. The job gets added to the change and |
| 2404 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2405 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2406 | |
| 2407 | # This change is fine. It's here to stop the queue long |
| 2408 | # enough for the next change to be subject to the |
| 2409 | # reconfiguration, as well as to provide a conflict for the |
| 2410 | # next change. This change will succeed and merge. |
| 2411 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2412 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2413 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2414 | |
| 2415 | # This change will be in merge conflict. During the |
| 2416 | # reconfiguration, we will add a job. We want to make sure |
| 2417 | # that doesn't cause it to get stuck. |
| 2418 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2419 | B.addPatchset({'conflict': 'B'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2420 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2421 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2422 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2423 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2424 | |
| 2425 | self.waitUntilSettled() |
| 2426 | |
| 2427 | # No jobs have run yet |
| 2428 | self.assertEqual(A.data['status'], 'NEW') |
| 2429 | self.assertEqual(A.reported, 1) |
| 2430 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2431 | self.assertEqual(len(self.history), 0) |
| 2432 | |
| 2433 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2434 | self.commitConfigUpdate('common-config', |
| 2435 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2436 | self.sched.reconfigure(self.config) |
| 2437 | self.waitUntilSettled() |
| 2438 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2439 | self.executor_server.hold_jobs_in_build = False |
| 2440 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2441 | self.waitUntilSettled() |
| 2442 | |
| 2443 | self.assertEqual(A.data['status'], 'MERGED') |
| 2444 | self.assertEqual(A.reported, 2) |
| 2445 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2446 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2447 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2448 | 'SUCCESS') |
| 2449 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2450 | 'SUCCESS') |
| 2451 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2452 | 'SUCCESS') |
| 2453 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2454 | 'SUCCESS') |
| 2455 | self.assertEqual(len(self.history), 4) |
| 2456 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2457 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2458 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2459 | # that tests a job added to a job tree with a failed root does |
| 2460 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2461 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2462 | |
| 2463 | # This change is fine. It's here to stop the queue long |
| 2464 | # enough for the next change to be subject to the |
| 2465 | # reconfiguration. This change will succeed and merge. |
| 2466 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2467 | A.addPatchset({'conflict': 'A'}) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2468 | A.addApproval('code-review', 2) |
| 2469 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2470 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2471 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2472 | self.waitUntilSettled() |
| 2473 | |
| 2474 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2475 | self.executor_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2476 | B.addApproval('code-review', 2) |
| 2477 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2478 | self.waitUntilSettled() |
| 2479 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2480 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2481 | self.waitUntilSettled() |
| 2482 | |
| 2483 | # Both -merge jobs have run, but no others. |
| 2484 | self.assertEqual(A.data['status'], 'NEW') |
| 2485 | self.assertEqual(A.reported, 1) |
| 2486 | self.assertEqual(B.data['status'], 'NEW') |
| 2487 | self.assertEqual(B.reported, 1) |
| 2488 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2489 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2490 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2491 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2492 | self.assertEqual(len(self.history), 2) |
| 2493 | |
| 2494 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2495 | self.commitConfigUpdate('common-config', |
| 2496 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2497 | self.sched.reconfigure(self.config) |
| 2498 | self.waitUntilSettled() |
| 2499 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2500 | self.executor_server.hold_jobs_in_build = False |
| 2501 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2502 | self.waitUntilSettled() |
| 2503 | |
| 2504 | self.assertEqual(A.data['status'], 'MERGED') |
| 2505 | self.assertEqual(A.reported, 2) |
| 2506 | self.assertEqual(B.data['status'], 'NEW') |
| 2507 | self.assertEqual(B.reported, 2) |
| 2508 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2509 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2510 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2511 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2512 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2513 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2514 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2515 | self.assertEqual(len(self.history), 5) |
| 2516 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2517 | def test_live_reconfiguration_failed_job(self): |
| 2518 | # Test that a change with a removed failing job does not |
| 2519 | # disrupt reconfiguration. If a change has a failed job and |
| 2520 | # that job is removed during a reconfiguration, we observed a |
| 2521 | # bug where the code to re-set build statuses would run on |
| 2522 | # that build and raise an exception because the job no longer |
| 2523 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2524 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2525 | |
| 2526 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2527 | |
| 2528 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2529 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2530 | |
| 2531 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2532 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2533 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2534 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2535 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2536 | self.waitUntilSettled() |
| 2537 | |
| 2538 | self.assertEqual(A.data['status'], 'NEW') |
| 2539 | self.assertEqual(A.reported, 0) |
| 2540 | |
| 2541 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2542 | 'SUCCESS') |
| 2543 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2544 | 'FAILURE') |
| 2545 | self.assertEqual(len(self.history), 2) |
| 2546 | |
| 2547 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2548 | self.commitConfigUpdate('common-config', |
| 2549 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2550 | self.sched.reconfigure(self.config) |
| 2551 | self.waitUntilSettled() |
| 2552 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2553 | self.executor_server.hold_jobs_in_build = False |
| 2554 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2555 | self.waitUntilSettled() |
| 2556 | |
| 2557 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2558 | 'SUCCESS') |
| 2559 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2560 | 'SUCCESS') |
| 2561 | self.assertEqual(len(self.history), 4) |
| 2562 | |
| 2563 | self.assertEqual(A.data['status'], 'NEW') |
| 2564 | self.assertEqual(A.reported, 1) |
| 2565 | self.assertIn('Build succeeded', A.messages[0]) |
| 2566 | # Ensure the removed job was not included in the report. |
| 2567 | self.assertNotIn('project-test1', A.messages[0]) |
| 2568 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2569 | def test_live_reconfiguration_shared_queue(self): |
| 2570 | # Test that a change with a failing job which was removed from |
| 2571 | # this project but otherwise still exists in the system does |
| 2572 | # not disrupt reconfiguration. |
| 2573 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2574 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2575 | |
| 2576 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2577 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2578 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2579 | |
| 2580 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2581 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2582 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2583 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2584 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2585 | self.waitUntilSettled() |
| 2586 | |
| 2587 | self.assertEqual(A.data['status'], 'NEW') |
| 2588 | self.assertEqual(A.reported, 0) |
| 2589 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2590 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2591 | 'SUCCESS') |
| 2592 | self.assertEqual(self.getJobFromHistory( |
| 2593 | 'project1-project2-integration').result, 'FAILURE') |
| 2594 | self.assertEqual(len(self.history), 2) |
| 2595 | |
| 2596 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2597 | self.commitConfigUpdate( |
| 2598 | 'common-config', |
| 2599 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2600 | self.sched.reconfigure(self.config) |
| 2601 | self.waitUntilSettled() |
| 2602 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2603 | self.executor_server.hold_jobs_in_build = False |
| 2604 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2605 | self.waitUntilSettled() |
| 2606 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2607 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2608 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2609 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2610 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2611 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2612 | 'SUCCESS') |
| 2613 | self.assertEqual(self.getJobFromHistory( |
| 2614 | 'project1-project2-integration').result, 'FAILURE') |
| 2615 | self.assertEqual(len(self.history), 4) |
| 2616 | |
| 2617 | self.assertEqual(A.data['status'], 'NEW') |
| 2618 | self.assertEqual(A.reported, 1) |
| 2619 | self.assertIn('Build succeeded', A.messages[0]) |
| 2620 | # Ensure the removed job was not included in the report. |
| 2621 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2622 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2623 | def test_double_live_reconfiguration_shared_queue(self): |
| 2624 | # This was a real-world regression. A change is added to |
| 2625 | # gate; a reconfigure happens, a second change which depends |
| 2626 | # on the first is added, and a second reconfiguration happens. |
| 2627 | # Ensure that both changes merge. |
| 2628 | |
| 2629 | # A failure may indicate incorrect caching or cleaning up of |
| 2630 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2631 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2632 | |
| 2633 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2634 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2635 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2636 | A.addApproval('code-review', 2) |
| 2637 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2638 | |
| 2639 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2640 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2641 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2642 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2643 | self.waitUntilSettled() |
| 2644 | |
| 2645 | # Reconfigure (with only one change in the pipeline). |
| 2646 | self.sched.reconfigure(self.config) |
| 2647 | self.waitUntilSettled() |
| 2648 | |
| 2649 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2650 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2651 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2652 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2653 | self.waitUntilSettled() |
| 2654 | |
| 2655 | # Reconfigure (with both in the pipeline). |
| 2656 | self.sched.reconfigure(self.config) |
| 2657 | self.waitUntilSettled() |
| 2658 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2659 | self.executor_server.hold_jobs_in_build = False |
| 2660 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2661 | self.waitUntilSettled() |
| 2662 | |
| 2663 | self.assertEqual(len(self.history), 8) |
| 2664 | |
| 2665 | self.assertEqual(A.data['status'], 'MERGED') |
| 2666 | self.assertEqual(A.reported, 2) |
| 2667 | self.assertEqual(B.data['status'], 'MERGED') |
| 2668 | self.assertEqual(B.reported, 2) |
| 2669 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2670 | def test_live_reconfiguration_del_project(self): |
| 2671 | # Test project deletion from layout |
| 2672 | # while changes are enqueued |
| 2673 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2674 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2675 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2676 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2677 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2678 | |
| 2679 | # A Depends-On: B |
| 2680 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2681 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2682 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2683 | |
| 2684 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2685 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2686 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2687 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2688 | self.waitUntilSettled() |
| 2689 | self.assertEqual(len(self.builds), 5) |
| 2690 | |
| 2691 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2692 | self.commitConfigUpdate( |
| 2693 | 'common-config', |
| 2694 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2695 | self.sched.reconfigure(self.config) |
| 2696 | self.waitUntilSettled() |
| 2697 | |
| 2698 | # Builds for C aborted, builds for A succeed, |
| 2699 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2700 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2701 | self.assertEqual(job_c.changes, '3,1') |
| 2702 | self.assertEqual(job_c.result, 'ABORTED') |
| 2703 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2704 | self.executor_server.hold_jobs_in_build = False |
| 2705 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2706 | self.waitUntilSettled() |
| 2707 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2708 | self.assertEqual( |
| 2709 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2710 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2711 | |
| 2712 | self.assertEqual(A.data['status'], 'NEW') |
| 2713 | self.assertEqual(B.data['status'], 'NEW') |
| 2714 | self.assertEqual(C.data['status'], 'NEW') |
| 2715 | self.assertEqual(A.reported, 1) |
| 2716 | self.assertEqual(B.reported, 0) |
| 2717 | self.assertEqual(C.reported, 0) |
| 2718 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2719 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2720 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2721 | self.assertIn('Build succeeded', A.messages[0]) |
| 2722 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2723 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2724 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2725 | self.updateConfigLayout( |
| 2726 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2727 | self.sched.reconfigure(self.config) |
| 2728 | |
| 2729 | self.init_repo("org/new-project") |
| 2730 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2731 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2732 | A.addApproval('code-review', 2) |
| 2733 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2734 | self.waitUntilSettled() |
| 2735 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2736 | 'SUCCESS') |
| 2737 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2738 | 'SUCCESS') |
| 2739 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2740 | 'SUCCESS') |
| 2741 | self.assertEqual(A.data['status'], 'MERGED') |
| 2742 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2743 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2744 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2745 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2746 | self.init_repo("org/delete-project") |
| 2747 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2748 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2749 | A.addApproval('code-review', 2) |
| 2750 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2751 | self.waitUntilSettled() |
| 2752 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2753 | 'SUCCESS') |
| 2754 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2755 | 'SUCCESS') |
| 2756 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2757 | 'SUCCESS') |
| 2758 | self.assertEqual(A.data['status'], 'MERGED') |
| 2759 | self.assertEqual(A.reported, 2) |
| 2760 | |
| 2761 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2762 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2763 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2764 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2765 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2766 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2767 | |
| 2768 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2769 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2770 | B.addApproval('code-review', 2) |
| 2771 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2772 | self.waitUntilSettled() |
| 2773 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2774 | 'SUCCESS') |
| 2775 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2776 | 'SUCCESS') |
| 2777 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2778 | 'SUCCESS') |
| 2779 | self.assertEqual(B.data['status'], 'MERGED') |
| 2780 | self.assertEqual(B.reported, 2) |
| 2781 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2782 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2783 | def test_tags(self): |
| 2784 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2785 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2786 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2787 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2788 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2789 | self.waitUntilSettled() |
| 2790 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2791 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2792 | |
| 2793 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2794 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2795 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2796 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2797 | |
| 2798 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2799 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2800 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2801 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2802 | def test_timer(self): |
| 2803 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2804 | # This test can not use simple_layout because it must start |
| 2805 | # with a configuration which does not include a |
| 2806 | # timer-triggered job so that we have an opportunity to set |
| 2807 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2808 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2809 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2810 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2811 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2812 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2813 | # The pipeline triggers every second, so we should have seen |
| 2814 | # several by now. |
| 2815 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2816 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2817 | |
| 2818 | self.assertEqual(len(self.builds), 2) |
| 2819 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2820 | port = self.webapp.server.socket.getsockname()[1] |
| 2821 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2822 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2823 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2824 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2825 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2826 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2827 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2828 | # Stop queuing timer triggered jobs so that the assertions |
| 2829 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2830 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2831 | self.sched.reconfigure(self.config) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2832 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2833 | self.waitUntilSettled() |
| 2834 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2835 | self.assertHistory([ |
| 2836 | dict(name='project-bitrot', result='SUCCESS', |
| 2837 | ref='refs/heads/master'), |
| 2838 | dict(name='project-bitrot', result='SUCCESS', |
| 2839 | ref='refs/heads/stable'), |
| 2840 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2841 | |
| 2842 | data = json.loads(data) |
| 2843 | status_jobs = set() |
| 2844 | for p in data['pipelines']: |
| 2845 | for q in p['change_queues']: |
| 2846 | for head in q['heads']: |
| 2847 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2848 | for job in change['jobs']: |
| 2849 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2850 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2851 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2852 | def test_idle(self): |
| 2853 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2854 | # This test can not use simple_layout because it must start |
| 2855 | # with a configuration which does not include a |
| 2856 | # timer-triggered job so that we have an opportunity to set |
| 2857 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2858 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2859 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2860 | for x in range(1, 3): |
| 2861 | # Test that timer triggers periodic jobs even across |
| 2862 | # layout config reloads. |
| 2863 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2864 | self.commitConfigUpdate('common-config', |
| 2865 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2866 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2867 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2868 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2869 | # The pipeline triggers every second, so we should have seen |
| 2870 | # several by now. |
| 2871 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2872 | |
| 2873 | # Stop queuing timer triggered jobs so that the assertions |
| 2874 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2875 | self.commitConfigUpdate('common-config', |
| 2876 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2877 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2878 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2879 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2880 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2881 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2882 | self.waitUntilSettled() |
| 2883 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2884 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2885 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2886 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2887 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2888 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2889 | self.waitUntilSettled() |
| 2890 | |
| 2891 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2892 | self.waitUntilSettled() |
| 2893 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2894 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2895 | |
| 2896 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2897 | # work on the knowledge of what the first message should be as |
| 2898 | # it is only configured to go to SMTP. |
| 2899 | |
| 2900 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2901 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2902 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2903 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2904 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2905 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2906 | |
| 2907 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2908 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2909 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2910 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2911 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2912 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2913 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2914 | def test_timer_smtp(self): |
| 2915 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2916 | # This test can not use simple_layout because it must start |
| 2917 | # with a configuration which does not include a |
| 2918 | # timer-triggered job so that we have an opportunity to set |
| 2919 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2920 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2921 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2922 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2923 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2924 | # The pipeline triggers every second, so we should have seen |
| 2925 | # several by now. |
| 2926 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2927 | self.waitUntilSettled() |
| 2928 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2929 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2930 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2931 | self.waitUntilSettled() |
| 2932 | self.assertEqual(len(self.history), 2) |
| 2933 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2934 | self.assertEqual(self.getJobFromHistory( |
| 2935 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2936 | self.assertEqual(self.getJobFromHistory( |
| 2937 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2938 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2939 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2940 | |
| 2941 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2942 | # work on the knowledge of what the first message should be as |
| 2943 | # it is only configured to go to SMTP. |
| 2944 | |
| 2945 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2946 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2947 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2948 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2949 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2950 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2951 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2952 | # Stop queuing timer triggered jobs and let any that may have |
| 2953 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2954 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2955 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2956 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2957 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2958 | self.waitUntilSettled() |
| 2959 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 2960 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 2961 | def test_timer_sshkey(self): |
| 2962 | "Test that a periodic job can setup SSH key authentication" |
| 2963 | self.worker.hold_jobs_in_build = True |
| 2964 | self.config.set('zuul', 'layout_config', |
| 2965 | 'tests/fixtures/layout-timer.yaml') |
| 2966 | self.sched.reconfigure(self.config) |
| 2967 | self.registerJobs() |
| 2968 | |
| 2969 | # The pipeline triggers every second, so we should have seen |
| 2970 | # several by now. |
| 2971 | time.sleep(5) |
| 2972 | self.waitUntilSettled() |
| 2973 | |
| 2974 | self.assertEqual(len(self.builds), 2) |
| 2975 | |
| 2976 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 2977 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 2978 | with open(ssh_wrapper) as f: |
| 2979 | ssh_wrapper_content = f.read() |
| 2980 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 2981 | # In the unit tests Merger runs in the same process, |
| 2982 | # so we see its' environment variables |
| 2983 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 2984 | |
| 2985 | self.worker.release('.*') |
| 2986 | self.waitUntilSettled() |
| 2987 | self.assertEqual(len(self.history), 2) |
| 2988 | |
| 2989 | self.assertEqual(self.getJobFromHistory( |
| 2990 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2991 | self.assertEqual(self.getJobFromHistory( |
| 2992 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2993 | |
| 2994 | # Stop queuing timer triggered jobs and let any that may have |
| 2995 | # queued through so that end of test assertions pass. |
| 2996 | self.config.set('zuul', 'layout_config', |
| 2997 | 'tests/fixtures/layout-no-timer.yaml') |
| 2998 | self.sched.reconfigure(self.config) |
| 2999 | self.registerJobs() |
| 3000 | self.waitUntilSettled() |
| 3001 | self.worker.release('.*') |
| 3002 | self.waitUntilSettled() |
| 3003 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3004 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3005 | "Test that the RPC client can enqueue a change" |
| 3006 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3007 | A.addApproval('code-review', 2) |
| 3008 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3009 | |
| 3010 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3011 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3012 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3013 | r = client.enqueue(tenant='tenant-one', |
| 3014 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3015 | project='org/project', |
| 3016 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3017 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3018 | self.waitUntilSettled() |
| 3019 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3020 | 'SUCCESS') |
| 3021 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3022 | 'SUCCESS') |
| 3023 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3024 | 'SUCCESS') |
| 3025 | self.assertEqual(A.data['status'], 'MERGED') |
| 3026 | self.assertEqual(A.reported, 2) |
| 3027 | self.assertEqual(r, True) |
| 3028 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3029 | def test_client_enqueue_ref(self): |
| 3030 | "Test that the RPC client can enqueue a ref" |
| 3031 | |
| 3032 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3033 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3034 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3035 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3036 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3037 | pipeline='post', |
| 3038 | project='org/project', |
| 3039 | trigger='gerrit', |
| 3040 | ref='master', |
| 3041 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3042 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3043 | self.waitUntilSettled() |
| 3044 | job_names = [x.name for x in self.history] |
| 3045 | self.assertEqual(len(self.history), 1) |
| 3046 | self.assertIn('project-post', job_names) |
| 3047 | self.assertEqual(r, True) |
| 3048 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3049 | def test_client_enqueue_negative(self): |
| 3050 | "Test that the RPC client returns errors" |
| 3051 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3052 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3053 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3054 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3055 | "Invalid tenant"): |
| 3056 | r = client.enqueue(tenant='tenant-foo', |
| 3057 | pipeline='gate', |
| 3058 | project='org/project', |
| 3059 | trigger='gerrit', |
| 3060 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3061 | self.assertEqual(r, False) |
| 3062 | |
| 3063 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3064 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3065 | r = client.enqueue(tenant='tenant-one', |
| 3066 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3067 | project='project-does-not-exist', |
| 3068 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3069 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3070 | self.assertEqual(r, False) |
| 3071 | |
| 3072 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3073 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3074 | r = client.enqueue(tenant='tenant-one', |
| 3075 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3076 | project='org/project', |
| 3077 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3078 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3079 | self.assertEqual(r, False) |
| 3080 | |
| 3081 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3082 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3083 | r = client.enqueue(tenant='tenant-one', |
| 3084 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3085 | project='org/project', |
| 3086 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3087 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3088 | self.assertEqual(r, False) |
| 3089 | |
| 3090 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3091 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3092 | r = client.enqueue(tenant='tenant-one', |
| 3093 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3094 | project='org/project', |
| 3095 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3096 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3097 | self.assertEqual(r, False) |
| 3098 | |
| 3099 | self.waitUntilSettled() |
| 3100 | self.assertEqual(len(self.history), 0) |
| 3101 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3102 | |
| 3103 | def test_client_promote(self): |
| 3104 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3105 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3106 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3107 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3108 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3109 | A.addApproval('code-review', 2) |
| 3110 | B.addApproval('code-review', 2) |
| 3111 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3112 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3113 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3114 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3115 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3116 | |
| 3117 | self.waitUntilSettled() |
| 3118 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3119 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3120 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3121 | enqueue_times = {} |
| 3122 | for item in items: |
| 3123 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3124 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3125 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3126 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3127 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3128 | r = client.promote(tenant='tenant-one', |
| 3129 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3130 | change_ids=['2,1', '3,1']) |
| 3131 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3132 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3133 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3134 | for item in items: |
| 3135 | self.assertEqual( |
| 3136 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3137 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3138 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3139 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3140 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3141 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3142 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3143 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3144 | self.waitUntilSettled() |
| 3145 | |
| 3146 | self.assertEqual(len(self.builds), 6) |
| 3147 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3148 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3149 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3150 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3151 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3152 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3153 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3154 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3155 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3156 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3157 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3158 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3159 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3160 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3161 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3162 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3163 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3164 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3166 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3167 | self.waitUntilSettled() |
| 3168 | |
| 3169 | self.assertEqual(A.data['status'], 'MERGED') |
| 3170 | self.assertEqual(A.reported, 2) |
| 3171 | self.assertEqual(B.data['status'], 'MERGED') |
| 3172 | self.assertEqual(B.reported, 2) |
| 3173 | self.assertEqual(C.data['status'], 'MERGED') |
| 3174 | self.assertEqual(C.reported, 2) |
| 3175 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3176 | self.assertEqual(r, True) |
| 3177 | |
| 3178 | def test_client_promote_dependent(self): |
| 3179 | "Test that the RPC client can promote a dependent change" |
| 3180 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3181 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3182 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3183 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3184 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3185 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3186 | |
| 3187 | C.setDependsOn(B, 1) |
| 3188 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3189 | A.addApproval('code-review', 2) |
| 3190 | B.addApproval('code-review', 2) |
| 3191 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3192 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3193 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3194 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3195 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3196 | |
| 3197 | self.waitUntilSettled() |
| 3198 | |
| 3199 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3200 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3201 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3202 | r = client.promote(tenant='tenant-one', |
| 3203 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3204 | change_ids=['3,1']) |
| 3205 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3206 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3207 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3208 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3209 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3211 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3212 | self.waitUntilSettled() |
| 3213 | |
| 3214 | self.assertEqual(len(self.builds), 6) |
| 3215 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3216 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3217 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3218 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3219 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3220 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3221 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3222 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3223 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3224 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3225 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3226 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3227 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3228 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3229 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3230 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3231 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3232 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3233 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3234 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3235 | self.waitUntilSettled() |
| 3236 | |
| 3237 | self.assertEqual(A.data['status'], 'MERGED') |
| 3238 | self.assertEqual(A.reported, 2) |
| 3239 | self.assertEqual(B.data['status'], 'MERGED') |
| 3240 | self.assertEqual(B.reported, 2) |
| 3241 | self.assertEqual(C.data['status'], 'MERGED') |
| 3242 | self.assertEqual(C.reported, 2) |
| 3243 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3244 | self.assertEqual(r, True) |
| 3245 | |
| 3246 | def test_client_promote_negative(self): |
| 3247 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3248 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3249 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3250 | A.addApproval('code-review', 2) |
| 3251 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3252 | self.waitUntilSettled() |
| 3253 | |
| 3254 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3255 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3256 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3257 | |
| 3258 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3259 | r = client.promote(tenant='tenant-one', |
| 3260 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3261 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3262 | self.assertEqual(r, False) |
| 3263 | |
| 3264 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3265 | r = client.promote(tenant='tenant-one', |
| 3266 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3267 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3268 | self.assertEqual(r, False) |
| 3269 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3270 | self.executor_server.hold_jobs_in_build = False |
| 3271 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3272 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3273 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3274 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3275 | def test_queue_rate_limiting(self): |
| 3276 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3277 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3278 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3279 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3280 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3281 | |
| 3282 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3283 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3284 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3285 | A.addApproval('code-review', 2) |
| 3286 | B.addApproval('code-review', 2) |
| 3287 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3288 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3289 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3290 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3291 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3292 | self.waitUntilSettled() |
| 3293 | |
| 3294 | # Only A and B will have their merge jobs queued because |
| 3295 | # window is 2. |
| 3296 | self.assertEqual(len(self.builds), 2) |
| 3297 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3298 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3299 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3300 | # Release the merge jobs one at a time. |
| 3301 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3302 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3303 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3304 | self.waitUntilSettled() |
| 3305 | |
| 3306 | # Only A and B will have their test jobs queued because |
| 3307 | # window is 2. |
| 3308 | self.assertEqual(len(self.builds), 4) |
| 3309 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3310 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3311 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3312 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3313 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3314 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3315 | self.waitUntilSettled() |
| 3316 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3317 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3318 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3319 | # A failed so window is reduced by 1 to 1. |
| 3320 | self.assertEqual(queue.window, 1) |
| 3321 | self.assertEqual(queue.window_floor, 1) |
| 3322 | self.assertEqual(A.data['status'], 'NEW') |
| 3323 | |
| 3324 | # Gate is reset and only B's merge job is queued because |
| 3325 | # window shrunk to 1. |
| 3326 | self.assertEqual(len(self.builds), 1) |
| 3327 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3328 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3329 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3330 | self.waitUntilSettled() |
| 3331 | |
| 3332 | # Only B's test jobs are queued because window is still 1. |
| 3333 | self.assertEqual(len(self.builds), 2) |
| 3334 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3335 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3336 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3337 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3338 | self.waitUntilSettled() |
| 3339 | |
| 3340 | # B was successfully merged so window is increased to 2. |
| 3341 | self.assertEqual(queue.window, 2) |
| 3342 | self.assertEqual(queue.window_floor, 1) |
| 3343 | self.assertEqual(B.data['status'], 'MERGED') |
| 3344 | |
| 3345 | # Only C is left and its merge job is queued. |
| 3346 | self.assertEqual(len(self.builds), 1) |
| 3347 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3348 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3349 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3350 | self.waitUntilSettled() |
| 3351 | |
| 3352 | # After successful merge job the test jobs for C are queued. |
| 3353 | self.assertEqual(len(self.builds), 2) |
| 3354 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3355 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3356 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3357 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3358 | self.waitUntilSettled() |
| 3359 | |
| 3360 | # C successfully merged so window is bumped to 3. |
| 3361 | self.assertEqual(queue.window, 3) |
| 3362 | self.assertEqual(queue.window_floor, 1) |
| 3363 | self.assertEqual(C.data['status'], 'MERGED') |
| 3364 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3365 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3366 | def test_queue_rate_limiting_dependent(self): |
| 3367 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3368 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3369 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3370 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3371 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3372 | |
| 3373 | B.setDependsOn(A, 1) |
| 3374 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3375 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3376 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3377 | A.addApproval('code-review', 2) |
| 3378 | B.addApproval('code-review', 2) |
| 3379 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3380 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3381 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3382 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3383 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3384 | self.waitUntilSettled() |
| 3385 | |
| 3386 | # Only A and B will have their merge jobs queued because |
| 3387 | # window is 2. |
| 3388 | self.assertEqual(len(self.builds), 2) |
| 3389 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3390 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3391 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3392 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3393 | |
| 3394 | # Only A and B will have their test jobs queued because |
| 3395 | # window is 2. |
| 3396 | self.assertEqual(len(self.builds), 4) |
| 3397 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3398 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3399 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3400 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3401 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3402 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3403 | self.waitUntilSettled() |
| 3404 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3405 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3406 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3407 | # A failed so window is reduced by 1 to 1. |
| 3408 | self.assertEqual(queue.window, 1) |
| 3409 | self.assertEqual(queue.window_floor, 1) |
| 3410 | self.assertEqual(A.data['status'], 'NEW') |
| 3411 | self.assertEqual(B.data['status'], 'NEW') |
| 3412 | |
| 3413 | # Gate is reset and only C's merge job is queued because |
| 3414 | # window shrunk to 1 and A and B were dequeued. |
| 3415 | self.assertEqual(len(self.builds), 1) |
| 3416 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3417 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3418 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3419 | |
| 3420 | # Only C's test jobs are queued because window is still 1. |
| 3421 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3422 | builds = self.getSortedBuilds() |
| 3423 | self.assertEqual(builds[0].name, 'project-test1') |
| 3424 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3425 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3426 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3427 | self.waitUntilSettled() |
| 3428 | |
| 3429 | # C was successfully merged so window is increased to 2. |
| 3430 | self.assertEqual(queue.window, 2) |
| 3431 | self.assertEqual(queue.window_floor, 1) |
| 3432 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3433 | |
| 3434 | def test_worker_update_metadata(self): |
| 3435 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3436 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3437 | |
| 3438 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3439 | A.addApproval('code-review', 2) |
| 3440 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3441 | self.waitUntilSettled() |
| 3442 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3443 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3444 | |
| 3445 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3446 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3447 | |
| 3448 | start = time.time() |
| 3449 | while True: |
| 3450 | if time.time() - start > 10: |
| 3451 | raise Exception("Timeout waiting for gearman server to report " |
| 3452 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3453 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3454 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3455 | break |
| 3456 | else: |
| 3457 | time.sleep(0) |
| 3458 | |
| 3459 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3460 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3461 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3462 | self.executor_server.hold_jobs_in_build = False |
| 3463 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3464 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3465 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3466 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3467 | def test_footer_message(self): |
| 3468 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3469 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3470 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3471 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3472 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3473 | self.waitUntilSettled() |
| 3474 | |
| 3475 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3476 | B.addApproval('code-review', 2) |
| 3477 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3478 | self.waitUntilSettled() |
| 3479 | |
| 3480 | self.assertEqual(2, len(self.smtp_messages)) |
| 3481 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3482 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3483 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3484 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3485 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3486 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3487 | For CI problems and help debugging, contact ci@example.org""" |
| 3488 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3489 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3490 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3491 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3492 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3493 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3494 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3495 | def test_unmanaged_project_start_message(self): |
| 3496 | "Test start reporting is not done for unmanaged projects." |
| 3497 | self.init_repo("org/project", tag='init') |
| 3498 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3499 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3500 | self.waitUntilSettled() |
| 3501 | |
| 3502 | self.assertEqual(0, len(A.messages)) |
| 3503 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3504 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3505 | def test_merge_failure_reporters(self): |
| 3506 | """Check that the config is set up correctly""" |
| 3507 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3508 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3509 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3510 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3511 | "dependencies was unable to be automatically merged with the " |
| 3512 | "current state of its repository. Please rebase the change and " |
| 3513 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3514 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3515 | self.assertEqual( |
| 3516 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3517 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3518 | |
| 3519 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3520 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3521 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3522 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3523 | |
| 3524 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3525 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3526 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3527 | |
| 3528 | self.assertTrue( |
| 3529 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3530 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3531 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3532 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3533 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3534 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3535 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3536 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3537 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3538 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3539 | gerritreporter.GerritReporter) and |
| 3540 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3541 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3542 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3543 | ) |
| 3544 | ) |
| 3545 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3546 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3547 | def test_merge_failure_reports(self): |
| 3548 | """Check that when a change fails to merge the correct message is sent |
| 3549 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3550 | self.updateConfigLayout( |
| 3551 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3552 | self.sched.reconfigure(self.config) |
| 3553 | self.registerJobs() |
| 3554 | |
| 3555 | # Check a test failure isn't reported to SMTP |
| 3556 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3557 | A.addApproval('code-review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3558 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3559 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3560 | self.waitUntilSettled() |
| 3561 | |
| 3562 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3563 | self.assertEqual(0, len(self.smtp_messages)) |
| 3564 | |
| 3565 | # Check a merge failure is reported to SMTP |
| 3566 | # B should be merged, but C will conflict with B |
| 3567 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3568 | B.addPatchset(['conflict']) |
| 3569 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3570 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3571 | B.addApproval('code-review', 2) |
| 3572 | C.addApproval('code-review', 2) |
| 3573 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3574 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3575 | self.waitUntilSettled() |
| 3576 | |
| 3577 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3578 | self.assertEqual(1, len(self.smtp_messages)) |
| 3579 | self.assertEqual('The merge failed! For more information...', |
| 3580 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3581 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3582 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3583 | def test_default_merge_failure_reports(self): |
| 3584 | """Check that the default merge failure reports are correct.""" |
| 3585 | |
| 3586 | # A should report success, B should report merge failure. |
| 3587 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3588 | A.addPatchset(['conflict']) |
| 3589 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3590 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3591 | A.addApproval('code-review', 2) |
| 3592 | B.addApproval('code-review', 2) |
| 3593 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3594 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3595 | self.waitUntilSettled() |
| 3596 | |
| 3597 | self.assertEqual(3, len(self.history)) # A jobs |
| 3598 | self.assertEqual(A.reported, 2) |
| 3599 | self.assertEqual(B.reported, 2) |
| 3600 | self.assertEqual(A.data['status'], 'MERGED') |
| 3601 | self.assertEqual(B.data['status'], 'NEW') |
| 3602 | self.assertIn('Build succeeded', A.messages[1]) |
| 3603 | self.assertIn('Merge Failed', B.messages[1]) |
| 3604 | self.assertIn('automatically merged', B.messages[1]) |
| 3605 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3606 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3607 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3608 | def test_client_get_running_jobs(self): |
| 3609 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3610 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3611 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3612 | A.addApproval('code-review', 2) |
| 3613 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3614 | self.waitUntilSettled() |
| 3615 | |
| 3616 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3617 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3618 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3619 | |
| 3620 | # Wait for gearman server to send the initial workData back to zuul |
| 3621 | start = time.time() |
| 3622 | while True: |
| 3623 | if time.time() - start > 10: |
| 3624 | raise Exception("Timeout waiting for gearman server to report " |
| 3625 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3626 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3627 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3628 | break |
| 3629 | else: |
| 3630 | time.sleep(0) |
| 3631 | |
| 3632 | running_items = client.get_running_jobs() |
| 3633 | |
| 3634 | self.assertEqual(1, len(running_items)) |
| 3635 | running_item = running_items[0] |
| 3636 | self.assertEqual([], running_item['failing_reasons']) |
| 3637 | self.assertEqual([], running_item['items_behind']) |
| 3638 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3639 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3640 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3641 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3642 | self.assertEqual(True, running_item['active']) |
| 3643 | self.assertEqual('1,1', running_item['id']) |
| 3644 | |
| 3645 | self.assertEqual(3, len(running_item['jobs'])) |
| 3646 | for job in running_item['jobs']: |
| 3647 | if job['name'] == 'project-merge': |
| 3648 | self.assertEqual('project-merge', job['name']) |
| 3649 | self.assertEqual('gate', job['pipeline']) |
| 3650 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3651 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3652 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3653 | .format(uuid=job['uuid']), job['url']) |
| 3654 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3655 | 'finger://{hostname}/{uuid}'.format( |
| 3656 | hostname=self.executor_server.hostname, |
| 3657 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3658 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3659 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3660 | self.assertEqual(False, job['canceled']) |
| 3661 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3662 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3663 | self.assertEqual('gate', job['pipeline']) |
| 3664 | break |
| 3665 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3666 | self.executor_server.hold_jobs_in_build = False |
| 3667 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3668 | self.waitUntilSettled() |
| 3669 | |
| 3670 | running_items = client.get_running_jobs() |
| 3671 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3672 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3673 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3674 | def test_nonvoting_pipeline(self): |
| 3675 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3676 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3677 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3678 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3679 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3680 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3681 | |
| 3682 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3683 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3684 | self.assertEqual( |
| 3685 | self.getJobFromHistory('experimental-project-test').result, |
| 3686 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3687 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3688 | |
| 3689 | def test_crd_gate(self): |
| 3690 | "Test cross-repo dependencies" |
| 3691 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3692 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3693 | A.addApproval('code-review', 2) |
| 3694 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3695 | |
| 3696 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3697 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3698 | AM2.setMerged() |
| 3699 | AM1.setMerged() |
| 3700 | |
| 3701 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3702 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3703 | BM2.setMerged() |
| 3704 | BM1.setMerged() |
| 3705 | |
| 3706 | # A -> AM1 -> AM2 |
| 3707 | # B -> BM1 -> BM2 |
| 3708 | # A Depends-On: B |
| 3709 | # M2 is here to make sure it is never queried. If it is, it |
| 3710 | # means zuul is walking down the entire history of merged |
| 3711 | # changes. |
| 3712 | |
| 3713 | B.setDependsOn(BM1, 1) |
| 3714 | BM1.setDependsOn(BM2, 1) |
| 3715 | |
| 3716 | A.setDependsOn(AM1, 1) |
| 3717 | AM1.setDependsOn(AM2, 1) |
| 3718 | |
| 3719 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3720 | A.subject, B.data['id']) |
| 3721 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3722 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3723 | self.waitUntilSettled() |
| 3724 | |
| 3725 | self.assertEqual(A.data['status'], 'NEW') |
| 3726 | self.assertEqual(B.data['status'], 'NEW') |
| 3727 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3728 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3729 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3730 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3731 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3732 | B.addApproval('approved', 1) |
| 3733 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3734 | self.waitUntilSettled() |
| 3735 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3736 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3737 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3738 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3739 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3740 | self.executor_server.hold_jobs_in_build = False |
| 3741 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3742 | self.waitUntilSettled() |
| 3743 | |
| 3744 | self.assertEqual(AM2.queried, 0) |
| 3745 | self.assertEqual(BM2.queried, 0) |
| 3746 | self.assertEqual(A.data['status'], 'MERGED') |
| 3747 | self.assertEqual(B.data['status'], 'MERGED') |
| 3748 | self.assertEqual(A.reported, 2) |
| 3749 | self.assertEqual(B.reported, 2) |
| 3750 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3751 | changes = self.getJobFromHistory( |
| 3752 | 'project-merge', 'org/project1').changes |
| 3753 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3754 | |
| 3755 | def test_crd_branch(self): |
| 3756 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3757 | |
| 3758 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3759 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3760 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3761 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3762 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3763 | A.addApproval('code-review', 2) |
| 3764 | B.addApproval('code-review', 2) |
| 3765 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3766 | |
| 3767 | # A Depends-On: B+C |
| 3768 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3769 | A.subject, B.data['id']) |
| 3770 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3771 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3772 | B.addApproval('approved', 1) |
| 3773 | C.addApproval('approved', 1) |
| 3774 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3775 | self.waitUntilSettled() |
| 3776 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3777 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3778 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3779 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3780 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3781 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3782 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3783 | self.executor_server.hold_jobs_in_build = False |
| 3784 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3785 | self.waitUntilSettled() |
| 3786 | |
| 3787 | self.assertEqual(A.data['status'], 'MERGED') |
| 3788 | self.assertEqual(B.data['status'], 'MERGED') |
| 3789 | self.assertEqual(C.data['status'], 'MERGED') |
| 3790 | self.assertEqual(A.reported, 2) |
| 3791 | self.assertEqual(B.reported, 2) |
| 3792 | self.assertEqual(C.reported, 2) |
| 3793 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3794 | changes = self.getJobFromHistory( |
| 3795 | 'project-merge', 'org/project1').changes |
| 3796 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3797 | |
| 3798 | def test_crd_multiline(self): |
| 3799 | "Test multiple depends-on lines in commit" |
| 3800 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3801 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3802 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3803 | A.addApproval('code-review', 2) |
| 3804 | B.addApproval('code-review', 2) |
| 3805 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3806 | |
| 3807 | # A Depends-On: B+C |
| 3808 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3809 | A.subject, B.data['id'], C.data['id']) |
| 3810 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3811 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3812 | B.addApproval('approved', 1) |
| 3813 | C.addApproval('approved', 1) |
| 3814 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3815 | self.waitUntilSettled() |
| 3816 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3817 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3818 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3819 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3820 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3821 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3822 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3823 | self.executor_server.hold_jobs_in_build = False |
| 3824 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3825 | self.waitUntilSettled() |
| 3826 | |
| 3827 | self.assertEqual(A.data['status'], 'MERGED') |
| 3828 | self.assertEqual(B.data['status'], 'MERGED') |
| 3829 | self.assertEqual(C.data['status'], 'MERGED') |
| 3830 | self.assertEqual(A.reported, 2) |
| 3831 | self.assertEqual(B.reported, 2) |
| 3832 | self.assertEqual(C.reported, 2) |
| 3833 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3834 | changes = self.getJobFromHistory( |
| 3835 | 'project-merge', 'org/project1').changes |
| 3836 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3837 | |
| 3838 | def test_crd_unshared_gate(self): |
| 3839 | "Test cross-repo dependencies in unshared gate queues" |
| 3840 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3841 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3842 | A.addApproval('code-review', 2) |
| 3843 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3844 | |
| 3845 | # A Depends-On: B |
| 3846 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3847 | A.subject, B.data['id']) |
| 3848 | |
| 3849 | # A and B do not share a queue, make sure that A is unable to |
| 3850 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3851 | B.addApproval('approved', 1) |
| 3852 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3853 | self.waitUntilSettled() |
| 3854 | |
| 3855 | self.assertEqual(A.data['status'], 'NEW') |
| 3856 | self.assertEqual(B.data['status'], 'NEW') |
| 3857 | self.assertEqual(A.reported, 0) |
| 3858 | self.assertEqual(B.reported, 0) |
| 3859 | self.assertEqual(len(self.history), 0) |
| 3860 | |
| 3861 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3862 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3863 | self.waitUntilSettled() |
| 3864 | |
| 3865 | self.assertEqual(B.data['status'], 'MERGED') |
| 3866 | self.assertEqual(B.reported, 2) |
| 3867 | |
| 3868 | # Now that B is merged, A should be able to be enqueued and |
| 3869 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3870 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3871 | self.waitUntilSettled() |
| 3872 | |
| 3873 | self.assertEqual(A.data['status'], 'MERGED') |
| 3874 | self.assertEqual(A.reported, 2) |
| 3875 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3876 | def test_crd_gate_reverse(self): |
| 3877 | "Test reverse cross-repo dependencies" |
| 3878 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3879 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3880 | A.addApproval('code-review', 2) |
| 3881 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3882 | |
| 3883 | # A Depends-On: B |
| 3884 | |
| 3885 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3886 | A.subject, B.data['id']) |
| 3887 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3888 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3889 | self.waitUntilSettled() |
| 3890 | |
| 3891 | self.assertEqual(A.data['status'], 'NEW') |
| 3892 | self.assertEqual(B.data['status'], 'NEW') |
| 3893 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3894 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3895 | A.addApproval('approved', 1) |
| 3896 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3897 | self.waitUntilSettled() |
| 3898 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3899 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3900 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3901 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3902 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3903 | self.executor_server.hold_jobs_in_build = False |
| 3904 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3905 | self.waitUntilSettled() |
| 3906 | |
| 3907 | self.assertEqual(A.data['status'], 'MERGED') |
| 3908 | self.assertEqual(B.data['status'], 'MERGED') |
| 3909 | self.assertEqual(A.reported, 2) |
| 3910 | self.assertEqual(B.reported, 2) |
| 3911 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3912 | changes = self.getJobFromHistory( |
| 3913 | 'project-merge', 'org/project1').changes |
| 3914 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3915 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3916 | def test_crd_cycle(self): |
| 3917 | "Test cross-repo dependency cycles" |
| 3918 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3919 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3920 | A.addApproval('code-review', 2) |
| 3921 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3922 | |
| 3923 | # A -> B -> A (via commit-depends) |
| 3924 | |
| 3925 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3926 | A.subject, B.data['id']) |
| 3927 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3928 | B.subject, A.data['id']) |
| 3929 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3930 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3931 | self.waitUntilSettled() |
| 3932 | |
| 3933 | self.assertEqual(A.reported, 0) |
| 3934 | self.assertEqual(B.reported, 0) |
| 3935 | self.assertEqual(A.data['status'], 'NEW') |
| 3936 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3937 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3938 | def test_crd_gate_unknown(self): |
| 3939 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 3940 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3941 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3942 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3943 | A.addApproval('code-review', 2) |
| 3944 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3945 | |
| 3946 | # A Depends-On: B |
| 3947 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3948 | A.subject, B.data['id']) |
| 3949 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3950 | B.addApproval('approved', 1) |
| 3951 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3952 | self.waitUntilSettled() |
| 3953 | |
| 3954 | # Unknown projects cannot share a queue with any other |
| 3955 | # since they don't have common jobs with any other (they have no jobs). |
| 3956 | # Changes which depend on unknown project changes |
| 3957 | # should not be processed in dependent pipeline |
| 3958 | self.assertEqual(A.data['status'], 'NEW') |
| 3959 | self.assertEqual(B.data['status'], 'NEW') |
| 3960 | self.assertEqual(A.reported, 0) |
| 3961 | self.assertEqual(B.reported, 0) |
| 3962 | self.assertEqual(len(self.history), 0) |
| 3963 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 3964 | # Simulate change B being gated outside this layout Set the |
| 3965 | # change merged before submitting the event so that when the |
| 3966 | # event triggers a gerrit query to update the change, we get |
| 3967 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3968 | B.setMerged() |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 3969 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3970 | self.waitUntilSettled() |
| 3971 | self.assertEqual(len(self.history), 0) |
| 3972 | |
| 3973 | # Now that B is merged, A should be able to be enqueued and |
| 3974 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3975 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3976 | self.waitUntilSettled() |
| 3977 | |
| 3978 | self.assertEqual(A.data['status'], 'MERGED') |
| 3979 | self.assertEqual(A.reported, 2) |
| 3980 | self.assertEqual(B.data['status'], 'MERGED') |
| 3981 | self.assertEqual(B.reported, 0) |
| 3982 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3983 | def test_crd_check(self): |
| 3984 | "Test cross-repo dependencies in independent pipelines" |
| 3985 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3986 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3987 | self.gearman_server.hold_jobs_in_queue = True |
| 3988 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3989 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3990 | |
| 3991 | # A Depends-On: B |
| 3992 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3993 | A.subject, B.data['id']) |
| 3994 | |
| 3995 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3996 | self.waitUntilSettled() |
| 3997 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3998 | self.gearman_server.hold_jobs_in_queue = False |
| 3999 | self.gearman_server.release() |
| 4000 | self.waitUntilSettled() |
| 4001 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4002 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4003 | self.waitUntilSettled() |
| 4004 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4005 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4006 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4007 | self.executor_server.hold_jobs_in_build = False |
| 4008 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4009 | self.waitUntilSettled() |
| 4010 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4011 | self.assertEqual(A.data['status'], 'NEW') |
| 4012 | self.assertEqual(B.data['status'], 'NEW') |
| 4013 | self.assertEqual(A.reported, 1) |
| 4014 | self.assertEqual(B.reported, 0) |
| 4015 | |
| 4016 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4017 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4018 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4019 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4020 | def test_crd_check_git_depends(self): |
| 4021 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4022 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4023 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4024 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4025 | |
| 4026 | # Add two git-dependent changes and make sure they both report |
| 4027 | # success. |
| 4028 | B.setDependsOn(A, 1) |
| 4029 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4030 | self.waitUntilSettled() |
| 4031 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4032 | self.waitUntilSettled() |
| 4033 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4034 | self.orderedRelease() |
| 4035 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4036 | self.waitUntilSettled() |
| 4037 | |
| 4038 | self.assertEqual(A.data['status'], 'NEW') |
| 4039 | self.assertEqual(B.data['status'], 'NEW') |
| 4040 | self.assertEqual(A.reported, 1) |
| 4041 | self.assertEqual(B.reported, 1) |
| 4042 | |
| 4043 | self.assertEqual(self.history[0].changes, '1,1') |
| 4044 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4045 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4046 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4047 | |
| 4048 | self.assertIn('Build succeeded', A.messages[0]) |
| 4049 | self.assertIn('Build succeeded', B.messages[0]) |
| 4050 | |
| 4051 | def test_crd_check_duplicate(self): |
| 4052 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4053 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4054 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4055 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4056 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4057 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4058 | |
| 4059 | # Add two git-dependent changes... |
| 4060 | B.setDependsOn(A, 1) |
| 4061 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4062 | self.waitUntilSettled() |
| 4063 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4064 | |
| 4065 | # ...make sure the live one is not duplicated... |
| 4066 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4067 | self.waitUntilSettled() |
| 4068 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4069 | |
| 4070 | # ...but the non-live one is able to be. |
| 4071 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4072 | self.waitUntilSettled() |
| 4073 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4074 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4075 | # Release jobs in order to avoid races with change A jobs |
| 4076 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4077 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4078 | self.executor_server.hold_jobs_in_build = False |
| 4079 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4080 | self.waitUntilSettled() |
| 4081 | |
| 4082 | self.assertEqual(A.data['status'], 'NEW') |
| 4083 | self.assertEqual(B.data['status'], 'NEW') |
| 4084 | self.assertEqual(A.reported, 1) |
| 4085 | self.assertEqual(B.reported, 1) |
| 4086 | |
| 4087 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4088 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4089 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4090 | |
| 4091 | self.assertIn('Build succeeded', A.messages[0]) |
| 4092 | self.assertIn('Build succeeded', B.messages[0]) |
| 4093 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4094 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4095 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4096 | |
| 4097 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4098 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4099 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4100 | |
| 4101 | # A Depends-On: B |
| 4102 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4103 | A.subject, B.data['id']) |
| 4104 | |
| 4105 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4106 | self.waitUntilSettled() |
| 4107 | |
| 4108 | self.sched.reconfigure(self.config) |
| 4109 | |
| 4110 | # Make sure the items still share a change queue, and the |
| 4111 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4112 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4113 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4114 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4115 | first_item = queue.queue[0] |
| 4116 | for item in queue.queue: |
| 4117 | self.assertEqual(item.queue, first_item.queue) |
| 4118 | self.assertFalse(first_item.live) |
| 4119 | self.assertTrue(queue.queue[1].live) |
| 4120 | |
| 4121 | self.gearman_server.hold_jobs_in_queue = False |
| 4122 | self.gearman_server.release() |
| 4123 | self.waitUntilSettled() |
| 4124 | |
| 4125 | self.assertEqual(A.data['status'], 'NEW') |
| 4126 | self.assertEqual(B.data['status'], 'NEW') |
| 4127 | self.assertEqual(A.reported, 1) |
| 4128 | self.assertEqual(B.reported, 0) |
| 4129 | |
| 4130 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4131 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4132 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4133 | def test_crd_check_reconfiguration(self): |
| 4134 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4135 | |
| 4136 | def test_crd_undefined_project(self): |
| 4137 | """Test that undefined projects in dependencies are handled for |
| 4138 | independent pipelines""" |
| 4139 | # It's a hack for fake gerrit, |
| 4140 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4141 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4142 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4143 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4144 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4145 | def test_crd_check_ignore_dependencies(self): |
| 4146 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4147 | |
| 4148 | self.gearman_server.hold_jobs_in_queue = True |
| 4149 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4150 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4151 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4152 | |
| 4153 | # A Depends-On: B |
| 4154 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4155 | A.subject, B.data['id']) |
| 4156 | # C git-depends on B |
| 4157 | C.setDependsOn(B, 1) |
| 4158 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4159 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4160 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4161 | self.waitUntilSettled() |
| 4162 | |
| 4163 | # Make sure none of the items share a change queue, and all |
| 4164 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4165 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4166 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4167 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4168 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4169 | for item in check_pipeline.getAllItems(): |
| 4170 | self.assertTrue(item.live) |
| 4171 | |
| 4172 | self.gearman_server.hold_jobs_in_queue = False |
| 4173 | self.gearman_server.release() |
| 4174 | self.waitUntilSettled() |
| 4175 | |
| 4176 | self.assertEqual(A.data['status'], 'NEW') |
| 4177 | self.assertEqual(B.data['status'], 'NEW') |
| 4178 | self.assertEqual(C.data['status'], 'NEW') |
| 4179 | self.assertEqual(A.reported, 1) |
| 4180 | self.assertEqual(B.reported, 1) |
| 4181 | self.assertEqual(C.reported, 1) |
| 4182 | |
| 4183 | # Each job should have tested exactly one change |
| 4184 | for job in self.history: |
| 4185 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4186 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4187 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4188 | def test_crd_check_transitive(self): |
| 4189 | "Test transitive cross-repo dependencies" |
| 4190 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4191 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4192 | # and C,2 (not C,1 which would indicate stale data in the |
| 4193 | # cache for B). |
| 4194 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4195 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4196 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4197 | |
| 4198 | # A Depends-On: B |
| 4199 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4200 | A.subject, B.data['id']) |
| 4201 | |
| 4202 | # B Depends-On: C |
| 4203 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4204 | B.subject, C.data['id']) |
| 4205 | |
| 4206 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4207 | self.waitUntilSettled() |
| 4208 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4209 | |
| 4210 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4211 | self.waitUntilSettled() |
| 4212 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4213 | |
| 4214 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4215 | self.waitUntilSettled() |
| 4216 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4217 | |
| 4218 | C.addPatchset() |
| 4219 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4220 | self.waitUntilSettled() |
| 4221 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4222 | |
| 4223 | A.addPatchset() |
| 4224 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4225 | self.waitUntilSettled() |
| 4226 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4227 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4228 | def test_crd_check_unknown(self): |
| 4229 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4230 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4231 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4232 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4233 | # A Depends-On: B |
| 4234 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4235 | A.subject, B.data['id']) |
| 4236 | |
| 4237 | # Make sure zuul has seen an event on B. |
| 4238 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4239 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4240 | self.waitUntilSettled() |
| 4241 | |
| 4242 | self.assertEqual(A.data['status'], 'NEW') |
| 4243 | self.assertEqual(A.reported, 1) |
| 4244 | self.assertEqual(B.data['status'], 'NEW') |
| 4245 | self.assertEqual(B.reported, 0) |
| 4246 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4247 | def test_crd_cycle_join(self): |
| 4248 | "Test an updated change creates a cycle" |
| 4249 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4250 | |
| 4251 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4252 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4253 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4254 | |
| 4255 | # Create B->A |
| 4256 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4257 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4258 | B.subject, A.data['id']) |
| 4259 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4260 | self.waitUntilSettled() |
| 4261 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4262 | # Dep is there so zuul should have reported on B |
| 4263 | self.assertEqual(B.reported, 1) |
| 4264 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4265 | # Update A to add A->B (a cycle). |
| 4266 | A.addPatchset() |
| 4267 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4268 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4269 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4270 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4271 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4272 | # Dependency cycle injected so zuul should not have reported again on A |
| 4273 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4274 | |
| 4275 | # Now if we update B to remove the depends-on, everything |
| 4276 | # should be okay. B; A->B |
| 4277 | |
| 4278 | B.addPatchset() |
| 4279 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4280 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4281 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4282 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4283 | # Cycle was removed so now zuul should have reported again on A |
| 4284 | self.assertEqual(A.reported, 2) |
| 4285 | |
| 4286 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4287 | self.waitUntilSettled() |
| 4288 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4289 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4290 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4291 | def test_disable_at(self): |
| 4292 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4293 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4294 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4295 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4296 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4297 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4298 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4299 | |
| 4300 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4301 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4302 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4303 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4304 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4305 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4306 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4307 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4308 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4309 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4310 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4311 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4312 | self.executor_server.failJob('project-test1', A) |
| 4313 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4314 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4315 | self.executor_server.failJob('project-test1', D) |
| 4316 | self.executor_server.failJob('project-test1', E) |
| 4317 | self.executor_server.failJob('project-test1', F) |
| 4318 | self.executor_server.failJob('project-test1', G) |
| 4319 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4320 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4321 | self.executor_server.failJob('project-test1', J) |
| 4322 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4323 | |
| 4324 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4325 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4326 | self.waitUntilSettled() |
| 4327 | |
| 4328 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4329 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4330 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4331 | |
| 4332 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4333 | self.waitUntilSettled() |
| 4334 | |
| 4335 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4336 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4337 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4338 | |
| 4339 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4340 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4341 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4342 | self.waitUntilSettled() |
| 4343 | |
| 4344 | # We should be disabled now |
| 4345 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4346 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4347 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4348 | |
| 4349 | # We need to wait between each of these patches to make sure the |
| 4350 | # smtp messages come back in an expected order |
| 4351 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4352 | self.waitUntilSettled() |
| 4353 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4354 | self.waitUntilSettled() |
| 4355 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4356 | self.waitUntilSettled() |
| 4357 | |
| 4358 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4359 | # leaving a message on each change |
| 4360 | self.assertEqual(1, len(A.messages)) |
| 4361 | self.assertIn('Build failed.', A.messages[0]) |
| 4362 | self.assertEqual(1, len(B.messages)) |
| 4363 | self.assertIn('Build failed.', B.messages[0]) |
| 4364 | self.assertEqual(1, len(C.messages)) |
| 4365 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4366 | self.assertEqual(1, len(D.messages)) |
| 4367 | self.assertIn('Build failed.', D.messages[0]) |
| 4368 | self.assertEqual(1, len(E.messages)) |
| 4369 | self.assertIn('Build failed.', E.messages[0]) |
| 4370 | self.assertEqual(1, len(F.messages)) |
| 4371 | self.assertIn('Build failed.', F.messages[0]) |
| 4372 | |
| 4373 | # The last 3 (GHI) would have only reported via smtp. |
| 4374 | self.assertEqual(3, len(self.smtp_messages)) |
| 4375 | self.assertEqual(0, len(G.messages)) |
| 4376 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4377 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4378 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4379 | self.assertEqual(0, len(H.messages)) |
| 4380 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4381 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4382 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4383 | self.assertEqual(0, len(I.messages)) |
| 4384 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4385 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4386 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4387 | |
| 4388 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4389 | # comes out of disabled |
| 4390 | self.sched.reconfigure(self.config) |
| 4391 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4392 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4393 | |
| 4394 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4395 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4396 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4397 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4398 | |
| 4399 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4400 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4401 | self.waitUntilSettled() |
| 4402 | |
| 4403 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4404 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4405 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4406 | |
| 4407 | # J and K went back to gerrit |
| 4408 | self.assertEqual(1, len(J.messages)) |
| 4409 | self.assertIn('Build failed.', J.messages[0]) |
| 4410 | self.assertEqual(1, len(K.messages)) |
| 4411 | self.assertIn('Build failed.', K.messages[0]) |
| 4412 | # No more messages reported via smtp |
| 4413 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4414 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4415 | @simple_layout('layouts/one-job-project.yaml') |
| 4416 | def test_one_job_project(self): |
| 4417 | "Test that queueing works with one job" |
| 4418 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4419 | 'master', 'A') |
| 4420 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4421 | 'master', 'B') |
| 4422 | A.addApproval('code-review', 2) |
| 4423 | B.addApproval('code-review', 2) |
| 4424 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4425 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4426 | self.waitUntilSettled() |
| 4427 | |
| 4428 | self.assertEqual(A.data['status'], 'MERGED') |
| 4429 | self.assertEqual(A.reported, 2) |
| 4430 | self.assertEqual(B.data['status'], 'MERGED') |
| 4431 | self.assertEqual(B.reported, 2) |
| 4432 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4433 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4434 | "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] | 4435 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4436 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4437 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4438 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4439 | self.waitUntilSettled() |
| 4440 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4441 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4442 | self.waitUntilSettled() |
| 4443 | |
| 4444 | self.assertEqual(len(self.builds), 2) |
| 4445 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4446 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4447 | self.waitUntilSettled() |
| 4448 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4449 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4450 | self.assertEqual(len(self.builds), 1, |
| 4451 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4452 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4453 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4454 | self.waitUntilSettled() |
| 4455 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4456 | self.executor_server.hold_jobs_in_build = False |
| 4457 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4458 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4459 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4460 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4461 | self.assertEqual(A.reported, 1) |
| 4462 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4463 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4464 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4465 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4466 | |
| 4467 | self.fake_nodepool.paused = True |
| 4468 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4469 | A.addApproval('code-review', 2) |
| 4470 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4471 | self.waitUntilSettled() |
| 4472 | |
| 4473 | self.zk.client.stop() |
| 4474 | self.zk.client.start() |
| 4475 | self.fake_nodepool.paused = False |
| 4476 | self.waitUntilSettled() |
| 4477 | |
| 4478 | self.assertEqual(A.data['status'], 'MERGED') |
| 4479 | self.assertEqual(A.reported, 2) |
| 4480 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4481 | def test_nodepool_failure(self): |
| 4482 | "Test that jobs are reported after a nodepool failure" |
| 4483 | |
| 4484 | self.fake_nodepool.paused = True |
| 4485 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4486 | A.addApproval('code-review', 2) |
| 4487 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4488 | self.waitUntilSettled() |
| 4489 | |
| 4490 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4491 | self.fake_nodepool.addFailRequest(req) |
| 4492 | |
| 4493 | self.fake_nodepool.paused = False |
| 4494 | self.waitUntilSettled() |
| 4495 | |
| 4496 | self.assertEqual(A.data['status'], 'NEW') |
| 4497 | self.assertEqual(A.reported, 2) |
| 4498 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4499 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4500 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4501 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4502 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4503 | class TestExecutor(ZuulTestCase): |
| 4504 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4505 | |
| 4506 | def assertFinalState(self): |
| 4507 | # In this test, we expect to shut down in a non-final state, |
| 4508 | # so skip these checks. |
| 4509 | pass |
| 4510 | |
| 4511 | def assertCleanShutdown(self): |
| 4512 | self.log.debug("Assert clean shutdown") |
| 4513 | |
| 4514 | # After shutdown, make sure no jobs are running |
| 4515 | self.assertEqual({}, self.executor_server.job_workers) |
| 4516 | |
| 4517 | # Make sure that git.Repo objects have been garbage collected. |
| 4518 | repos = [] |
| 4519 | gc.collect() |
| 4520 | for obj in gc.get_objects(): |
| 4521 | if isinstance(obj, git.Repo): |
| 4522 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4523 | repos.append(obj) |
| 4524 | self.assertEqual(len(repos), 0) |
| 4525 | |
| 4526 | def test_executor_shutdown(self): |
| 4527 | "Test that the executor can shut down with jobs running" |
| 4528 | |
| 4529 | self.executor_server.hold_jobs_in_build = True |
| 4530 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4531 | A.addApproval('code-review', 2) |
| 4532 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4533 | self.waitUntilSettled() |
| 4534 | |
| 4535 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4536 | class TestDependencyGraph(ZuulTestCase): |
| 4537 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4538 | |
| 4539 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4540 | "Test a job in a dependency graph is queued only once" |
| 4541 | # Job dependencies, starting with A |
| 4542 | # A |
| 4543 | # / \ |
| 4544 | # B C |
| 4545 | # / \ / \ |
| 4546 | # D F E |
| 4547 | # | |
| 4548 | # G |
| 4549 | |
| 4550 | self.executor_server.hold_jobs_in_build = True |
| 4551 | change = self.fake_gerrit.addFakeChange( |
| 4552 | 'org/project', 'master', 'change') |
| 4553 | change.addApproval('code-review', 2) |
| 4554 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4555 | |
| 4556 | self.waitUntilSettled() |
| 4557 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4558 | |
| 4559 | self.executor_server.release('A') |
| 4560 | self.waitUntilSettled() |
| 4561 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4562 | |
| 4563 | self.executor_server.release('B') |
| 4564 | self.waitUntilSettled() |
| 4565 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4566 | |
| 4567 | self.executor_server.release('D') |
| 4568 | self.waitUntilSettled() |
| 4569 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4570 | |
| 4571 | self.executor_server.release('C') |
| 4572 | self.waitUntilSettled() |
| 4573 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4574 | |
| 4575 | self.executor_server.release('F') |
| 4576 | self.waitUntilSettled() |
| 4577 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4578 | |
| 4579 | self.executor_server.release('G') |
| 4580 | self.waitUntilSettled() |
| 4581 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4582 | |
| 4583 | self.executor_server.release('E') |
| 4584 | self.waitUntilSettled() |
| 4585 | self.assertEqual(len(self.builds), 0) |
| 4586 | |
| 4587 | self.executor_server.hold_jobs_in_build = False |
| 4588 | self.executor_server.release() |
| 4589 | self.waitUntilSettled() |
| 4590 | |
| 4591 | self.assertEqual(len(self.builds), 0) |
| 4592 | self.assertEqual(len(self.history), 7) |
| 4593 | |
| 4594 | self.assertEqual(change.data['status'], 'MERGED') |
| 4595 | self.assertEqual(change.reported, 2) |
| 4596 | |
| 4597 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4598 | "Test that a job waits till all dependencies are successful" |
| 4599 | # Job dependencies, starting with A |
| 4600 | # A |
| 4601 | # / \ |
| 4602 | # B C* |
| 4603 | # / \ / \ |
| 4604 | # D F E |
| 4605 | # | |
| 4606 | # G |
| 4607 | |
| 4608 | self.executor_server.hold_jobs_in_build = True |
| 4609 | change = self.fake_gerrit.addFakeChange( |
| 4610 | 'org/project', 'master', 'change') |
| 4611 | change.addApproval('code-review', 2) |
| 4612 | |
| 4613 | self.executor_server.failJob('C', change) |
| 4614 | |
| 4615 | self.fake_gerrit.addEvent(change.addApproval('approved', 1)) |
| 4616 | |
| 4617 | self.waitUntilSettled() |
| 4618 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4619 | |
| 4620 | self.executor_server.release('A') |
| 4621 | self.waitUntilSettled() |
| 4622 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4623 | |
| 4624 | self.executor_server.release('B') |
| 4625 | self.waitUntilSettled() |
| 4626 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4627 | |
| 4628 | self.executor_server.release('D') |
| 4629 | self.waitUntilSettled() |
| 4630 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4631 | |
| 4632 | self.executor_server.release('C') |
| 4633 | self.waitUntilSettled() |
| 4634 | self.assertEqual(len(self.builds), 0) |
| 4635 | |
| 4636 | self.executor_server.hold_jobs_in_build = False |
| 4637 | self.executor_server.release() |
| 4638 | self.waitUntilSettled() |
| 4639 | |
| 4640 | self.assertEqual(len(self.builds), 0) |
| 4641 | self.assertEqual(len(self.history), 4) |
| 4642 | |
| 4643 | self.assertEqual(change.data['status'], 'NEW') |
| 4644 | self.assertEqual(change.reported, 2) |
| 4645 | |
| 4646 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4647 | class TestDuplicatePipeline(ZuulTestCase): |
| 4648 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4649 | |
| 4650 | def test_duplicate_pipelines(self): |
| 4651 | "Test that a change matching multiple pipelines works" |
| 4652 | |
| 4653 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4654 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4655 | self.waitUntilSettled() |
| 4656 | |
| 4657 | self.assertHistory([ |
| 4658 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4659 | pipeline='dup1'), |
| 4660 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4661 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4662 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4663 | |
| 4664 | self.assertEqual(len(A.messages), 2) |
| 4665 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4666 | if 'dup1' in A.messages[0]: |
| 4667 | self.assertIn('dup1', A.messages[0]) |
| 4668 | self.assertNotIn('dup2', A.messages[0]) |
| 4669 | self.assertIn('project-test1', A.messages[0]) |
| 4670 | self.assertIn('dup2', A.messages[1]) |
| 4671 | self.assertNotIn('dup1', A.messages[1]) |
| 4672 | self.assertIn('project-test1', A.messages[1]) |
| 4673 | else: |
| 4674 | self.assertIn('dup1', A.messages[1]) |
| 4675 | self.assertNotIn('dup2', A.messages[1]) |
| 4676 | self.assertIn('project-test1', A.messages[1]) |
| 4677 | self.assertIn('dup2', A.messages[0]) |
| 4678 | self.assertNotIn('dup1', A.messages[0]) |
| 4679 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4680 | |
| 4681 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4682 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4683 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4684 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4685 | def test_job_from_templates_executed(self): |
| 4686 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4687 | |
| 4688 | A = self.fake_gerrit.addFakeChange( |
| 4689 | 'org/templated-project', 'master', 'A') |
| 4690 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4691 | self.waitUntilSettled() |
| 4692 | |
| 4693 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4694 | 'SUCCESS') |
| 4695 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4696 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4697 | |
| 4698 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4699 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4700 | |
| 4701 | A = self.fake_gerrit.addFakeChange( |
| 4702 | 'org/layered-project', 'master', 'A') |
| 4703 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4704 | self.waitUntilSettled() |
| 4705 | |
| 4706 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4707 | 'SUCCESS') |
| 4708 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4709 | 'SUCCESS') |
| 4710 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4711 | ).result, 'SUCCESS') |
| 4712 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4713 | ).result, 'SUCCESS') |
| 4714 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4715 | ).result, 'SUCCESS') |
| 4716 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4717 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4718 | |
| 4719 | |
| 4720 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4721 | tenant_config_file = 'config/success-url/main.yaml' |
| 4722 | |
| 4723 | def test_success_url(self): |
| 4724 | "Ensure bad build params are ignored" |
| 4725 | self.sched.reconfigure(self.config) |
| 4726 | self.init_repo('org/docs') |
| 4727 | |
| 4728 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4729 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4730 | self.waitUntilSettled() |
| 4731 | |
| 4732 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4733 | self.assertEqual(len(self.history), 2) |
| 4734 | |
| 4735 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4736 | for build in self.history: |
| 4737 | if build.name == 'docs-draft-test': |
| 4738 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4739 | elif build.name == 'docs-draft-test2': |
| 4740 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4741 | |
| 4742 | # Two msgs: 'Starting...' + results |
| 4743 | self.assertEqual(len(self.smtp_messages), 2) |
| 4744 | body = self.smtp_messages[1]['body'].splitlines() |
| 4745 | self.assertEqual('Build succeeded.', body[0]) |
| 4746 | |
| 4747 | self.assertIn( |
| 4748 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4749 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4750 | body[2]) |
| 4751 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4752 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4753 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4754 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4755 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4756 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4757 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4758 | |
| 4759 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4760 | class TestSchedulerMerges(ZuulTestCase): |
| 4761 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4762 | |
| 4763 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4764 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4765 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4766 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4767 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4768 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4769 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
| 4770 | A.addApproval('code-review', 2) |
| 4771 | B.addApproval('code-review', 2) |
| 4772 | C.addApproval('code-review', 2) |
| 4773 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4774 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4775 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4776 | self.waitUntilSettled() |
| 4777 | |
| 4778 | build = self.builds[-1] |
| 4779 | ref = self.getParameter(build, 'ZUUL_REF') |
| 4780 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4781 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4782 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4783 | repo = git.Repo(path) |
| 4784 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4785 | repo_messages.reverse() |
| 4786 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4787 | self.executor_server.hold_jobs_in_build = False |
| 4788 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4789 | self.waitUntilSettled() |
| 4790 | |
| 4791 | return repo_messages |
| 4792 | |
| 4793 | def _test_merge(self, mode): |
| 4794 | us_path = os.path.join( |
| 4795 | self.upstream_root, 'org/project-%s' % mode) |
| 4796 | expected_messages = [ |
| 4797 | 'initial commit', |
| 4798 | 'add content from fixture', |
| 4799 | # the intermediate commits order is nondeterministic |
| 4800 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4801 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4802 | ] |
| 4803 | result = self._test_project_merge_mode(mode) |
| 4804 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4805 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4806 | |
| 4807 | def test_project_merge_mode_merge(self): |
| 4808 | self._test_merge('merge') |
| 4809 | |
| 4810 | def test_project_merge_mode_merge_resolve(self): |
| 4811 | self._test_merge('merge-resolve') |
| 4812 | |
| 4813 | def test_project_merge_mode_cherrypick(self): |
| 4814 | expected_messages = [ |
| 4815 | 'initial commit', |
| 4816 | 'add content from fixture', |
| 4817 | 'A-1', |
| 4818 | 'B-1', |
| 4819 | 'C-1'] |
| 4820 | result = self._test_project_merge_mode('cherry-pick') |
| 4821 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4822 | |
| 4823 | def test_merge_branch(self): |
| 4824 | "Test that the right commits are on alternate branches" |
| 4825 | self.create_branch('org/project-merge-branches', 'mp') |
| 4826 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4827 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4828 | A = self.fake_gerrit.addFakeChange( |
| 4829 | 'org/project-merge-branches', 'mp', 'A') |
| 4830 | B = self.fake_gerrit.addFakeChange( |
| 4831 | 'org/project-merge-branches', 'mp', 'B') |
| 4832 | C = self.fake_gerrit.addFakeChange( |
| 4833 | 'org/project-merge-branches', 'mp', 'C') |
| 4834 | A.addApproval('code-review', 2) |
| 4835 | B.addApproval('code-review', 2) |
| 4836 | C.addApproval('code-review', 2) |
| 4837 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4838 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4839 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4840 | self.waitUntilSettled() |
| 4841 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4842 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4843 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4844 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4845 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4846 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4847 | self.waitUntilSettled() |
| 4848 | |
| 4849 | build = self.builds[-1] |
| 4850 | self.assertEqual(self.getParameter(build, 'ZUUL_BRANCH'), 'mp') |
| 4851 | ref = self.getParameter(build, 'ZUUL_REF') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4852 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4853 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4854 | repo = git.Repo(path) |
| 4855 | |
| 4856 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4857 | repo_messages.reverse() |
| 4858 | correct_messages = [ |
| 4859 | 'initial commit', |
| 4860 | 'add content from fixture', |
| 4861 | 'mp commit', |
| 4862 | 'A-1', 'B-1', 'C-1'] |
| 4863 | self.assertEqual(repo_messages, correct_messages) |
| 4864 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4865 | self.executor_server.hold_jobs_in_build = False |
| 4866 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4867 | self.waitUntilSettled() |
| 4868 | |
| 4869 | def test_merge_multi_branch(self): |
| 4870 | "Test that dependent changes on multiple branches are merged" |
| 4871 | self.create_branch('org/project-merge-branches', 'mp') |
| 4872 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4873 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4874 | A = self.fake_gerrit.addFakeChange( |
| 4875 | 'org/project-merge-branches', 'master', 'A') |
| 4876 | B = self.fake_gerrit.addFakeChange( |
| 4877 | 'org/project-merge-branches', 'mp', 'B') |
| 4878 | C = self.fake_gerrit.addFakeChange( |
| 4879 | 'org/project-merge-branches', 'master', 'C') |
| 4880 | A.addApproval('code-review', 2) |
| 4881 | B.addApproval('code-review', 2) |
| 4882 | C.addApproval('code-review', 2) |
| 4883 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 4884 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 4885 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 4886 | self.waitUntilSettled() |
| 4887 | |
| 4888 | job_A = None |
| 4889 | for job in self.builds: |
| 4890 | if 'project-merge' in job.name: |
| 4891 | job_A = job |
| 4892 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 4893 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 4894 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 4895 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
| 4896 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4897 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4898 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4899 | repo = git.Repo(path) |
| 4900 | repo_messages = [c.message.strip() |
| 4901 | for c in repo.iter_commits(ref_A)] |
| 4902 | repo_messages.reverse() |
| 4903 | correct_messages = [ |
| 4904 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4905 | self.assertEqual(repo_messages, correct_messages) |
| 4906 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4907 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4908 | self.waitUntilSettled() |
| 4909 | |
| 4910 | job_B = None |
| 4911 | for job in self.builds: |
| 4912 | if 'project-merge' in job.name: |
| 4913 | job_B = job |
| 4914 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
| 4915 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
| 4916 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
| 4917 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 4918 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4919 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4920 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4921 | repo = git.Repo(path) |
| 4922 | repo_messages = [c.message.strip() |
| 4923 | for c in repo.iter_commits(ref_B)] |
| 4924 | repo_messages.reverse() |
| 4925 | correct_messages = [ |
| 4926 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4927 | self.assertEqual(repo_messages, correct_messages) |
| 4928 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4929 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4930 | self.waitUntilSettled() |
| 4931 | |
| 4932 | job_C = None |
| 4933 | for job in self.builds: |
| 4934 | if 'project-merge' in job.name: |
| 4935 | job_C = job |
| 4936 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
| 4937 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
| 4938 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
| 4939 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4940 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4941 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4942 | repo = git.Repo(path) |
| 4943 | repo_messages = [c.message.strip() |
| 4944 | for c in repo.iter_commits(ref_C)] |
| 4945 | |
| 4946 | repo_messages.reverse() |
| 4947 | correct_messages = [ |
| 4948 | 'initial commit', 'add content from fixture', |
| 4949 | 'A-1', 'C-1'] |
| 4950 | # Ensure the right commits are in the history for this ref |
| 4951 | self.assertEqual(repo_messages, correct_messages) |
| 4952 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4953 | self.executor_server.hold_jobs_in_build = False |
| 4954 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4955 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 4956 | |
| 4957 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 4958 | class TestSemaphore(ZuulTestCase): |
| 4959 | tenant_config_file = 'config/semaphore/main.yaml' |
| 4960 | |
| 4961 | def test_semaphore_one(self): |
| 4962 | "Test semaphores with max=1 (mutex)" |
| 4963 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4964 | |
| 4965 | self.executor_server.hold_jobs_in_build = True |
| 4966 | |
| 4967 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4968 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4969 | self.assertFalse('test-semaphore' in |
| 4970 | tenant.semaphore_handler.semaphores) |
| 4971 | |
| 4972 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4973 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4974 | self.waitUntilSettled() |
| 4975 | |
| 4976 | self.assertEqual(len(self.builds), 3) |
| 4977 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4978 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 4979 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 4980 | |
| 4981 | self.executor_server.release('semaphore-one-test1') |
| 4982 | self.waitUntilSettled() |
| 4983 | |
| 4984 | self.assertEqual(len(self.builds), 3) |
| 4985 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4986 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4987 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 4988 | self.assertTrue('test-semaphore' in |
| 4989 | tenant.semaphore_handler.semaphores) |
| 4990 | |
| 4991 | self.executor_server.release('semaphore-one-test2') |
| 4992 | self.waitUntilSettled() |
| 4993 | |
| 4994 | self.assertEqual(len(self.builds), 3) |
| 4995 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 4996 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 4997 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 4998 | self.assertTrue('test-semaphore' in |
| 4999 | tenant.semaphore_handler.semaphores) |
| 5000 | |
| 5001 | self.executor_server.release('semaphore-one-test1') |
| 5002 | self.waitUntilSettled() |
| 5003 | |
| 5004 | self.assertEqual(len(self.builds), 3) |
| 5005 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5006 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5007 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5008 | self.assertTrue('test-semaphore' in |
| 5009 | tenant.semaphore_handler.semaphores) |
| 5010 | |
| 5011 | self.executor_server.release('semaphore-one-test2') |
| 5012 | self.waitUntilSettled() |
| 5013 | |
| 5014 | self.assertEqual(len(self.builds), 2) |
| 5015 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5016 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5017 | self.assertFalse('test-semaphore' in |
| 5018 | tenant.semaphore_handler.semaphores) |
| 5019 | |
| 5020 | self.executor_server.hold_jobs_in_build = False |
| 5021 | self.executor_server.release() |
| 5022 | |
| 5023 | self.waitUntilSettled() |
| 5024 | self.assertEqual(len(self.builds), 0) |
| 5025 | |
| 5026 | self.assertEqual(A.reported, 1) |
| 5027 | self.assertEqual(B.reported, 1) |
| 5028 | self.assertFalse('test-semaphore' in |
| 5029 | tenant.semaphore_handler.semaphores) |
| 5030 | |
| 5031 | def test_semaphore_two(self): |
| 5032 | "Test semaphores with max>1" |
| 5033 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5034 | |
| 5035 | self.executor_server.hold_jobs_in_build = True |
| 5036 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5037 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5038 | self.assertFalse('test-semaphore-two' in |
| 5039 | tenant.semaphore_handler.semaphores) |
| 5040 | |
| 5041 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5042 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5043 | self.waitUntilSettled() |
| 5044 | |
| 5045 | self.assertEqual(len(self.builds), 4) |
| 5046 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5047 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5048 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5049 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5050 | self.assertTrue('test-semaphore-two' in |
| 5051 | tenant.semaphore_handler.semaphores) |
| 5052 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5053 | 'test-semaphore-two', [])), 2) |
| 5054 | |
| 5055 | self.executor_server.release('semaphore-two-test1') |
| 5056 | self.waitUntilSettled() |
| 5057 | |
| 5058 | self.assertEqual(len(self.builds), 4) |
| 5059 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5060 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5061 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5062 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5063 | self.assertTrue('test-semaphore-two' in |
| 5064 | tenant.semaphore_handler.semaphores) |
| 5065 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5066 | 'test-semaphore-two', [])), 2) |
| 5067 | |
| 5068 | self.executor_server.release('semaphore-two-test2') |
| 5069 | self.waitUntilSettled() |
| 5070 | |
| 5071 | self.assertEqual(len(self.builds), 4) |
| 5072 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5073 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5074 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5075 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5076 | self.assertTrue('test-semaphore-two' in |
| 5077 | tenant.semaphore_handler.semaphores) |
| 5078 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5079 | 'test-semaphore-two', [])), 2) |
| 5080 | |
| 5081 | self.executor_server.release('semaphore-two-test1') |
| 5082 | self.waitUntilSettled() |
| 5083 | |
| 5084 | self.assertEqual(len(self.builds), 3) |
| 5085 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5086 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5087 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5088 | self.assertTrue('test-semaphore-two' in |
| 5089 | tenant.semaphore_handler.semaphores) |
| 5090 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5091 | 'test-semaphore-two', [])), 1) |
| 5092 | |
| 5093 | self.executor_server.release('semaphore-two-test2') |
| 5094 | self.waitUntilSettled() |
| 5095 | |
| 5096 | self.assertEqual(len(self.builds), 2) |
| 5097 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5098 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5099 | self.assertFalse('test-semaphore-two' in |
| 5100 | tenant.semaphore_handler.semaphores) |
| 5101 | |
| 5102 | self.executor_server.hold_jobs_in_build = False |
| 5103 | self.executor_server.release() |
| 5104 | |
| 5105 | self.waitUntilSettled() |
| 5106 | self.assertEqual(len(self.builds), 0) |
| 5107 | |
| 5108 | self.assertEqual(A.reported, 1) |
| 5109 | self.assertEqual(B.reported, 1) |
| 5110 | |
| 5111 | def test_semaphore_abandon(self): |
| 5112 | "Test abandon with job semaphores" |
| 5113 | self.executor_server.hold_jobs_in_build = True |
| 5114 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5115 | check_pipeline = tenant.layout.pipelines['check'] |
| 5116 | |
| 5117 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5118 | self.assertFalse('test-semaphore' in |
| 5119 | tenant.semaphore_handler.semaphores) |
| 5120 | |
| 5121 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5122 | self.waitUntilSettled() |
| 5123 | |
| 5124 | self.assertTrue('test-semaphore' in |
| 5125 | tenant.semaphore_handler.semaphores) |
| 5126 | |
| 5127 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5128 | self.waitUntilSettled() |
| 5129 | |
| 5130 | # The check pipeline should be empty |
| 5131 | items = check_pipeline.getAllItems() |
| 5132 | self.assertEqual(len(items), 0) |
| 5133 | |
| 5134 | # The semaphore should be released |
| 5135 | self.assertFalse('test-semaphore' in |
| 5136 | tenant.semaphore_handler.semaphores) |
| 5137 | |
| 5138 | self.executor_server.hold_jobs_in_build = False |
| 5139 | self.executor_server.release() |
| 5140 | self.waitUntilSettled() |
| 5141 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5142 | def test_semaphore_new_patchset(self): |
| 5143 | "Test new patchset with job semaphores" |
| 5144 | self.executor_server.hold_jobs_in_build = True |
| 5145 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5146 | check_pipeline = tenant.layout.pipelines['check'] |
| 5147 | |
| 5148 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5149 | self.assertFalse('test-semaphore' in |
| 5150 | tenant.semaphore_handler.semaphores) |
| 5151 | |
| 5152 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5153 | self.waitUntilSettled() |
| 5154 | |
| 5155 | self.assertTrue('test-semaphore' in |
| 5156 | tenant.semaphore_handler.semaphores) |
| 5157 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5158 | self.assertEqual(len(semaphore), 1) |
| 5159 | |
| 5160 | A.addPatchset() |
| 5161 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5162 | self.waitUntilSettled() |
| 5163 | |
| 5164 | self.assertTrue('test-semaphore' in |
| 5165 | tenant.semaphore_handler.semaphores) |
| 5166 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5167 | self.assertEqual(len(semaphore), 1) |
| 5168 | |
| 5169 | items = check_pipeline.getAllItems() |
| 5170 | self.assertEqual(items[0].change.number, '1') |
| 5171 | self.assertEqual(items[0].change.patchset, '2') |
| 5172 | self.assertTrue(items[0].live) |
| 5173 | |
| 5174 | self.executor_server.hold_jobs_in_build = False |
| 5175 | self.executor_server.release() |
| 5176 | self.waitUntilSettled() |
| 5177 | |
| 5178 | # The semaphore should be released |
| 5179 | self.assertFalse('test-semaphore' in |
| 5180 | tenant.semaphore_handler.semaphores) |
| 5181 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5182 | def test_semaphore_reconfigure(self): |
| 5183 | "Test reconfigure with job semaphores" |
| 5184 | self.executor_server.hold_jobs_in_build = True |
| 5185 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5187 | self.assertFalse('test-semaphore' in |
| 5188 | tenant.semaphore_handler.semaphores) |
| 5189 | |
| 5190 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5191 | self.waitUntilSettled() |
| 5192 | |
| 5193 | self.assertTrue('test-semaphore' in |
| 5194 | tenant.semaphore_handler.semaphores) |
| 5195 | |
| 5196 | # reconfigure without layout change |
| 5197 | self.sched.reconfigure(self.config) |
| 5198 | self.waitUntilSettled() |
| 5199 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5200 | |
| 5201 | # semaphore still must be held |
| 5202 | self.assertTrue('test-semaphore' in |
| 5203 | tenant.semaphore_handler.semaphores) |
| 5204 | |
| 5205 | self.commitConfigUpdate( |
| 5206 | 'common-config', |
| 5207 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5208 | self.sched.reconfigure(self.config) |
| 5209 | self.waitUntilSettled() |
| 5210 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5211 | |
| 5212 | self.executor_server.release('project-test1') |
| 5213 | self.waitUntilSettled() |
| 5214 | |
| 5215 | # There should be no builds anymore |
| 5216 | self.assertEqual(len(self.builds), 0) |
| 5217 | |
| 5218 | # The semaphore should be released |
| 5219 | self.assertFalse('test-semaphore' in |
| 5220 | tenant.semaphore_handler.semaphores) |
| 5221 | |
| 5222 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5223 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5224 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5225 | |
| 5226 | def test_semaphore_tenant_isolation(self): |
| 5227 | "Test semaphores in multiple tenants" |
| 5228 | |
| 5229 | self.waitUntilSettled() |
| 5230 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5231 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5232 | |
| 5233 | self.executor_server.hold_jobs_in_build = True |
| 5234 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5235 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5236 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5237 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5238 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5239 | self.assertFalse('test-semaphore' in |
| 5240 | tenant_one.semaphore_handler.semaphores) |
| 5241 | self.assertFalse('test-semaphore' in |
| 5242 | tenant_two.semaphore_handler.semaphores) |
| 5243 | |
| 5244 | # add patches to project1 of tenant-one |
| 5245 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5246 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5247 | self.waitUntilSettled() |
| 5248 | |
| 5249 | # one build of project1-test1 must run |
| 5250 | # semaphore of tenant-one must be acquired once |
| 5251 | # semaphore of tenant-two must not be acquired |
| 5252 | self.assertEqual(len(self.builds), 1) |
| 5253 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5254 | self.assertTrue('test-semaphore' in |
| 5255 | tenant_one.semaphore_handler.semaphores) |
| 5256 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5257 | 'test-semaphore', [])), 1) |
| 5258 | self.assertFalse('test-semaphore' in |
| 5259 | tenant_two.semaphore_handler.semaphores) |
| 5260 | |
| 5261 | # add patches to project2 of tenant-two |
| 5262 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5263 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5264 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5265 | self.waitUntilSettled() |
| 5266 | |
| 5267 | # one build of project1-test1 must run |
| 5268 | # two builds of project2-test1 must run |
| 5269 | # semaphore of tenant-one must be acquired once |
| 5270 | # semaphore of tenant-two must be acquired twice |
| 5271 | self.assertEqual(len(self.builds), 3) |
| 5272 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5273 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5274 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5275 | self.assertTrue('test-semaphore' in |
| 5276 | tenant_one.semaphore_handler.semaphores) |
| 5277 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5278 | 'test-semaphore', [])), 1) |
| 5279 | self.assertTrue('test-semaphore' in |
| 5280 | tenant_two.semaphore_handler.semaphores) |
| 5281 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5282 | 'test-semaphore', [])), 2) |
| 5283 | |
| 5284 | self.executor_server.release('project1-test1') |
| 5285 | self.waitUntilSettled() |
| 5286 | |
| 5287 | # one build of project1-test1 must run |
| 5288 | # two builds of project2-test1 must run |
| 5289 | # semaphore of tenant-one must be acquired once |
| 5290 | # semaphore of tenant-two must be acquired twice |
| 5291 | self.assertEqual(len(self.builds), 3) |
| 5292 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5293 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5294 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5295 | self.assertTrue('test-semaphore' in |
| 5296 | tenant_one.semaphore_handler.semaphores) |
| 5297 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5298 | 'test-semaphore', [])), 1) |
| 5299 | self.assertTrue('test-semaphore' in |
| 5300 | tenant_two.semaphore_handler.semaphores) |
| 5301 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5302 | 'test-semaphore', [])), 2) |
| 5303 | |
| 5304 | self.executor_server.release('project2-test1') |
| 5305 | self.waitUntilSettled() |
| 5306 | |
| 5307 | # one build of project1-test1 must run |
| 5308 | # one build of project2-test1 must run |
| 5309 | # semaphore of tenant-one must be acquired once |
| 5310 | # semaphore of tenant-two must be acquired once |
| 5311 | self.assertEqual(len(self.builds), 2) |
| 5312 | self.assertTrue('test-semaphore' in |
| 5313 | tenant_one.semaphore_handler.semaphores) |
| 5314 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5315 | 'test-semaphore', [])), 1) |
| 5316 | self.assertTrue('test-semaphore' in |
| 5317 | tenant_two.semaphore_handler.semaphores) |
| 5318 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5319 | 'test-semaphore', [])), 1) |
| 5320 | |
| 5321 | self.executor_server.hold_jobs_in_build = False |
| 5322 | self.executor_server.release() |
| 5323 | |
| 5324 | self.waitUntilSettled() |
| 5325 | |
| 5326 | # no build must run |
| 5327 | # semaphore of tenant-one must not be acquired |
| 5328 | # semaphore of tenant-two must not be acquired |
| 5329 | self.assertEqual(len(self.builds), 0) |
| 5330 | self.assertFalse('test-semaphore' in |
| 5331 | tenant_one.semaphore_handler.semaphores) |
| 5332 | self.assertFalse('test-semaphore' in |
| 5333 | tenant_two.semaphore_handler.semaphores) |
| 5334 | |
| 5335 | self.assertEqual(A.reported, 1) |
| 5336 | self.assertEqual(B.reported, 1) |
| 5337 | |
| 5338 | |
| 5339 | class TestSemaphoreInRepo(ZuulTestCase): |
| 5340 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5341 | |
| 5342 | def test_semaphore_in_repo(self): |
| 5343 | "Test semaphores in repo config" |
| 5344 | |
| 5345 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5346 | # max value should not be evaluated dynamically but must be updated |
| 5347 | # after the change lands. |
| 5348 | |
| 5349 | self.waitUntilSettled() |
| 5350 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5351 | |
| 5352 | in_repo_conf = textwrap.dedent( |
| 5353 | """ |
| 5354 | - job: |
| 5355 | name: project-test2 |
| 5356 | semaphore: test-semaphore |
| 5357 | |
| 5358 | - project: |
| 5359 | name: org/project |
| 5360 | tenant-one-gate: |
| 5361 | jobs: |
| 5362 | - project-test2 |
| 5363 | |
| 5364 | # the max value in dynamic layout must be ignored |
| 5365 | - semaphore: |
| 5366 | name: test-semaphore |
| 5367 | max: 2 |
| 5368 | """) |
| 5369 | |
| 5370 | in_repo_playbook = textwrap.dedent( |
| 5371 | """ |
| 5372 | - hosts: all |
| 5373 | tasks: [] |
| 5374 | """) |
| 5375 | |
| 5376 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5377 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5378 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5379 | files=file_dict) |
| 5380 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5381 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5382 | B.setDependsOn(A, 1) |
| 5383 | C.setDependsOn(A, 1) |
| 5384 | |
| 5385 | self.executor_server.hold_jobs_in_build = True |
| 5386 | |
| 5387 | A.addApproval('code-review', 2) |
| 5388 | B.addApproval('code-review', 2) |
| 5389 | C.addApproval('code-review', 2) |
| 5390 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 5391 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 5392 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 5393 | self.waitUntilSettled() |
| 5394 | |
| 5395 | # check that the layout in a queue item still has max value of 1 |
| 5396 | # for test-semaphore |
| 5397 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5398 | queue = None |
| 5399 | for queue_candidate in pipeline.queues: |
| 5400 | if queue_candidate.name == 'org/project': |
| 5401 | queue = queue_candidate |
| 5402 | break |
| 5403 | queue_item = queue.queue[0] |
| 5404 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5405 | dynamic_test_semaphore = \ |
| 5406 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5407 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5408 | |
| 5409 | # one build must be in queue, one semaphores acquired |
| 5410 | self.assertEqual(len(self.builds), 1) |
| 5411 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5412 | self.assertTrue('test-semaphore' in |
| 5413 | tenant.semaphore_handler.semaphores) |
| 5414 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5415 | 'test-semaphore', [])), 1) |
| 5416 | |
| 5417 | self.executor_server.release('project-test2') |
| 5418 | self.waitUntilSettled() |
| 5419 | |
| 5420 | # change A must be merged |
| 5421 | self.assertEqual(A.data['status'], 'MERGED') |
| 5422 | self.assertEqual(A.reported, 2) |
| 5423 | |
| 5424 | # send change-merged event as the gerrit mock doesn't send it |
| 5425 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5426 | self.waitUntilSettled() |
| 5427 | |
| 5428 | # now that change A was merged, the new semaphore max must be effective |
| 5429 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5430 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5431 | |
| 5432 | # two builds must be in queue, two semaphores acquired |
| 5433 | self.assertEqual(len(self.builds), 2) |
| 5434 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5435 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5436 | self.assertTrue('test-semaphore' in |
| 5437 | tenant.semaphore_handler.semaphores) |
| 5438 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5439 | 'test-semaphore', [])), 2) |
| 5440 | |
| 5441 | self.executor_server.release('project-test2') |
| 5442 | self.waitUntilSettled() |
| 5443 | |
| 5444 | self.assertEqual(len(self.builds), 0) |
| 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 | |
| 5451 | self.waitUntilSettled() |
| 5452 | self.assertEqual(len(self.builds), 0) |
| 5453 | |
| 5454 | self.assertEqual(A.reported, 2) |
| 5455 | self.assertEqual(B.reported, 2) |
| 5456 | self.assertEqual(C.reported, 2) |