James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 17 | import gc |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 18 | import json |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 19 | import textwrap |
| 20 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 21 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 22 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 23 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 24 | import time |
Clint Byrum | 03454a5 | 2017-05-26 17:14:02 -0700 | [diff] [blame] | 25 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 26 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 27 | import git |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
Monty Taylor | b934c1a | 2017-06-16 19:31:47 -0500 | [diff] [blame] | 29 | import urllib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 30 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 31 | import zuul.change_matcher |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 32 | from zuul.driver.gerrit import gerritreporter |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 33 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 34 | import zuul.rpcclient |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 35 | import zuul.model |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 36 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | from tests.base import ( |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 38 | SSLZuulTestCase, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 39 | ZuulTestCase, |
| 40 | repack_repo, |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 41 | simple_layout, |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 42 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 43 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 45 | class TestSchedulerSSL(SSLZuulTestCase): |
| 46 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 47 | |
| 48 | def test_jobs_executed(self): |
| 49 | "Test that jobs are executed and a change is merged" |
| 50 | |
| 51 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 52 | A.addApproval('Code-Review', 2) |
| 53 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 54 | self.waitUntilSettled() |
| 55 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 56 | 'SUCCESS') |
| 57 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 58 | 'SUCCESS') |
| 59 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 60 | 'SUCCESS') |
| 61 | self.assertEqual(A.data['status'], 'MERGED') |
| 62 | self.assertEqual(A.reported, 2) |
| 63 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 64 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 65 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 66 | 'label1') |
Paul Belanger | 0a21f0a | 2017-06-13 13:14:42 -0400 | [diff] [blame] | 67 | |
| 68 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 69 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 70 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 71 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 72 | def test_jobs_executed(self): |
| 73 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 74 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 75 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 76 | A.addApproval('Code-Review', 2) |
| 77 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 78 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 79 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 80 | 'SUCCESS') |
| 81 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 82 | 'SUCCESS') |
| 83 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 84 | 'SUCCESS') |
| 85 | self.assertEqual(A.data['status'], 'MERGED') |
| 86 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 87 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 88 | 'label1') |
James E. Blair | fcbf95d | 2017-07-25 16:38:09 -0700 | [diff] [blame] | 89 | self.assertEqual(self.getJobFromHistory('project-test2').node, |
| 90 | 'label1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 91 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 92 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 93 | # Per-driver |
| 94 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 95 | # Per-driver per-connection |
| 96 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 97 | value='1|c') |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 98 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 99 | value='1|g') |
| 100 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 101 | kind='ms') |
| 102 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 103 | value='1|c') |
| 104 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 105 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 106 | value='1|c') |
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.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 109 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 110 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 111 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 112 | for build in self.history: |
| 113 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 114 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 115 | def test_initial_pipeline_gauges(self): |
| 116 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 117 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 118 | value='0|g') |
| 119 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 120 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 121 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 122 | def test_job_branch(self): |
| 123 | "Test the correct variant of a job runs on a branch" |
| 124 | self.create_branch('org/project', 'stable') |
| 125 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 126 | A.addApproval('Code-Review', 2) |
| 127 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 128 | self.waitUntilSettled() |
| 129 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 130 | 'SUCCESS') |
| 131 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 132 | 'SUCCESS') |
| 133 | self.assertEqual(A.data['status'], 'MERGED') |
| 134 | self.assertEqual(A.reported, 2, |
| 135 | "A should report start and success") |
| 136 | self.assertIn('gate', A.messages[1], |
| 137 | "A should transit gate") |
| 138 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 139 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 140 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 141 | def test_parallel_changes(self): |
| 142 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 143 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 144 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 145 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 146 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 147 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 148 | A.addApproval('Code-Review', 2) |
| 149 | B.addApproval('Code-Review', 2) |
| 150 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 151 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 152 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 153 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 154 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | |
| 156 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 157 | self.assertEqual(len(self.builds), 1) |
| 158 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 159 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 161 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 162 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(len(self.builds), 3) |
| 164 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 168 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 169 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 171 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 172 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 173 | self.assertEqual(len(self.builds), 5) |
| 174 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 175 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 177 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 180 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 181 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 182 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 183 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 184 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 185 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 186 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 187 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 188 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 189 | self.assertEqual(len(self.builds), 6) |
| 190 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 191 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 192 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 193 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 194 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 197 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 198 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 199 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 200 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 201 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 202 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 203 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 204 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 205 | self.executor_server.hold_jobs_in_build = False |
| 206 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 207 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 208 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 209 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 210 | self.assertEqual(len(self.history), 9) |
| 211 | self.assertEqual(A.data['status'], 'MERGED') |
| 212 | self.assertEqual(B.data['status'], 'MERGED') |
| 213 | self.assertEqual(C.data['status'], 'MERGED') |
| 214 | self.assertEqual(A.reported, 2) |
| 215 | self.assertEqual(B.reported, 2) |
| 216 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 217 | |
| 218 | def test_failed_changes(self): |
| 219 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 220 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 221 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 222 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 223 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 224 | A.addApproval('Code-Review', 2) |
| 225 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 227 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 228 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 229 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 230 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 231 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 232 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 233 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 234 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 235 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 236 | # A/project-merge is complete |
| 237 | self.assertBuilds([ |
| 238 | dict(name='project-test1', changes='1,1'), |
| 239 | dict(name='project-test2', changes='1,1'), |
| 240 | dict(name='project-merge', changes='1,1 2,1'), |
| 241 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 242 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 243 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 244 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 245 | # A/project-merge is complete |
| 246 | # B/project-merge is complete |
| 247 | self.assertBuilds([ |
| 248 | dict(name='project-test1', changes='1,1'), |
| 249 | dict(name='project-test2', changes='1,1'), |
| 250 | dict(name='project-test1', changes='1,1 2,1'), |
| 251 | dict(name='project-test2', changes='1,1 2,1'), |
| 252 | ]) |
| 253 | |
| 254 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 255 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 256 | self.builds[0].release() |
| 257 | self.waitUntilSettled() |
| 258 | |
| 259 | self.orderedRelease() |
| 260 | self.assertHistory([ |
| 261 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 262 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 263 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 264 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 265 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 266 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 267 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 268 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 269 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 270 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 271 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 272 | self.assertEqual(A.data['status'], 'NEW') |
| 273 | self.assertEqual(B.data['status'], 'MERGED') |
| 274 | self.assertEqual(A.reported, 2) |
| 275 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 276 | |
| 277 | def test_independent_queues(self): |
| 278 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 279 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 280 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 281 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 282 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 283 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 284 | A.addApproval('Code-Review', 2) |
| 285 | B.addApproval('Code-Review', 2) |
| 286 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 287 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 288 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 289 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 290 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 291 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 292 | self.waitUntilSettled() |
| 293 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 294 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 295 | self.waitUntilSettled() |
| 296 | |
| 297 | # 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] | 298 | self.assertBuilds([ |
| 299 | dict(name='project-merge', changes='1,1'), |
| 300 | dict(name='project-merge', changes='2,1'), |
| 301 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 302 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 303 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 304 | self.builds[0].release() |
| 305 | self.waitUntilSettled() |
| 306 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 307 | self.waitUntilSettled() |
| 308 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 309 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 310 | self.waitUntilSettled() |
| 311 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 312 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 313 | self.assertBuilds([ |
| 314 | dict(name='project-test1', changes='1,1'), |
| 315 | dict(name='project-test2', changes='1,1'), |
| 316 | dict(name='project-test1', changes='2,1'), |
| 317 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 318 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 319 | dict(name='project-test1', changes='2,1 3,1'), |
| 320 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 321 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 322 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 323 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 324 | self.orderedRelease() |
| 325 | self.assertHistory([ |
| 326 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 327 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 328 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 329 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 330 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 331 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 332 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 333 | dict( |
| 334 | name='project1-project2-integration', |
| 335 | result='SUCCESS', |
| 336 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 337 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 338 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 339 | dict(name='project1-project2-integration', |
| 340 | result='SUCCESS', |
| 341 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 342 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 343 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 344 | self.assertEqual(A.data['status'], 'MERGED') |
| 345 | self.assertEqual(B.data['status'], 'MERGED') |
| 346 | self.assertEqual(C.data['status'], 'MERGED') |
| 347 | self.assertEqual(A.reported, 2) |
| 348 | self.assertEqual(B.reported, 2) |
| 349 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 350 | |
| 351 | def test_failed_change_at_head(self): |
| 352 | "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] | 353 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 354 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 355 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 356 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 357 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 358 | A.addApproval('Code-Review', 2) |
| 359 | B.addApproval('Code-Review', 2) |
| 360 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 361 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 362 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 363 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 364 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 365 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 366 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 367 | |
| 368 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 369 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 370 | self.assertBuilds([ |
| 371 | dict(name='project-merge', changes='1,1'), |
| 372 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 373 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 378 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 379 | self.waitUntilSettled() |
| 380 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 381 | self.assertBuilds([ |
| 382 | dict(name='project-test1', changes='1,1'), |
| 383 | dict(name='project-test2', changes='1,1'), |
| 384 | dict(name='project-test1', changes='1,1 2,1'), |
| 385 | dict(name='project-test2', changes='1,1 2,1'), |
| 386 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 387 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 388 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 389 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 390 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 391 | self.waitUntilSettled() |
| 392 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 393 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 394 | self.assertBuilds([ |
| 395 | dict(name='project-test2', changes='1,1'), |
| 396 | dict(name='project-merge', changes='2,1'), |
| 397 | ]) |
| 398 | # Unordered history comparison because the aborts can finish |
| 399 | # in any order. |
| 400 | self.assertHistory([ |
| 401 | dict(name='project-merge', result='SUCCESS', |
| 402 | changes='1,1'), |
| 403 | dict(name='project-merge', result='SUCCESS', |
| 404 | changes='1,1 2,1'), |
| 405 | dict(name='project-merge', result='SUCCESS', |
| 406 | changes='1,1 2,1 3,1'), |
| 407 | dict(name='project-test1', result='FAILURE', |
| 408 | changes='1,1'), |
| 409 | dict(name='project-test1', result='ABORTED', |
| 410 | changes='1,1 2,1'), |
| 411 | dict(name='project-test2', result='ABORTED', |
| 412 | changes='1,1 2,1'), |
| 413 | dict(name='project-test1', result='ABORTED', |
| 414 | changes='1,1 2,1 3,1'), |
| 415 | dict(name='project-test2', result='ABORTED', |
| 416 | changes='1,1 2,1 3,1'), |
| 417 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 418 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 419 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 420 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 421 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 422 | self.waitUntilSettled() |
| 423 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 424 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 425 | self.assertBuilds([]) |
| 426 | self.assertHistory([ |
| 427 | dict(name='project-merge', result='SUCCESS', |
| 428 | changes='1,1'), |
| 429 | dict(name='project-merge', result='SUCCESS', |
| 430 | changes='1,1 2,1'), |
| 431 | dict(name='project-merge', result='SUCCESS', |
| 432 | changes='1,1 2,1 3,1'), |
| 433 | dict(name='project-test1', result='FAILURE', |
| 434 | changes='1,1'), |
| 435 | dict(name='project-test1', result='ABORTED', |
| 436 | changes='1,1 2,1'), |
| 437 | dict(name='project-test2', result='ABORTED', |
| 438 | changes='1,1 2,1'), |
| 439 | dict(name='project-test1', result='ABORTED', |
| 440 | changes='1,1 2,1 3,1'), |
| 441 | dict(name='project-test2', result='ABORTED', |
| 442 | changes='1,1 2,1 3,1'), |
| 443 | dict(name='project-merge', result='SUCCESS', |
| 444 | changes='2,1'), |
| 445 | dict(name='project-merge', result='SUCCESS', |
| 446 | changes='2,1 3,1'), |
| 447 | dict(name='project-test2', result='SUCCESS', |
| 448 | changes='1,1'), |
| 449 | dict(name='project-test1', result='SUCCESS', |
| 450 | changes='2,1'), |
| 451 | dict(name='project-test2', result='SUCCESS', |
| 452 | changes='2,1'), |
| 453 | dict(name='project-test1', result='SUCCESS', |
| 454 | changes='2,1 3,1'), |
| 455 | dict(name='project-test2', result='SUCCESS', |
| 456 | changes='2,1 3,1'), |
| 457 | ], ordered=False) |
| 458 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 459 | self.assertEqual(A.data['status'], 'NEW') |
| 460 | self.assertEqual(B.data['status'], 'MERGED') |
| 461 | self.assertEqual(C.data['status'], 'MERGED') |
| 462 | self.assertEqual(A.reported, 2) |
| 463 | self.assertEqual(B.reported, 2) |
| 464 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 465 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 466 | def test_failed_change_in_middle(self): |
| 467 | "Test a failed change in the middle of the queue" |
| 468 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 469 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 470 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 471 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 472 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 473 | A.addApproval('Code-Review', 2) |
| 474 | B.addApproval('Code-Review', 2) |
| 475 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 476 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 477 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 478 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 479 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 480 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 481 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 482 | |
| 483 | self.waitUntilSettled() |
| 484 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 489 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 490 | self.waitUntilSettled() |
| 491 | |
| 492 | self.assertEqual(len(self.builds), 6) |
| 493 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 494 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 495 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 496 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 497 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 498 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 499 | |
| 500 | self.release(self.builds[2]) |
| 501 | self.waitUntilSettled() |
| 502 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 503 | # project-test1 and project-test2 for A |
| 504 | # project-test2 for B |
| 505 | # project-merge for C (without B) |
| 506 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 507 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 508 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 509 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 510 | self.waitUntilSettled() |
| 511 | |
| 512 | # project-test1 and project-test2 for A |
| 513 | # project-test2 for B |
| 514 | # project-test1 and project-test2 for C |
| 515 | self.assertEqual(len(self.builds), 5) |
| 516 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 517 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 518 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 519 | builds = items[0].current_build_set.getBuilds() |
| 520 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 521 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 522 | builds = items[1].current_build_set.getBuilds() |
| 523 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 524 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 525 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 526 | builds = items[2].current_build_set.getBuilds() |
| 527 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 528 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 529 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 530 | self.executor_server.hold_jobs_in_build = False |
| 531 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 532 | self.waitUntilSettled() |
| 533 | |
| 534 | self.assertEqual(len(self.builds), 0) |
| 535 | self.assertEqual(len(self.history), 12) |
| 536 | self.assertEqual(A.data['status'], 'MERGED') |
| 537 | self.assertEqual(B.data['status'], 'NEW') |
| 538 | self.assertEqual(C.data['status'], 'MERGED') |
| 539 | self.assertEqual(A.reported, 2) |
| 540 | self.assertEqual(B.reported, 2) |
| 541 | self.assertEqual(C.reported, 2) |
| 542 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | def test_failed_change_at_head_with_queue(self): |
| 544 | "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] | 545 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 546 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 547 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 548 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 549 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 550 | A.addApproval('Code-Review', 2) |
| 551 | B.addApproval('Code-Review', 2) |
| 552 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 553 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 554 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 555 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 556 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 557 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 558 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 559 | |
| 560 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 561 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 562 | self.assertEqual(len(self.builds), 0) |
| 563 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 564 | self.assertEqual(queue[0].name, b'executor:execute') |
| 565 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 566 | self.assertEqual(job_args['job'], 'project-merge') |
| 567 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 568 | |
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 | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 573 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 575 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 576 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 577 | self.assertEqual(len(self.builds), 0) |
| 578 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 579 | |
| 580 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 581 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 582 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 583 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 584 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 585 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 586 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 587 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 588 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 589 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 590 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 591 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 592 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 593 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 594 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 595 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 596 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 597 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 598 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 599 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 600 | self.waitUntilSettled() |
| 601 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 602 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 603 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 604 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 605 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 606 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 607 | self.gearman_server.hold_jobs_in_queue = False |
| 608 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 609 | self.waitUntilSettled() |
| 610 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 611 | self.assertEqual(len(self.builds), 0) |
| 612 | self.assertEqual(len(self.history), 11) |
| 613 | self.assertEqual(A.data['status'], 'NEW') |
| 614 | self.assertEqual(B.data['status'], 'MERGED') |
| 615 | self.assertEqual(C.data['status'], 'MERGED') |
| 616 | self.assertEqual(A.reported, 2) |
| 617 | self.assertEqual(B.reported, 2) |
| 618 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 619 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 620 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 621 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 622 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 623 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 624 | A.addApproval('Code-Review', 2) |
| 625 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 626 | self.waitUntilSettled() |
| 627 | time.sleep(2) |
| 628 | |
| 629 | data = json.loads(self.sched.formatStatusJSON()) |
| 630 | found_job = None |
| 631 | for pipeline in data['pipelines']: |
| 632 | if pipeline['name'] != 'gate': |
| 633 | continue |
| 634 | for queue in pipeline['change_queues']: |
| 635 | for head in queue['heads']: |
| 636 | for item in head: |
| 637 | for job in item['jobs']: |
| 638 | if job['name'] == 'project-merge': |
| 639 | found_job = job |
| 640 | break |
| 641 | |
| 642 | self.assertIsNotNone(found_job) |
| 643 | if iteration == 1: |
| 644 | self.assertIsNotNone(found_job['estimated_time']) |
| 645 | self.assertIsNone(found_job['remaining_time']) |
| 646 | else: |
| 647 | self.assertIsNotNone(found_job['estimated_time']) |
| 648 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 649 | self.assertIsNotNone(found_job['remaining_time']) |
| 650 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 651 | self.executor_server.hold_jobs_in_build = False |
| 652 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 653 | self.waitUntilSettled() |
| 654 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 655 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 656 | def test_time_database(self): |
| 657 | "Test the time database" |
| 658 | |
| 659 | self._test_time_database(1) |
| 660 | self._test_time_database(2) |
| 661 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 662 | def test_two_failed_changes_at_head(self): |
| 663 | "Test that changes are reparented correctly if 2 fail at head" |
| 664 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 665 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 666 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 667 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 668 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 669 | A.addApproval('Code-Review', 2) |
| 670 | B.addApproval('Code-Review', 2) |
| 671 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 672 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 673 | self.executor_server.failJob('project-test1', A) |
| 674 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 675 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 676 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 677 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 678 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | self.waitUntilSettled() |
| 680 | |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 685 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 686 | self.waitUntilSettled() |
| 687 | |
| 688 | self.assertEqual(len(self.builds), 6) |
| 689 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 690 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 691 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 692 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 693 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 694 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 695 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 696 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 697 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 698 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 699 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 700 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 701 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 702 | |
| 703 | # Fail change B first |
| 704 | self.release(self.builds[2]) |
| 705 | self.waitUntilSettled() |
| 706 | |
| 707 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 708 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 709 | self.waitUntilSettled() |
| 710 | |
| 711 | self.assertEqual(len(self.builds), 5) |
| 712 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 713 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 714 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 715 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 716 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 717 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 718 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 719 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 720 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 721 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 722 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 723 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 724 | |
| 725 | # Finish running all passing jobs for change A |
| 726 | self.release(self.builds[1]) |
| 727 | self.waitUntilSettled() |
| 728 | # Fail and report change A |
| 729 | self.release(self.builds[0]) |
| 730 | self.waitUntilSettled() |
| 731 | |
| 732 | # restart of B,C after A failure |
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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 735 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 736 | self.waitUntilSettled() |
| 737 | |
| 738 | self.assertEqual(len(self.builds), 4) |
| 739 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 740 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 741 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 742 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 743 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 744 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 745 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 746 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 747 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 748 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 749 | # After A failed and B and C restarted, B should be back in |
| 750 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 751 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 752 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 753 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 754 | self.executor_server.hold_jobs_in_build = False |
| 755 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 756 | self.waitUntilSettled() |
| 757 | |
| 758 | self.assertEqual(len(self.builds), 0) |
| 759 | self.assertEqual(len(self.history), 21) |
| 760 | self.assertEqual(A.data['status'], 'NEW') |
| 761 | self.assertEqual(B.data['status'], 'NEW') |
| 762 | self.assertEqual(C.data['status'], 'MERGED') |
| 763 | self.assertEqual(A.reported, 2) |
| 764 | self.assertEqual(B.reported, 2) |
| 765 | self.assertEqual(C.reported, 2) |
| 766 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 767 | def test_patch_order(self): |
| 768 | "Test that dependent patches are tested in the right order" |
| 769 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 770 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 771 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 772 | A.addApproval('Code-Review', 2) |
| 773 | B.addApproval('Code-Review', 2) |
| 774 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 775 | |
| 776 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 777 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 778 | M2.setMerged() |
| 779 | M1.setMerged() |
| 780 | |
| 781 | # C -> B -> A -> M1 -> M2 |
| 782 | # M2 is here to make sure it is never queried. If it is, it |
| 783 | # means zuul is walking down the entire history of merged |
| 784 | # changes. |
| 785 | |
| 786 | C.setDependsOn(B, 1) |
| 787 | B.setDependsOn(A, 1) |
| 788 | A.setDependsOn(M1, 1) |
| 789 | M1.setDependsOn(M2, 1) |
| 790 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 791 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 792 | |
| 793 | self.waitUntilSettled() |
| 794 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 795 | self.assertEqual(A.data['status'], 'NEW') |
| 796 | self.assertEqual(B.data['status'], 'NEW') |
| 797 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 798 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 799 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 800 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 801 | |
| 802 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 803 | self.assertEqual(M2.queried, 0) |
| 804 | self.assertEqual(A.data['status'], 'MERGED') |
| 805 | self.assertEqual(B.data['status'], 'MERGED') |
| 806 | self.assertEqual(C.data['status'], 'MERGED') |
| 807 | self.assertEqual(A.reported, 2) |
| 808 | self.assertEqual(B.reported, 2) |
| 809 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 810 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 811 | def test_needed_changes_enqueue(self): |
| 812 | "Test that a needed change is enqueued ahead" |
| 813 | # A Given a git tree like this, if we enqueue |
| 814 | # / \ change C, we should walk up and down the tree |
| 815 | # B G and enqueue changes in the order ABCDEFG. |
| 816 | # /|\ This is also the order that you would get if |
| 817 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 818 | # / the ordering is stable across re-enqueue events. |
| 819 | # D |
| 820 | |
| 821 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 822 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 823 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 824 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 825 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 826 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 827 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 828 | B.setDependsOn(A, 1) |
| 829 | C.setDependsOn(B, 1) |
| 830 | D.setDependsOn(C, 1) |
| 831 | E.setDependsOn(B, 1) |
| 832 | F.setDependsOn(B, 1) |
| 833 | G.setDependsOn(A, 1) |
| 834 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 835 | A.addApproval('Code-Review', 2) |
| 836 | B.addApproval('Code-Review', 2) |
| 837 | C.addApproval('Code-Review', 2) |
| 838 | D.addApproval('Code-Review', 2) |
| 839 | E.addApproval('Code-Review', 2) |
| 840 | F.addApproval('Code-Review', 2) |
| 841 | G.addApproval('Code-Review', 2) |
| 842 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 843 | |
| 844 | self.waitUntilSettled() |
| 845 | |
| 846 | self.assertEqual(A.data['status'], 'NEW') |
| 847 | self.assertEqual(B.data['status'], 'NEW') |
| 848 | self.assertEqual(C.data['status'], 'NEW') |
| 849 | self.assertEqual(D.data['status'], 'NEW') |
| 850 | self.assertEqual(E.data['status'], 'NEW') |
| 851 | self.assertEqual(F.data['status'], 'NEW') |
| 852 | self.assertEqual(G.data['status'], 'NEW') |
| 853 | |
| 854 | # We're about to add approvals to changes without adding the |
| 855 | # triggering events to Zuul, so that we can be sure that it is |
| 856 | # enqueing the changes based on dependencies, not because of |
| 857 | # triggering events. Since it will have the changes cached |
| 858 | # already (without approvals), we need to clear the cache |
| 859 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 860 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 861 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 863 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 864 | A.addApproval('Approved', 1) |
| 865 | B.addApproval('Approved', 1) |
| 866 | D.addApproval('Approved', 1) |
| 867 | E.addApproval('Approved', 1) |
| 868 | F.addApproval('Approved', 1) |
| 869 | G.addApproval('Approved', 1) |
| 870 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 871 | |
| 872 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 873 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 874 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 875 | self.executor_server.hold_jobs_in_build = False |
| 876 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 877 | self.waitUntilSettled() |
| 878 | |
| 879 | self.assertEqual(A.data['status'], 'MERGED') |
| 880 | self.assertEqual(B.data['status'], 'MERGED') |
| 881 | self.assertEqual(C.data['status'], 'MERGED') |
| 882 | self.assertEqual(D.data['status'], 'MERGED') |
| 883 | self.assertEqual(E.data['status'], 'MERGED') |
| 884 | self.assertEqual(F.data['status'], 'MERGED') |
| 885 | self.assertEqual(G.data['status'], 'MERGED') |
| 886 | self.assertEqual(A.reported, 2) |
| 887 | self.assertEqual(B.reported, 2) |
| 888 | self.assertEqual(C.reported, 2) |
| 889 | self.assertEqual(D.reported, 2) |
| 890 | self.assertEqual(E.reported, 2) |
| 891 | self.assertEqual(F.reported, 2) |
| 892 | self.assertEqual(G.reported, 2) |
| 893 | self.assertEqual(self.history[6].changes, |
| 894 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 895 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 896 | def test_source_cache(self): |
| 897 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 898 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 899 | |
| 900 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 901 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 902 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 903 | A.addApproval('Code-Review', 2) |
| 904 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 905 | |
| 906 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 907 | M1.setMerged() |
| 908 | |
| 909 | B.setDependsOn(A, 1) |
| 910 | A.setDependsOn(M1, 1) |
| 911 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 912 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 913 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 914 | |
| 915 | self.waitUntilSettled() |
| 916 | |
| 917 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 918 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 919 | build.release() |
| 920 | self.waitUntilSettled() |
| 921 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 922 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 923 | build.release() |
| 924 | self.waitUntilSettled() |
| 925 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 926 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 927 | self.waitUntilSettled() |
| 928 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 929 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 930 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 931 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 932 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 933 | self.executor_server.hold_jobs_in_build = False |
| 934 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 935 | self.waitUntilSettled() |
| 936 | |
| 937 | self.assertEqual(A.data['status'], 'MERGED') |
| 938 | self.assertEqual(B.data['status'], 'MERGED') |
| 939 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 940 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 941 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 942 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 943 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 944 | # TODO: move to test_gerrit (this is a unit test!) |
| 945 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 946 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 947 | (trusted, project) = tenant.getProject('org/project') |
| 948 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 949 | |
| 950 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 951 | # it easier for users to create events for testing. |
| 952 | event = zuul.model.TriggerEvent() |
| 953 | event.trigger_name = 'gerrit' |
| 954 | event.change_number = '1' |
| 955 | event.patch_number = '2' |
| 956 | |
| 957 | a = source.getChange(event) |
| 958 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 959 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 960 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 961 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 962 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 963 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 964 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 965 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 966 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 967 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 968 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 969 | def test_project_merge_conflict(self): |
| 970 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 971 | |
| 972 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 973 | A = self.fake_gerrit.addFakeChange('org/project', |
| 974 | 'master', 'A', |
| 975 | files={'conflict': 'foo'}) |
| 976 | B = self.fake_gerrit.addFakeChange('org/project', |
| 977 | 'master', 'B', |
| 978 | files={'conflict': 'bar'}) |
| 979 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 980 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 981 | A.addApproval('Code-Review', 2) |
| 982 | B.addApproval('Code-Review', 2) |
| 983 | C.addApproval('Code-Review', 2) |
| 984 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 985 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 986 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 987 | self.waitUntilSettled() |
| 988 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 989 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 990 | self.assertEqual(C.reported, 1) |
| 991 | |
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() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 996 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 997 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 998 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 999 | self.gearman_server.hold_jobs_in_queue = False |
| 1000 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1001 | self.waitUntilSettled() |
| 1002 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1003 | self.assertEqual(A.data['status'], 'MERGED') |
| 1004 | self.assertEqual(B.data['status'], 'NEW') |
| 1005 | self.assertEqual(C.data['status'], 'MERGED') |
| 1006 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1007 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1008 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1009 | |
| 1010 | self.assertHistory([ |
| 1011 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1012 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1013 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1014 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1015 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1016 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1017 | ], ordered=False) |
| 1018 | |
| 1019 | def test_delayed_merge_conflict(self): |
| 1020 | "Test that delayed check merge conflicts are handled properly" |
| 1021 | |
| 1022 | # 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] | 1023 | # the executor sucesfully merges a change based on an old |
| 1024 | # repo state (frozen by the scheduler) which would otherwise |
| 1025 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1026 | self.gearman_server.hold_jobs_in_queue = True |
| 1027 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1028 | 'master', 'A', |
| 1029 | files={'conflict': 'foo'}) |
| 1030 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1031 | 'master', 'B', |
| 1032 | files={'conflict': 'bar'}) |
| 1033 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1034 | 'master', 'C') |
| 1035 | C.setDependsOn(B, 1) |
| 1036 | |
| 1037 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1038 | A.addApproval('Code-Review', 2) |
| 1039 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1040 | self.waitUntilSettled() |
| 1041 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1042 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1043 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1044 | self.waitUntilSettled() |
| 1045 | |
| 1046 | self.assertEqual(A.reported, 1) |
| 1047 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1048 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1049 | |
| 1050 | # A merges while B and C are queued in check |
| 1051 | # Release A project-merge |
| 1052 | queue = self.gearman_server.getQueue() |
| 1053 | self.release(queue[0]) |
| 1054 | self.waitUntilSettled() |
| 1055 | |
| 1056 | # Release A project-test* |
| 1057 | # gate has higher precedence, so A's test jobs are added in |
| 1058 | # front of the merge jobs for B and C |
| 1059 | queue = self.gearman_server.getQueue() |
| 1060 | self.release(queue[0]) |
| 1061 | self.release(queue[1]) |
| 1062 | self.waitUntilSettled() |
| 1063 | |
| 1064 | self.assertEqual(A.data['status'], 'MERGED') |
| 1065 | self.assertEqual(B.data['status'], 'NEW') |
| 1066 | self.assertEqual(C.data['status'], 'NEW') |
| 1067 | self.assertEqual(A.reported, 2) |
| 1068 | self.assertEqual(B.reported, 0) |
| 1069 | self.assertEqual(C.reported, 0) |
| 1070 | self.assertHistory([ |
| 1071 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1072 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1073 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1074 | ], ordered=False) |
| 1075 | |
| 1076 | # B and C report merge conflicts |
| 1077 | # Release B project-merge |
| 1078 | queue = self.gearman_server.getQueue() |
| 1079 | self.release(queue[0]) |
| 1080 | self.waitUntilSettled() |
| 1081 | |
| 1082 | # Release C |
| 1083 | self.gearman_server.hold_jobs_in_queue = False |
| 1084 | self.gearman_server.release() |
| 1085 | self.waitUntilSettled() |
| 1086 | |
| 1087 | self.assertEqual(A.data['status'], 'MERGED') |
| 1088 | self.assertEqual(B.data['status'], 'NEW') |
| 1089 | self.assertEqual(C.data['status'], 'NEW') |
| 1090 | self.assertEqual(A.reported, 2) |
| 1091 | self.assertEqual(B.reported, 1) |
| 1092 | self.assertEqual(C.reported, 1) |
| 1093 | |
| 1094 | self.assertHistory([ |
| 1095 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1096 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1097 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1098 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1099 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1100 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1101 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1102 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1103 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1104 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1105 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1106 | def test_post(self): |
| 1107 | "Test that post jobs run" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1108 | p = "review.example.com/org/project" |
| 1109 | upstream = self.getUpstreamRepos([p]) |
| 1110 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1111 | A.setMerged() |
| 1112 | A_commit = str(upstream[p].commit('master')) |
| 1113 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1114 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1115 | e = { |
| 1116 | "type": "ref-updated", |
| 1117 | "submitter": { |
| 1118 | "name": "User Name", |
| 1119 | }, |
| 1120 | "refUpdate": { |
| 1121 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1122 | "newRev": A_commit, |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1123 | "refName": "master", |
| 1124 | "project": "org/project", |
| 1125 | } |
| 1126 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1127 | self.fake_gerrit.addEvent(e) |
| 1128 | self.waitUntilSettled() |
| 1129 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1130 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1131 | self.assertEqual(len(self.history), 1) |
| 1132 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1133 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1134 | def test_post_ignore_deletes(self): |
| 1135 | "Test that deleting refs does not trigger post jobs" |
| 1136 | |
| 1137 | e = { |
| 1138 | "type": "ref-updated", |
| 1139 | "submitter": { |
| 1140 | "name": "User Name", |
| 1141 | }, |
| 1142 | "refUpdate": { |
| 1143 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1144 | "newRev": "0000000000000000000000000000000000000000", |
| 1145 | "refName": "master", |
| 1146 | "project": "org/project", |
| 1147 | } |
| 1148 | } |
| 1149 | self.fake_gerrit.addEvent(e) |
| 1150 | self.waitUntilSettled() |
| 1151 | |
| 1152 | job_names = [x.name for x in self.history] |
| 1153 | self.assertEqual(len(self.history), 0) |
| 1154 | self.assertNotIn('project-post', job_names) |
| 1155 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1156 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1157 | def test_post_ignore_deletes_negative(self): |
| 1158 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1159 | e = { |
| 1160 | "type": "ref-updated", |
| 1161 | "submitter": { |
| 1162 | "name": "User Name", |
| 1163 | }, |
| 1164 | "refUpdate": { |
| 1165 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1166 | "newRev": "0000000000000000000000000000000000000000", |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 1167 | "refName": "testbranch", |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1168 | "project": "org/project", |
| 1169 | } |
| 1170 | } |
| 1171 | self.fake_gerrit.addEvent(e) |
| 1172 | self.waitUntilSettled() |
| 1173 | |
| 1174 | job_names = [x.name for x in self.history] |
| 1175 | self.assertEqual(len(self.history), 1) |
| 1176 | self.assertIn('project-post', job_names) |
| 1177 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1178 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1179 | def test_build_configuration_branch_interaction(self): |
| 1180 | "Test that switching between branches works" |
| 1181 | self.test_build_configuration() |
| 1182 | self.test_build_configuration_branch() |
| 1183 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1184 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1185 | repo = git.Repo(path) |
| 1186 | repo.heads.master.commit = repo.commit('init') |
| 1187 | self.test_build_configuration() |
| 1188 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1189 | def test_dependent_changes_rebase(self): |
| 1190 | # Test that no errors occur when we walk a dependency tree |
| 1191 | # with an unused leaf node due to a rebase. |
| 1192 | # Start by constructing: C -> B -> A |
| 1193 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1194 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1195 | B.setDependsOn(A, 1) |
| 1196 | |
| 1197 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1198 | C.setDependsOn(B, 1) |
| 1199 | |
| 1200 | # Then rebase to form: D -> C -> A |
| 1201 | C.addPatchset() # C,2 |
| 1202 | C.setDependsOn(A, 1) |
| 1203 | |
| 1204 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1205 | D.setDependsOn(C, 2) |
| 1206 | |
| 1207 | # Walk the entire tree |
| 1208 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1209 | self.waitUntilSettled() |
| 1210 | self.assertEqual(len(self.history), 3) |
| 1211 | |
| 1212 | # Verify that walking just part of the tree still works |
| 1213 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1214 | self.waitUntilSettled() |
| 1215 | self.assertEqual(len(self.history), 6) |
| 1216 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1217 | def test_dependent_changes_dequeue(self): |
| 1218 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1219 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1220 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1221 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1222 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1223 | A.addApproval('Code-Review', 2) |
| 1224 | B.addApproval('Code-Review', 2) |
| 1225 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1226 | |
| 1227 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1228 | M1.setMerged() |
| 1229 | |
| 1230 | # C -> B -> A -> M1 |
| 1231 | |
| 1232 | C.setDependsOn(B, 1) |
| 1233 | B.setDependsOn(A, 1) |
| 1234 | A.setDependsOn(M1, 1) |
| 1235 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1236 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1237 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1238 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1239 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1240 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1241 | |
| 1242 | self.waitUntilSettled() |
| 1243 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1244 | self.assertEqual(A.data['status'], 'NEW') |
| 1245 | self.assertEqual(A.reported, 2) |
| 1246 | self.assertEqual(B.data['status'], 'NEW') |
| 1247 | self.assertEqual(B.reported, 2) |
| 1248 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1249 | self.assertIn('This change depends on a change that failed to merge.', |
| 1250 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1251 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1252 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1253 | def test_failing_dependent_changes(self): |
| 1254 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1255 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1256 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1257 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1258 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1259 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1260 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1261 | A.addApproval('Code-Review', 2) |
| 1262 | B.addApproval('Code-Review', 2) |
| 1263 | C.addApproval('Code-Review', 2) |
| 1264 | D.addApproval('Code-Review', 2) |
| 1265 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1266 | |
| 1267 | # E, D -> C -> B, A |
| 1268 | |
| 1269 | D.setDependsOn(C, 1) |
| 1270 | C.setDependsOn(B, 1) |
| 1271 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1272 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1273 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1274 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1275 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1276 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1277 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1278 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1279 | |
| 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() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1283 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1284 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1285 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1286 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1287 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1288 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1289 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1290 | self.waitUntilSettled() |
| 1291 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1292 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1293 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1294 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1295 | build.release() |
| 1296 | self.waitUntilSettled() |
| 1297 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1298 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1299 | self.waitUntilSettled() |
| 1300 | |
| 1301 | self.assertEqual(A.data['status'], 'MERGED') |
| 1302 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1303 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1304 | self.assertEqual(B.data['status'], 'NEW') |
| 1305 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1306 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1307 | self.assertEqual(C.data['status'], 'NEW') |
| 1308 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1309 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1310 | self.assertEqual(D.data['status'], 'NEW') |
| 1311 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1312 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1313 | self.assertEqual(E.data['status'], 'MERGED') |
| 1314 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1315 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1316 | self.assertEqual(len(self.history), 18) |
| 1317 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1318 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1319 | "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] | 1320 | # If it's dequeued more than once, we should see extra |
| 1321 | # aborted jobs. |
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.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1324 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1325 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1326 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1327 | A.addApproval('Code-Review', 2) |
| 1328 | B.addApproval('Code-Review', 2) |
| 1329 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1330 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1331 | self.executor_server.failJob('project-test1', A) |
| 1332 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1333 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1334 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1335 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1336 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | |
| 1338 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1340 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1341 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1342 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1343 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1344 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1345 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1346 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1347 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1348 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1349 | self.waitUntilSettled() |
| 1350 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1351 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1352 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1353 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1354 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1355 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1356 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1357 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1358 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1359 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1360 | self.waitUntilSettled() |
| 1361 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1362 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1363 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1364 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1365 | self.executor_server.hold_jobs_in_build = False |
| 1366 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1367 | self.waitUntilSettled() |
| 1368 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1369 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1370 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1371 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1372 | self.assertEqual(A.data['status'], 'NEW') |
| 1373 | self.assertEqual(B.data['status'], 'MERGED') |
| 1374 | self.assertEqual(C.data['status'], 'MERGED') |
| 1375 | self.assertEqual(A.reported, 2) |
| 1376 | self.assertEqual(B.reported, 2) |
| 1377 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1378 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1379 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1380 | def test_nonvoting_job(self): |
| 1381 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1382 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1383 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1384 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1385 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1386 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1387 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1388 | |
| 1389 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1390 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1391 | self.assertEqual(A.data['status'], 'MERGED') |
| 1392 | self.assertEqual(A.reported, 2) |
| 1393 | self.assertEqual( |
| 1394 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1395 | 'SUCCESS') |
| 1396 | self.assertEqual( |
| 1397 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1398 | 'SUCCESS') |
| 1399 | self.assertEqual( |
| 1400 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1401 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1402 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1403 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1404 | parameters['zuul']['voting']) |
| 1405 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1406 | parameters['zuul']['voting']) |
| 1407 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1408 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1409 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1410 | def test_check_queue_success(self): |
| 1411 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1412 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1413 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1414 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1415 | |
| 1416 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1417 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1418 | self.assertEqual(A.data['status'], 'NEW') |
| 1419 | self.assertEqual(A.reported, 1) |
| 1420 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1421 | 'SUCCESS') |
| 1422 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1423 | 'SUCCESS') |
| 1424 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1425 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1426 | |
| 1427 | def test_check_queue_failure(self): |
| 1428 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1429 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1430 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1431 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1432 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1433 | |
| 1434 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1435 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1436 | self.assertEqual(A.data['status'], 'NEW') |
| 1437 | self.assertEqual(A.reported, 1) |
| 1438 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1439 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1440 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1441 | 'SUCCESS') |
| 1442 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1443 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1444 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1445 | @simple_layout('layouts/autohold.yaml') |
| 1446 | def test_autohold(self): |
| 1447 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1448 | |
| 1449 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1450 | self.gearman_server.port) |
| 1451 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1452 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1453 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1454 | self.assertTrue(r) |
| 1455 | |
| 1456 | self.executor_server.failJob('project-test2', A) |
| 1457 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1458 | |
| 1459 | self.waitUntilSettled() |
| 1460 | |
| 1461 | self.assertEqual(A.data['status'], 'NEW') |
| 1462 | self.assertEqual(A.reported, 1) |
| 1463 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1464 | 'FAILURE') |
| 1465 | |
| 1466 | # Check nodepool for a held node |
| 1467 | held_node = None |
| 1468 | for node in self.fake_nodepool.getNodes(): |
| 1469 | if node['state'] == zuul.model.STATE_HOLD: |
| 1470 | held_node = node |
| 1471 | break |
| 1472 | self.assertIsNotNone(held_node) |
| 1473 | |
| 1474 | # Validate node has recorded the failed job |
| 1475 | self.assertEqual( |
| 1476 | held_node['hold_job'], |
| 1477 | " ".join(['tenant-one', |
| 1478 | 'review.example.com/org/project', |
| 1479 | 'project-test2']) |
| 1480 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1481 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1482 | |
| 1483 | # Another failed change should not hold any more nodes |
| 1484 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1485 | self.executor_server.failJob('project-test2', B) |
| 1486 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1487 | self.waitUntilSettled() |
| 1488 | self.assertEqual(B.data['status'], 'NEW') |
| 1489 | self.assertEqual(B.reported, 1) |
| 1490 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1491 | 'FAILURE') |
| 1492 | |
| 1493 | held_nodes = 0 |
| 1494 | for node in self.fake_nodepool.getNodes(): |
| 1495 | if node['state'] == zuul.model.STATE_HOLD: |
| 1496 | held_nodes += 1 |
| 1497 | self.assertEqual(held_nodes, 1) |
| 1498 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1499 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1500 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1501 | # This particular test does a large amount of merges and needs a little |
| 1502 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1503 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1504 | "test that dependent changes behind dequeued changes work" |
| 1505 | # This complicated test is a reproduction of a real life bug |
| 1506 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1507 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1508 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1509 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1510 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1511 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1512 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1513 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1514 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1515 | D.setDependsOn(C, 1) |
| 1516 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1517 | A.addApproval('Code-Review', 2) |
| 1518 | B.addApproval('Code-Review', 2) |
| 1519 | C.addApproval('Code-Review', 2) |
| 1520 | D.addApproval('Code-Review', 2) |
| 1521 | E.addApproval('Code-Review', 2) |
| 1522 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1523 | |
| 1524 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1525 | |
| 1526 | # Change object re-use in the gerrit trigger is hidden if |
| 1527 | # changes are added in quick succession; waiting makes it more |
| 1528 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1529 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1530 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1531 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1532 | self.waitUntilSettled() |
| 1533 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1534 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1535 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1536 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1537 | self.waitUntilSettled() |
| 1538 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1539 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1540 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1541 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1542 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1543 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1544 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1545 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1546 | self.waitUntilSettled() |
| 1547 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1548 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1549 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1550 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1551 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1552 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1553 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1554 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1555 | self.waitUntilSettled() |
| 1556 | |
| 1557 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1558 | |
| 1559 | # Grab pointers to the jobs we want to release before |
| 1560 | # releasing any, because list indexes may change as |
| 1561 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1562 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1563 | a.release() |
| 1564 | b.release() |
| 1565 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1566 | self.waitUntilSettled() |
| 1567 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1568 | self.executor_server.hold_jobs_in_build = False |
| 1569 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1570 | self.waitUntilSettled() |
| 1571 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1572 | self.assertEqual(A.data['status'], 'NEW') |
| 1573 | self.assertEqual(B.data['status'], 'MERGED') |
| 1574 | self.assertEqual(C.data['status'], 'MERGED') |
| 1575 | self.assertEqual(D.data['status'], 'MERGED') |
| 1576 | self.assertEqual(E.data['status'], 'MERGED') |
| 1577 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1578 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1579 | self.assertEqual(A.reported, 2) |
| 1580 | self.assertEqual(B.reported, 2) |
| 1581 | self.assertEqual(C.reported, 2) |
| 1582 | self.assertEqual(D.reported, 2) |
| 1583 | self.assertEqual(E.reported, 2) |
| 1584 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1585 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1586 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1587 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1588 | |
| 1589 | def test_merger_repack(self): |
| 1590 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1591 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1592 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1593 | A.addApproval('Code-Review', 2) |
| 1594 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1595 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1596 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1597 | 'SUCCESS') |
| 1598 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1599 | 'SUCCESS') |
| 1600 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1601 | 'SUCCESS') |
| 1602 | self.assertEqual(A.data['status'], 'MERGED') |
| 1603 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1604 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1605 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1606 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1607 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1608 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1609 | if os.path.exists(path): |
| 1610 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1611 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1612 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1613 | if os.path.exists(path): |
| 1614 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1615 | |
| 1616 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1617 | A.addApproval('Code-Review', 2) |
| 1618 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1619 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1620 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1621 | 'SUCCESS') |
| 1622 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1623 | 'SUCCESS') |
| 1624 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1625 | 'SUCCESS') |
| 1626 | self.assertEqual(A.data['status'], 'MERGED') |
| 1627 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1628 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1629 | def test_merger_repack_large_change(self): |
| 1630 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1631 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1632 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1633 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1634 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1635 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1636 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1637 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1638 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1639 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1640 | # TODOv3(jeblair): add hostname to upstream root |
| 1641 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1642 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1643 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1644 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1645 | if os.path.exists(path): |
| 1646 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1647 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1648 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1649 | if os.path.exists(path): |
| 1650 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1651 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1652 | A.addApproval('Code-Review', 2) |
| 1653 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1654 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1655 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1656 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1657 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1658 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1659 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1660 | 'SUCCESS') |
| 1661 | self.assertEqual(A.data['status'], 'MERGED') |
| 1662 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1663 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1664 | def test_new_patchset_dequeues_old(self): |
| 1665 | "Test that a new patchset causes the old to be dequeued" |
| 1666 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1667 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1668 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1669 | M.setMerged() |
| 1670 | |
| 1671 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1672 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1673 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1674 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1675 | A.addApproval('Code-Review', 2) |
| 1676 | B.addApproval('Code-Review', 2) |
| 1677 | C.addApproval('Code-Review', 2) |
| 1678 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1679 | |
| 1680 | C.setDependsOn(B, 1) |
| 1681 | B.setDependsOn(A, 1) |
| 1682 | A.setDependsOn(M, 1) |
| 1683 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1684 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1685 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1686 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1687 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1688 | self.waitUntilSettled() |
| 1689 | |
| 1690 | B.addPatchset() |
| 1691 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1692 | self.waitUntilSettled() |
| 1693 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1694 | self.executor_server.hold_jobs_in_build = False |
| 1695 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1696 | self.waitUntilSettled() |
| 1697 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1698 | self.assertEqual(A.data['status'], 'MERGED') |
| 1699 | self.assertEqual(A.reported, 2) |
| 1700 | self.assertEqual(B.data['status'], 'NEW') |
| 1701 | self.assertEqual(B.reported, 2) |
| 1702 | self.assertEqual(C.data['status'], 'NEW') |
| 1703 | self.assertEqual(C.reported, 2) |
| 1704 | self.assertEqual(D.data['status'], 'MERGED') |
| 1705 | self.assertEqual(D.reported, 2) |
| 1706 | 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] | 1707 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1708 | def test_new_patchset_check(self): |
| 1709 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1710 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1711 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1712 | |
| 1713 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1714 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1715 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1716 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1717 | |
| 1718 | # Add two git-dependent changes |
| 1719 | B.setDependsOn(A, 1) |
| 1720 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1721 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1722 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1723 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1724 | |
| 1725 | # A live item, and a non-live/live pair |
| 1726 | items = check_pipeline.getAllItems() |
| 1727 | self.assertEqual(len(items), 3) |
| 1728 | |
| 1729 | self.assertEqual(items[0].change.number, '1') |
| 1730 | self.assertEqual(items[0].change.patchset, '1') |
| 1731 | self.assertFalse(items[0].live) |
| 1732 | |
| 1733 | self.assertEqual(items[1].change.number, '2') |
| 1734 | self.assertEqual(items[1].change.patchset, '1') |
| 1735 | self.assertTrue(items[1].live) |
| 1736 | |
| 1737 | self.assertEqual(items[2].change.number, '1') |
| 1738 | self.assertEqual(items[2].change.patchset, '1') |
| 1739 | self.assertTrue(items[2].live) |
| 1740 | |
| 1741 | # Add a new patchset to A |
| 1742 | A.addPatchset() |
| 1743 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1744 | self.waitUntilSettled() |
| 1745 | |
| 1746 | # The live copy of A,1 should be gone, but the non-live and B |
| 1747 | # should continue, and we should have a new A,2 |
| 1748 | items = check_pipeline.getAllItems() |
| 1749 | self.assertEqual(len(items), 3) |
| 1750 | |
| 1751 | self.assertEqual(items[0].change.number, '1') |
| 1752 | self.assertEqual(items[0].change.patchset, '1') |
| 1753 | self.assertFalse(items[0].live) |
| 1754 | |
| 1755 | self.assertEqual(items[1].change.number, '2') |
| 1756 | self.assertEqual(items[1].change.patchset, '1') |
| 1757 | self.assertTrue(items[1].live) |
| 1758 | |
| 1759 | self.assertEqual(items[2].change.number, '1') |
| 1760 | self.assertEqual(items[2].change.patchset, '2') |
| 1761 | self.assertTrue(items[2].live) |
| 1762 | |
| 1763 | # Add a new patchset to B |
| 1764 | B.addPatchset() |
| 1765 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1766 | self.waitUntilSettled() |
| 1767 | |
| 1768 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1769 | # but we should have a new B,2 (still based on A,1) |
| 1770 | items = check_pipeline.getAllItems() |
| 1771 | self.assertEqual(len(items), 3) |
| 1772 | |
| 1773 | self.assertEqual(items[0].change.number, '1') |
| 1774 | self.assertEqual(items[0].change.patchset, '2') |
| 1775 | self.assertTrue(items[0].live) |
| 1776 | |
| 1777 | self.assertEqual(items[1].change.number, '1') |
| 1778 | self.assertEqual(items[1].change.patchset, '1') |
| 1779 | self.assertFalse(items[1].live) |
| 1780 | |
| 1781 | self.assertEqual(items[2].change.number, '2') |
| 1782 | self.assertEqual(items[2].change.patchset, '2') |
| 1783 | self.assertTrue(items[2].live) |
| 1784 | |
| 1785 | self.builds[0].release() |
| 1786 | self.waitUntilSettled() |
| 1787 | self.builds[0].release() |
| 1788 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1789 | self.executor_server.hold_jobs_in_build = False |
| 1790 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1791 | self.waitUntilSettled() |
| 1792 | |
| 1793 | self.assertEqual(A.reported, 1) |
| 1794 | self.assertEqual(B.reported, 1) |
| 1795 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1796 | self.assertEqual(self.history[0].changes, '1,1') |
| 1797 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1798 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1799 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1800 | self.assertEqual(self.history[2].changes, '1,2') |
| 1801 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1802 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1803 | |
| 1804 | def test_abandoned_gate(self): |
| 1805 | "Test that an abandoned change is dequeued from gate" |
| 1806 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1807 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1808 | |
| 1809 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1810 | A.addApproval('Code-Review', 2) |
| 1811 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1812 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1813 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1814 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1815 | |
| 1816 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1817 | self.waitUntilSettled() |
| 1818 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1819 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1820 | self.waitUntilSettled() |
| 1821 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1822 | self.assertBuilds([]) |
| 1823 | self.assertHistory([ |
| 1824 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1825 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1826 | self.assertEqual(A.reported, 1, |
| 1827 | "Abandoned gate change should report only start") |
| 1828 | |
| 1829 | def test_abandoned_check(self): |
| 1830 | "Test that an abandoned change is dequeued from check" |
| 1831 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1832 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1833 | |
| 1834 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1835 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1836 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1837 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1838 | |
| 1839 | # Add two git-dependent changes |
| 1840 | B.setDependsOn(A, 1) |
| 1841 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1842 | self.waitUntilSettled() |
| 1843 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1844 | self.waitUntilSettled() |
| 1845 | # A live item, and a non-live/live pair |
| 1846 | items = check_pipeline.getAllItems() |
| 1847 | self.assertEqual(len(items), 3) |
| 1848 | |
| 1849 | self.assertEqual(items[0].change.number, '1') |
| 1850 | self.assertFalse(items[0].live) |
| 1851 | |
| 1852 | self.assertEqual(items[1].change.number, '2') |
| 1853 | self.assertTrue(items[1].live) |
| 1854 | |
| 1855 | self.assertEqual(items[2].change.number, '1') |
| 1856 | self.assertTrue(items[2].live) |
| 1857 | |
| 1858 | # Abandon A |
| 1859 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1860 | self.waitUntilSettled() |
| 1861 | |
| 1862 | # The live copy of A should be gone, but the non-live and B |
| 1863 | # should continue |
| 1864 | items = check_pipeline.getAllItems() |
| 1865 | self.assertEqual(len(items), 2) |
| 1866 | |
| 1867 | self.assertEqual(items[0].change.number, '1') |
| 1868 | self.assertFalse(items[0].live) |
| 1869 | |
| 1870 | self.assertEqual(items[1].change.number, '2') |
| 1871 | self.assertTrue(items[1].live) |
| 1872 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1873 | self.executor_server.hold_jobs_in_build = False |
| 1874 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1875 | self.waitUntilSettled() |
| 1876 | |
| 1877 | self.assertEqual(len(self.history), 4) |
| 1878 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1879 | 'Build should have been aborted') |
| 1880 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1881 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1882 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1883 | def test_abandoned_not_timer(self): |
| 1884 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1885 | # This test can not use simple_layout because it must start |
| 1886 | # with a configuration which does not include a |
| 1887 | # timer-triggered job so that we have an opportunity to set |
| 1888 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1889 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1890 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1891 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1892 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1893 | # The pipeline triggers every second, so we should have seen |
| 1894 | # several by now. |
| 1895 | time.sleep(5) |
| 1896 | self.waitUntilSettled() |
| 1897 | # Stop queuing timer triggered jobs so that the assertions |
| 1898 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1899 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1900 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1901 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1902 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1903 | # If APScheduler is in mid-event when we remove the job, we |
| 1904 | # can end up with one more event firing, so give it an extra |
| 1905 | # second to settle. |
| 1906 | time.sleep(1) |
| 1907 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1908 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1909 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1910 | |
| 1911 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1912 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1913 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1914 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1915 | |
| 1916 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1917 | self.waitUntilSettled() |
| 1918 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1919 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1920 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1921 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1922 | self.waitUntilSettled() |
| 1923 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1924 | def test_new_patchset_dequeues_old_on_head(self): |
| 1925 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1926 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1927 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1928 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1929 | M.setMerged() |
| 1930 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1931 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1932 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1933 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1934 | A.addApproval('Code-Review', 2) |
| 1935 | B.addApproval('Code-Review', 2) |
| 1936 | C.addApproval('Code-Review', 2) |
| 1937 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1938 | |
| 1939 | C.setDependsOn(B, 1) |
| 1940 | B.setDependsOn(A, 1) |
| 1941 | A.setDependsOn(M, 1) |
| 1942 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1943 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1944 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1945 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1946 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1947 | self.waitUntilSettled() |
| 1948 | |
| 1949 | A.addPatchset() |
| 1950 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1951 | self.waitUntilSettled() |
| 1952 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1953 | self.executor_server.hold_jobs_in_build = False |
| 1954 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1955 | self.waitUntilSettled() |
| 1956 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1957 | self.assertEqual(A.data['status'], 'NEW') |
| 1958 | self.assertEqual(A.reported, 2) |
| 1959 | self.assertEqual(B.data['status'], 'NEW') |
| 1960 | self.assertEqual(B.reported, 2) |
| 1961 | self.assertEqual(C.data['status'], 'NEW') |
| 1962 | self.assertEqual(C.reported, 2) |
| 1963 | self.assertEqual(D.data['status'], 'MERGED') |
| 1964 | self.assertEqual(D.reported, 2) |
| 1965 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1966 | |
| 1967 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1968 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1969 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1970 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1971 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1972 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1973 | A.addApproval('Code-Review', 2) |
| 1974 | B.addApproval('Code-Review', 2) |
| 1975 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1976 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1977 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1978 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1979 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1980 | self.waitUntilSettled() |
| 1981 | |
| 1982 | B.addPatchset() |
| 1983 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1984 | self.waitUntilSettled() |
| 1985 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1986 | self.executor_server.hold_jobs_in_build = False |
| 1987 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1988 | self.waitUntilSettled() |
| 1989 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1990 | self.assertEqual(A.data['status'], 'MERGED') |
| 1991 | self.assertEqual(A.reported, 2) |
| 1992 | self.assertEqual(B.data['status'], 'NEW') |
| 1993 | self.assertEqual(B.reported, 2) |
| 1994 | self.assertEqual(C.data['status'], 'MERGED') |
| 1995 | self.assertEqual(C.reported, 2) |
| 1996 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1997 | |
| 1998 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1999 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2000 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2001 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2002 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2003 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2004 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2005 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2006 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2007 | self.waitUntilSettled() |
| 2008 | |
| 2009 | B.addPatchset() |
| 2010 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2011 | self.waitUntilSettled() |
| 2012 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2013 | self.executor_server.hold_jobs_in_build = False |
| 2014 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2015 | self.waitUntilSettled() |
| 2016 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2017 | self.assertEqual(A.data['status'], 'NEW') |
| 2018 | self.assertEqual(A.reported, 1) |
| 2019 | self.assertEqual(B.data['status'], 'NEW') |
| 2020 | self.assertEqual(B.reported, 1) |
| 2021 | self.assertEqual(C.data['status'], 'NEW') |
| 2022 | self.assertEqual(C.reported, 1) |
| 2023 | self.assertEqual(len(self.history), 10) |
| 2024 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2025 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2026 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2027 | def test_noop_job(self): |
| 2028 | "Test that the internal noop job works" |
| 2029 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2030 | A.addApproval('Code-Review', 2) |
| 2031 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2032 | self.waitUntilSettled() |
| 2033 | |
| 2034 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2035 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2036 | self.assertEqual(len(self.history), 0) |
| 2037 | self.assertEqual(A.data['status'], 'MERGED') |
| 2038 | self.assertEqual(A.reported, 2) |
| 2039 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2040 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2041 | def test_no_job_project(self): |
| 2042 | "Test that reports with no jobs don't get sent" |
| 2043 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2044 | 'master', 'A') |
| 2045 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2046 | self.waitUntilSettled() |
| 2047 | |
| 2048 | # Change wasn't reported to |
| 2049 | self.assertEqual(A.reported, False) |
| 2050 | |
| 2051 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2052 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2053 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2054 | items = check_pipeline.getAllItems() |
| 2055 | self.assertEqual(len(items), 0) |
| 2056 | |
| 2057 | self.assertEqual(len(self.history), 0) |
| 2058 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2059 | def test_zuul_refs(self): |
| 2060 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2061 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2062 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2063 | M1.setMerged() |
| 2064 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2065 | M2.setMerged() |
| 2066 | |
| 2067 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2068 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2069 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2070 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2071 | A.addApproval('Code-Review', 2) |
| 2072 | B.addApproval('Code-Review', 2) |
| 2073 | C.addApproval('Code-Review', 2) |
| 2074 | D.addApproval('Code-Review', 2) |
| 2075 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2076 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2077 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2078 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2079 | |
| 2080 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2081 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2082 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2083 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2084 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2085 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2086 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2087 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2088 | self.waitUntilSettled() |
| 2089 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2090 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2091 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2092 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2093 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2094 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2095 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2096 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2097 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2098 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2099 | d_build = x |
| 2100 | if a_build and b_build and c_build and d_build: |
| 2101 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2102 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2103 | # should have a, not b, and should not be in project2 |
| 2104 | self.assertTrue(a_build.hasChanges(A)) |
| 2105 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2106 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2107 | # should have a and b, and should not be in project2 |
| 2108 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2109 | self.assertFalse(b_build.hasChanges(M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2110 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2111 | # should have a and b in 1, c in 2 |
| 2112 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2113 | self.assertFalse(c_build.hasChanges(D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2114 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2115 | # should have a and b in 1, c and d in 2 |
| 2116 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2117 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2118 | self.executor_server.hold_jobs_in_build = False |
| 2119 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2120 | self.waitUntilSettled() |
| 2121 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2122 | self.assertEqual(A.data['status'], 'MERGED') |
| 2123 | self.assertEqual(A.reported, 2) |
| 2124 | self.assertEqual(B.data['status'], 'MERGED') |
| 2125 | self.assertEqual(B.reported, 2) |
| 2126 | self.assertEqual(C.data['status'], 'MERGED') |
| 2127 | self.assertEqual(C.reported, 2) |
| 2128 | self.assertEqual(D.data['status'], 'MERGED') |
| 2129 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2130 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2131 | def test_rerun_on_error(self): |
| 2132 | "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] | 2133 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2134 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2135 | A.addApproval('Code-Review', 2) |
| 2136 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2137 | self.waitUntilSettled() |
| 2138 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2139 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2140 | self.executor_server.hold_jobs_in_build = False |
| 2141 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2142 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2143 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2144 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2145 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2146 | def test_statsd(self): |
| 2147 | "Test each of the statsd methods used in the scheduler" |
| 2148 | import extras |
| 2149 | statsd = extras.try_import('statsd.statsd') |
| 2150 | statsd.incr('test-incr') |
| 2151 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2152 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2153 | self.assertReportedStat('test-incr', '1|c') |
| 2154 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2155 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2156 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2157 | def test_stuck_job_cleanup(self): |
| 2158 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2159 | |
| 2160 | # 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] | 2161 | self.gearman_server.hold_jobs_in_queue = True |
| 2162 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2163 | A.addApproval('Code-Review', 2) |
| 2164 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2165 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2166 | # 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] | 2167 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2168 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2169 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2170 | self.sched.reconfigure(self.config) |
| 2171 | self.waitUntilSettled() |
| 2172 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2173 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2174 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2175 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2176 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2177 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2178 | |
| 2179 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2180 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2181 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2182 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2183 | def test_file_head(self): |
| 2184 | # This is a regression test for an observed bug. A change |
| 2185 | # with a file named "HEAD" in the root directory of the repo |
| 2186 | # was processed by a merger. It then was unable to reset the |
| 2187 | # repo because of: |
| 2188 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2189 | # with exit code 128 |
| 2190 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2191 | # and filename |
| 2192 | # Use '--' to separate filenames from revisions' |
| 2193 | |
| 2194 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2195 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2196 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2197 | |
| 2198 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2199 | self.waitUntilSettled() |
| 2200 | |
| 2201 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2202 | self.waitUntilSettled() |
| 2203 | |
| 2204 | self.assertIn('Build succeeded', A.messages[0]) |
| 2205 | self.assertIn('Build succeeded', B.messages[0]) |
| 2206 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2207 | def test_file_jobs(self): |
| 2208 | "Test that file jobs run only when appropriate" |
| 2209 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2210 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2211 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2212 | A.addApproval('Code-Review', 2) |
| 2213 | B.addApproval('Code-Review', 2) |
| 2214 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2215 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2216 | self.waitUntilSettled() |
| 2217 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2218 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2219 | if x.name == 'project-testfile'] |
| 2220 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2221 | self.assertEqual(len(testfile_jobs), 1) |
| 2222 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2223 | self.assertEqual(A.data['status'], 'MERGED') |
| 2224 | self.assertEqual(A.reported, 2) |
| 2225 | self.assertEqual(B.data['status'], 'MERGED') |
| 2226 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2227 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2228 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2229 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2230 | if should_skip: |
| 2231 | files = {'ignoreme': 'ignored\n'} |
| 2232 | else: |
| 2233 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2234 | |
| 2235 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2236 | 'master', |
| 2237 | 'test irrelevant-files', |
| 2238 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2239 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2240 | self.waitUntilSettled() |
| 2241 | |
| 2242 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2243 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2244 | |
| 2245 | if should_skip: |
| 2246 | self.assertEqual([], tested_change_ids) |
| 2247 | else: |
| 2248 | self.assertIn(change.data['number'], tested_change_ids) |
| 2249 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2250 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2251 | def test_irrelevant_files_match_skips_job(self): |
| 2252 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2253 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2254 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2255 | def test_irrelevant_files_no_match_runs_job(self): |
| 2256 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2257 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2258 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2259 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2260 | files = {'ignoreme': 'ignored\n'} |
| 2261 | |
| 2262 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2263 | 'master', |
| 2264 | 'test irrelevant-files', |
| 2265 | files=files) |
| 2266 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2267 | self.waitUntilSettled() |
| 2268 | |
| 2269 | run_jobs = set([build.name for build in self.history]) |
| 2270 | |
| 2271 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2272 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2273 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2274 | def test_queue_names(self): |
| 2275 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2276 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2277 | (trusted, project1) = tenant.getProject('org/project1') |
| 2278 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2279 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2280 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2281 | self.assertEqual(q1.name, 'integrated') |
| 2282 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2283 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2284 | def test_queue_precedence(self): |
| 2285 | "Test that queue precedence works" |
| 2286 | |
| 2287 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2288 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2289 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2290 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2291 | A.addApproval('Code-Review', 2) |
| 2292 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2293 | |
| 2294 | self.waitUntilSettled() |
| 2295 | self.gearman_server.hold_jobs_in_queue = False |
| 2296 | self.gearman_server.release() |
| 2297 | self.waitUntilSettled() |
| 2298 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2299 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2300 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2301 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2302 | self.waitUntilSettled() |
| 2303 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2304 | self.log.debug(self.history) |
| 2305 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2306 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2307 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2308 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2309 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2310 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2311 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2312 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2313 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2314 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2316 | A.addApproval('Code-Review', 2) |
| 2317 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2318 | self.waitUntilSettled() |
| 2319 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2320 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2321 | self.waitUntilSettled() |
| 2322 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2323 | port = self.webapp.server.socket.getsockname()[1] |
| 2324 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2325 | req = urllib.request.Request( |
| 2326 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2327 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2328 | headers = f.info() |
| 2329 | self.assertIn('Content-Length', headers) |
| 2330 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2331 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2332 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2333 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2334 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2335 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2336 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2337 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2338 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2339 | self.executor_server.hold_jobs_in_build = False |
| 2340 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2341 | self.waitUntilSettled() |
| 2342 | |
| 2343 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2344 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2345 | for p in data['pipelines']: |
| 2346 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2347 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2348 | self.assertEqual(q['window'], 20) |
| 2349 | else: |
| 2350 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2351 | for head in q['heads']: |
| 2352 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2353 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2354 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2355 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2356 | status_jobs.append(job) |
| 2357 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2358 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2359 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2360 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2361 | uuid=status_jobs[0]['uuid']), |
| 2362 | status_jobs[0]['url']) |
| 2363 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2364 | 'finger://{hostname}/{uuid}'.format( |
| 2365 | hostname=self.executor_server.hostname, |
| 2366 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2367 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2368 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2369 | self.assertEqual( |
| 2370 | 'finger://{hostname}/{uuid}'.format( |
| 2371 | hostname=self.executor_server.hostname, |
| 2372 | uuid=status_jobs[0]['uuid']), |
| 2373 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2374 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2375 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2376 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2377 | uuid=status_jobs[1]['uuid']), |
| 2378 | status_jobs[1]['url']) |
| 2379 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2380 | 'finger://{hostname}/{uuid}'.format( |
| 2381 | hostname=self.executor_server.hostname, |
| 2382 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2383 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2384 | self.assertEqual( |
| 2385 | 'finger://{hostname}/{uuid}'.format( |
| 2386 | hostname=self.executor_server.hostname, |
| 2387 | uuid=status_jobs[1]['uuid']), |
| 2388 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2389 | |
| 2390 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2391 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2392 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2393 | uuid=status_jobs[2]['uuid']), |
| 2394 | status_jobs[2]['url']) |
| 2395 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2396 | 'finger://{hostname}/{uuid}'.format( |
| 2397 | hostname=self.executor_server.hostname, |
| 2398 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2399 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2400 | self.assertEqual( |
| 2401 | 'finger://{hostname}/{uuid}'.format( |
| 2402 | hostname=self.executor_server.hostname, |
| 2403 | uuid=status_jobs[2]['uuid']), |
| 2404 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2405 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2406 | # check job dependencies |
| 2407 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2408 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2409 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2410 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2411 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2412 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2413 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2414 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2415 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2416 | def test_live_reconfiguration(self): |
| 2417 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2418 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2419 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2420 | A.addApproval('Code-Review', 2) |
| 2421 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2422 | self.waitUntilSettled() |
| 2423 | |
| 2424 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2425 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2426 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2427 | self.executor_server.hold_jobs_in_build = False |
| 2428 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2429 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2430 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2431 | 'SUCCESS') |
| 2432 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2433 | 'SUCCESS') |
| 2434 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2435 | 'SUCCESS') |
| 2436 | self.assertEqual(A.data['status'], 'MERGED') |
| 2437 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2438 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2439 | def test_live_reconfiguration_merge_conflict(self): |
| 2440 | # A real-world bug: a change in a gate queue has a merge |
| 2441 | # conflict and a job is added to its project while it's |
| 2442 | # sitting in the queue. The job gets added to the change and |
| 2443 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2444 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2445 | |
| 2446 | # This change is fine. It's here to stop the queue long |
| 2447 | # enough for the next change to be subject to the |
| 2448 | # reconfiguration, as well as to provide a conflict for the |
| 2449 | # next change. This change will succeed and merge. |
| 2450 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2451 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2452 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2453 | |
| 2454 | # This change will be in merge conflict. During the |
| 2455 | # reconfiguration, we will add a job. We want to make sure |
| 2456 | # that doesn't cause it to get stuck. |
| 2457 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2458 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2459 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2460 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2461 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2462 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2463 | |
| 2464 | self.waitUntilSettled() |
| 2465 | |
| 2466 | # No jobs have run yet |
| 2467 | self.assertEqual(A.data['status'], 'NEW') |
| 2468 | self.assertEqual(A.reported, 1) |
| 2469 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2470 | self.assertEqual(len(self.history), 0) |
| 2471 | |
| 2472 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2473 | self.commitConfigUpdate('common-config', |
| 2474 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2475 | self.sched.reconfigure(self.config) |
| 2476 | self.waitUntilSettled() |
| 2477 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2478 | self.executor_server.hold_jobs_in_build = False |
| 2479 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2480 | self.waitUntilSettled() |
| 2481 | |
| 2482 | self.assertEqual(A.data['status'], 'MERGED') |
| 2483 | self.assertEqual(A.reported, 2) |
| 2484 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2485 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2486 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2487 | 'SUCCESS') |
| 2488 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2489 | 'SUCCESS') |
| 2490 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2491 | 'SUCCESS') |
| 2492 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2493 | 'SUCCESS') |
| 2494 | self.assertEqual(len(self.history), 4) |
| 2495 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2496 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2497 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2498 | # that tests a job added to a job tree with a failed root does |
| 2499 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2500 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2501 | |
| 2502 | # This change is fine. It's here to stop the queue long |
| 2503 | # enough for the next change to be subject to the |
| 2504 | # reconfiguration. This change will succeed and merge. |
| 2505 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2506 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2507 | A.addApproval('Code-Review', 2) |
| 2508 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2509 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2510 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2511 | self.waitUntilSettled() |
| 2512 | |
| 2513 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2514 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2515 | B.addApproval('Code-Review', 2) |
| 2516 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2517 | self.waitUntilSettled() |
| 2518 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2519 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2520 | self.waitUntilSettled() |
| 2521 | |
| 2522 | # Both -merge jobs have run, but no others. |
| 2523 | self.assertEqual(A.data['status'], 'NEW') |
| 2524 | self.assertEqual(A.reported, 1) |
| 2525 | self.assertEqual(B.data['status'], 'NEW') |
| 2526 | self.assertEqual(B.reported, 1) |
| 2527 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2528 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2529 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2530 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2531 | self.assertEqual(len(self.history), 2) |
| 2532 | |
| 2533 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2534 | self.commitConfigUpdate('common-config', |
| 2535 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2536 | self.sched.reconfigure(self.config) |
| 2537 | self.waitUntilSettled() |
| 2538 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2539 | self.executor_server.hold_jobs_in_build = False |
| 2540 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2541 | self.waitUntilSettled() |
| 2542 | |
| 2543 | self.assertEqual(A.data['status'], 'MERGED') |
| 2544 | self.assertEqual(A.reported, 2) |
| 2545 | self.assertEqual(B.data['status'], 'NEW') |
| 2546 | self.assertEqual(B.reported, 2) |
| 2547 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2548 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2549 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2550 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2551 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2552 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2553 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2554 | self.assertEqual(len(self.history), 5) |
| 2555 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2556 | def test_live_reconfiguration_failed_job(self): |
| 2557 | # Test that a change with a removed failing job does not |
| 2558 | # disrupt reconfiguration. If a change has a failed job and |
| 2559 | # that job is removed during a reconfiguration, we observed a |
| 2560 | # bug where the code to re-set build statuses would run on |
| 2561 | # that build and raise an exception because the job no longer |
| 2562 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2563 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2564 | |
| 2565 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2566 | |
| 2567 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2568 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2569 | |
| 2570 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2571 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2572 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2573 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2574 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2575 | self.waitUntilSettled() |
| 2576 | |
| 2577 | self.assertEqual(A.data['status'], 'NEW') |
| 2578 | self.assertEqual(A.reported, 0) |
| 2579 | |
| 2580 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2581 | 'SUCCESS') |
| 2582 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2583 | 'FAILURE') |
| 2584 | self.assertEqual(len(self.history), 2) |
| 2585 | |
| 2586 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2587 | self.commitConfigUpdate('common-config', |
| 2588 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2589 | self.sched.reconfigure(self.config) |
| 2590 | self.waitUntilSettled() |
| 2591 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2592 | self.executor_server.hold_jobs_in_build = False |
| 2593 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2594 | self.waitUntilSettled() |
| 2595 | |
| 2596 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2597 | 'SUCCESS') |
| 2598 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2599 | 'SUCCESS') |
| 2600 | self.assertEqual(len(self.history), 4) |
| 2601 | |
| 2602 | self.assertEqual(A.data['status'], 'NEW') |
| 2603 | self.assertEqual(A.reported, 1) |
| 2604 | self.assertIn('Build succeeded', A.messages[0]) |
| 2605 | # Ensure the removed job was not included in the report. |
| 2606 | self.assertNotIn('project-test1', A.messages[0]) |
| 2607 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2608 | def test_live_reconfiguration_shared_queue(self): |
| 2609 | # Test that a change with a failing job which was removed from |
| 2610 | # this project but otherwise still exists in the system does |
| 2611 | # not disrupt reconfiguration. |
| 2612 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2613 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2614 | |
| 2615 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2616 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2617 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2618 | |
| 2619 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2620 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2621 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2622 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2623 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2624 | self.waitUntilSettled() |
| 2625 | |
| 2626 | self.assertEqual(A.data['status'], 'NEW') |
| 2627 | self.assertEqual(A.reported, 0) |
| 2628 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2629 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2630 | 'SUCCESS') |
| 2631 | self.assertEqual(self.getJobFromHistory( |
| 2632 | 'project1-project2-integration').result, 'FAILURE') |
| 2633 | self.assertEqual(len(self.history), 2) |
| 2634 | |
| 2635 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2636 | self.commitConfigUpdate( |
| 2637 | 'common-config', |
| 2638 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2639 | self.sched.reconfigure(self.config) |
| 2640 | self.waitUntilSettled() |
| 2641 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2642 | self.executor_server.hold_jobs_in_build = False |
| 2643 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2644 | self.waitUntilSettled() |
| 2645 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2646 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2647 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2648 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2649 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2650 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2651 | 'SUCCESS') |
| 2652 | self.assertEqual(self.getJobFromHistory( |
| 2653 | 'project1-project2-integration').result, 'FAILURE') |
| 2654 | self.assertEqual(len(self.history), 4) |
| 2655 | |
| 2656 | self.assertEqual(A.data['status'], 'NEW') |
| 2657 | self.assertEqual(A.reported, 1) |
| 2658 | self.assertIn('Build succeeded', A.messages[0]) |
| 2659 | # Ensure the removed job was not included in the report. |
| 2660 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2661 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2662 | def test_double_live_reconfiguration_shared_queue(self): |
| 2663 | # This was a real-world regression. A change is added to |
| 2664 | # gate; a reconfigure happens, a second change which depends |
| 2665 | # on the first is added, and a second reconfiguration happens. |
| 2666 | # Ensure that both changes merge. |
| 2667 | |
| 2668 | # A failure may indicate incorrect caching or cleaning up of |
| 2669 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2670 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2671 | |
| 2672 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2673 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2674 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2675 | A.addApproval('Code-Review', 2) |
| 2676 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2677 | |
| 2678 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2679 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2680 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2681 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2682 | self.waitUntilSettled() |
| 2683 | |
| 2684 | # Reconfigure (with only one change in the pipeline). |
| 2685 | self.sched.reconfigure(self.config) |
| 2686 | self.waitUntilSettled() |
| 2687 | |
| 2688 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2689 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2690 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2691 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2692 | self.waitUntilSettled() |
| 2693 | |
| 2694 | # Reconfigure (with both in the pipeline). |
| 2695 | self.sched.reconfigure(self.config) |
| 2696 | self.waitUntilSettled() |
| 2697 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2698 | self.executor_server.hold_jobs_in_build = False |
| 2699 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2700 | self.waitUntilSettled() |
| 2701 | |
| 2702 | self.assertEqual(len(self.history), 8) |
| 2703 | |
| 2704 | self.assertEqual(A.data['status'], 'MERGED') |
| 2705 | self.assertEqual(A.reported, 2) |
| 2706 | self.assertEqual(B.data['status'], 'MERGED') |
| 2707 | self.assertEqual(B.reported, 2) |
| 2708 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2709 | def test_live_reconfiguration_del_project(self): |
| 2710 | # Test project deletion from layout |
| 2711 | # while changes are enqueued |
| 2712 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2713 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2714 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2715 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2716 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2717 | |
| 2718 | # A Depends-On: B |
| 2719 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2720 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2721 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2722 | |
| 2723 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2724 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2725 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2726 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2727 | self.waitUntilSettled() |
| 2728 | self.assertEqual(len(self.builds), 5) |
| 2729 | |
| 2730 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2731 | self.commitConfigUpdate( |
| 2732 | 'common-config', |
| 2733 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2734 | self.sched.reconfigure(self.config) |
| 2735 | self.waitUntilSettled() |
| 2736 | |
| 2737 | # Builds for C aborted, builds for A succeed, |
| 2738 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2739 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2740 | self.assertEqual(job_c.changes, '3,1') |
| 2741 | self.assertEqual(job_c.result, 'ABORTED') |
| 2742 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2743 | self.executor_server.hold_jobs_in_build = False |
| 2744 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2745 | self.waitUntilSettled() |
| 2746 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2747 | self.assertEqual( |
| 2748 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2749 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2750 | |
| 2751 | self.assertEqual(A.data['status'], 'NEW') |
| 2752 | self.assertEqual(B.data['status'], 'NEW') |
| 2753 | self.assertEqual(C.data['status'], 'NEW') |
| 2754 | self.assertEqual(A.reported, 1) |
| 2755 | self.assertEqual(B.reported, 0) |
| 2756 | self.assertEqual(C.reported, 0) |
| 2757 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2758 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2759 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2760 | self.assertIn('Build succeeded', A.messages[0]) |
| 2761 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2762 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2763 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2764 | self.updateConfigLayout( |
| 2765 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2766 | self.sched.reconfigure(self.config) |
| 2767 | |
| 2768 | self.init_repo("org/new-project") |
| 2769 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2770 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2771 | A.addApproval('Code-Review', 2) |
| 2772 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2773 | self.waitUntilSettled() |
| 2774 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2775 | 'SUCCESS') |
| 2776 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2777 | 'SUCCESS') |
| 2778 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2779 | 'SUCCESS') |
| 2780 | self.assertEqual(A.data['status'], 'MERGED') |
| 2781 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2782 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2783 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2784 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2785 | self.init_repo("org/delete-project") |
| 2786 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2787 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2788 | A.addApproval('Code-Review', 2) |
| 2789 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2790 | self.waitUntilSettled() |
| 2791 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2792 | 'SUCCESS') |
| 2793 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2794 | 'SUCCESS') |
| 2795 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2796 | 'SUCCESS') |
| 2797 | self.assertEqual(A.data['status'], 'MERGED') |
| 2798 | self.assertEqual(A.reported, 2) |
| 2799 | |
| 2800 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2801 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2802 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2803 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2804 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2805 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2806 | |
| 2807 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2808 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2809 | B.addApproval('Code-Review', 2) |
| 2810 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2811 | self.waitUntilSettled() |
| 2812 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2813 | 'SUCCESS') |
| 2814 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2815 | 'SUCCESS') |
| 2816 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2817 | 'SUCCESS') |
| 2818 | self.assertEqual(B.data['status'], 'MERGED') |
| 2819 | self.assertEqual(B.reported, 2) |
| 2820 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 2821 | @simple_layout('layouts/untrusted-secrets.yaml') |
| 2822 | def test_untrusted_secrets(self): |
| 2823 | "Test untrusted secrets" |
| 2824 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2825 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2826 | self.waitUntilSettled() |
| 2827 | |
| 2828 | self.assertHistory([]) |
| 2829 | self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") |
| 2830 | self.assertIn('does not allow jobs with secrets', |
| 2831 | A.messages[0]) |
| 2832 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2833 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2834 | def test_tags(self): |
| 2835 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2836 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2837 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2838 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2839 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2840 | self.waitUntilSettled() |
| 2841 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2842 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2843 | |
| 2844 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2845 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2846 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2847 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2848 | |
| 2849 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2850 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2851 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2852 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2853 | def test_timer(self): |
| 2854 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2855 | # This test can not use simple_layout because it must start |
| 2856 | # with a configuration which does not include a |
| 2857 | # timer-triggered job so that we have an opportunity to set |
| 2858 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2859 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2860 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2861 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2862 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2863 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2864 | # The pipeline triggers every second, so we should have seen |
| 2865 | # several by now. |
| 2866 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2867 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2868 | |
| 2869 | self.assertEqual(len(self.builds), 2) |
| 2870 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2871 | port = self.webapp.server.socket.getsockname()[1] |
| 2872 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2873 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2874 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2875 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2876 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2877 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2878 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2879 | # Stop queuing timer triggered jobs so that the assertions |
| 2880 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2881 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2882 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2883 | self.waitUntilSettled() |
| 2884 | # If APScheduler is in mid-event when we remove the job, we |
| 2885 | # can end up with one more event firing, so give it an extra |
| 2886 | # second to settle. |
| 2887 | time.sleep(1) |
| 2888 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2889 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2890 | self.waitUntilSettled() |
| 2891 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2892 | self.assertHistory([ |
| 2893 | dict(name='project-bitrot', result='SUCCESS', |
| 2894 | ref='refs/heads/master'), |
| 2895 | dict(name='project-bitrot', result='SUCCESS', |
| 2896 | ref='refs/heads/stable'), |
| 2897 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2898 | |
| 2899 | data = json.loads(data) |
| 2900 | status_jobs = set() |
| 2901 | for p in data['pipelines']: |
| 2902 | for q in p['change_queues']: |
| 2903 | for head in q['heads']: |
| 2904 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2905 | for job in change['jobs']: |
| 2906 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2907 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2908 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2909 | def test_idle(self): |
| 2910 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2911 | # This test can not use simple_layout because it must start |
| 2912 | # with a configuration which does not include a |
| 2913 | # timer-triggered job so that we have an opportunity to set |
| 2914 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2915 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2916 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2917 | for x in range(1, 3): |
| 2918 | # Test that timer triggers periodic jobs even across |
| 2919 | # layout config reloads. |
| 2920 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2921 | self.commitConfigUpdate('common-config', |
| 2922 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2923 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2924 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2925 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2926 | # The pipeline triggers every second, so we should have seen |
| 2927 | # several by now. |
| 2928 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2929 | |
| 2930 | # Stop queuing timer triggered jobs so that the assertions |
| 2931 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2932 | self.commitConfigUpdate('common-config', |
| 2933 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2934 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2935 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2936 | # If APScheduler is in mid-event when we remove the job, |
| 2937 | # we can end up with one more event firing, so give it an |
| 2938 | # extra second to settle. |
| 2939 | time.sleep(1) |
| 2940 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2941 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2942 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2943 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2944 | self.waitUntilSettled() |
| 2945 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2946 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2947 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2948 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2949 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2950 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2951 | self.waitUntilSettled() |
| 2952 | |
| 2953 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2954 | self.waitUntilSettled() |
| 2955 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2956 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2957 | |
| 2958 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2959 | # work on the knowledge of what the first message should be as |
| 2960 | # it is only configured to go to SMTP. |
| 2961 | |
| 2962 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2963 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2964 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2965 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2966 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2967 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2968 | |
| 2969 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2970 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2971 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2972 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2973 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2974 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2975 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2976 | def test_timer_smtp(self): |
| 2977 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2978 | # This test can not use simple_layout because it must start |
| 2979 | # with a configuration which does not include a |
| 2980 | # timer-triggered job so that we have an opportunity to set |
| 2981 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2982 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2983 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2984 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2985 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2986 | # The pipeline triggers every second, so we should have seen |
| 2987 | # several by now. |
| 2988 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2989 | self.waitUntilSettled() |
| 2990 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2991 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2992 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2993 | self.waitUntilSettled() |
| 2994 | self.assertEqual(len(self.history), 2) |
| 2995 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2996 | self.assertEqual(self.getJobFromHistory( |
| 2997 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2998 | self.assertEqual(self.getJobFromHistory( |
| 2999 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3000 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3001 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3002 | |
| 3003 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3004 | # work on the knowledge of what the first message should be as |
| 3005 | # it is only configured to go to SMTP. |
| 3006 | |
| 3007 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3008 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3009 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3010 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3011 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3012 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3013 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3014 | # Stop queuing timer triggered jobs and let any that may have |
| 3015 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3016 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3017 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3018 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3019 | # If APScheduler is in mid-event when we remove the job, we |
| 3020 | # can end up with one more event firing, so give it an extra |
| 3021 | # second to settle. |
| 3022 | time.sleep(1) |
| 3023 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3024 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3025 | self.waitUntilSettled() |
| 3026 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3027 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3028 | def test_timer_sshkey(self): |
| 3029 | "Test that a periodic job can setup SSH key authentication" |
| 3030 | self.worker.hold_jobs_in_build = True |
| 3031 | self.config.set('zuul', 'layout_config', |
| 3032 | 'tests/fixtures/layout-timer.yaml') |
| 3033 | self.sched.reconfigure(self.config) |
| 3034 | self.registerJobs() |
| 3035 | |
| 3036 | # The pipeline triggers every second, so we should have seen |
| 3037 | # several by now. |
| 3038 | time.sleep(5) |
| 3039 | self.waitUntilSettled() |
| 3040 | |
| 3041 | self.assertEqual(len(self.builds), 2) |
| 3042 | |
| 3043 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3044 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3045 | with open(ssh_wrapper) as f: |
| 3046 | ssh_wrapper_content = f.read() |
| 3047 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3048 | # In the unit tests Merger runs in the same process, |
| 3049 | # so we see its' environment variables |
| 3050 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3051 | |
| 3052 | self.worker.release('.*') |
| 3053 | self.waitUntilSettled() |
| 3054 | self.assertEqual(len(self.history), 2) |
| 3055 | |
| 3056 | self.assertEqual(self.getJobFromHistory( |
| 3057 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3058 | self.assertEqual(self.getJobFromHistory( |
| 3059 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3060 | |
| 3061 | # Stop queuing timer triggered jobs and let any that may have |
| 3062 | # queued through so that end of test assertions pass. |
| 3063 | self.config.set('zuul', 'layout_config', |
| 3064 | 'tests/fixtures/layout-no-timer.yaml') |
| 3065 | self.sched.reconfigure(self.config) |
| 3066 | self.registerJobs() |
| 3067 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3068 | # If APScheduler is in mid-event when we remove the job, we |
| 3069 | # can end up with one more event firing, so give it an extra |
| 3070 | # second to settle. |
| 3071 | time.sleep(1) |
| 3072 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3073 | self.worker.release('.*') |
| 3074 | self.waitUntilSettled() |
| 3075 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3076 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3077 | "Test that the RPC client can enqueue a change" |
| 3078 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3079 | A.addApproval('Code-Review', 2) |
| 3080 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3081 | |
| 3082 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3083 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3084 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3085 | r = client.enqueue(tenant='tenant-one', |
| 3086 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3087 | project='org/project', |
| 3088 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3089 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3090 | self.waitUntilSettled() |
| 3091 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3092 | 'SUCCESS') |
| 3093 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3094 | 'SUCCESS') |
| 3095 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3096 | 'SUCCESS') |
| 3097 | self.assertEqual(A.data['status'], 'MERGED') |
| 3098 | self.assertEqual(A.reported, 2) |
| 3099 | self.assertEqual(r, True) |
| 3100 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3101 | def test_client_enqueue_ref(self): |
| 3102 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3103 | p = "review.example.com/org/project" |
| 3104 | upstream = self.getUpstreamRepos([p]) |
| 3105 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3106 | A.setMerged() |
| 3107 | A_commit = str(upstream[p].commit('master')) |
| 3108 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3109 | |
| 3110 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3111 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3112 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3113 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3114 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3115 | pipeline='post', |
| 3116 | project='org/project', |
| 3117 | trigger='gerrit', |
| 3118 | ref='master', |
| 3119 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3120 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3121 | self.waitUntilSettled() |
| 3122 | job_names = [x.name for x in self.history] |
| 3123 | self.assertEqual(len(self.history), 1) |
| 3124 | self.assertIn('project-post', job_names) |
| 3125 | self.assertEqual(r, True) |
| 3126 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3127 | def test_client_enqueue_negative(self): |
| 3128 | "Test that the RPC client returns errors" |
| 3129 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3130 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3131 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3132 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3133 | "Invalid tenant"): |
| 3134 | r = client.enqueue(tenant='tenant-foo', |
| 3135 | pipeline='gate', |
| 3136 | project='org/project', |
| 3137 | trigger='gerrit', |
| 3138 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3139 | self.assertEqual(r, False) |
| 3140 | |
| 3141 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3142 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3143 | r = client.enqueue(tenant='tenant-one', |
| 3144 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3145 | project='project-does-not-exist', |
| 3146 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3147 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3148 | self.assertEqual(r, False) |
| 3149 | |
| 3150 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3151 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3152 | r = client.enqueue(tenant='tenant-one', |
| 3153 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3154 | project='org/project', |
| 3155 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3156 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3157 | self.assertEqual(r, False) |
| 3158 | |
| 3159 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3160 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3161 | r = client.enqueue(tenant='tenant-one', |
| 3162 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3163 | project='org/project', |
| 3164 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3165 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3166 | self.assertEqual(r, False) |
| 3167 | |
| 3168 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3169 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3170 | r = client.enqueue(tenant='tenant-one', |
| 3171 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3172 | project='org/project', |
| 3173 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3174 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3175 | self.assertEqual(r, False) |
| 3176 | |
| 3177 | self.waitUntilSettled() |
| 3178 | self.assertEqual(len(self.history), 0) |
| 3179 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3180 | |
| 3181 | def test_client_promote(self): |
| 3182 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3183 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3184 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3185 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3186 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3187 | A.addApproval('Code-Review', 2) |
| 3188 | B.addApproval('Code-Review', 2) |
| 3189 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3190 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3191 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3192 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3193 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3194 | |
| 3195 | self.waitUntilSettled() |
| 3196 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3197 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3198 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3199 | enqueue_times = {} |
| 3200 | for item in items: |
| 3201 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3202 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3203 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3204 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3205 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | r = client.promote(tenant='tenant-one', |
| 3207 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3208 | change_ids=['2,1', '3,1']) |
| 3209 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3210 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3211 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3212 | for item in items: |
| 3213 | self.assertEqual( |
| 3214 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3215 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3216 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3217 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3218 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3219 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3220 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3221 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3222 | self.waitUntilSettled() |
| 3223 | |
| 3224 | self.assertEqual(len(self.builds), 6) |
| 3225 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3226 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3227 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3228 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3229 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3230 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3231 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3232 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3233 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3234 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3235 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3236 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3237 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3238 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3239 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3240 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3241 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3242 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3243 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3244 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3245 | self.waitUntilSettled() |
| 3246 | |
| 3247 | self.assertEqual(A.data['status'], 'MERGED') |
| 3248 | self.assertEqual(A.reported, 2) |
| 3249 | self.assertEqual(B.data['status'], 'MERGED') |
| 3250 | self.assertEqual(B.reported, 2) |
| 3251 | self.assertEqual(C.data['status'], 'MERGED') |
| 3252 | self.assertEqual(C.reported, 2) |
| 3253 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3254 | self.assertEqual(r, True) |
| 3255 | |
| 3256 | def test_client_promote_dependent(self): |
| 3257 | "Test that the RPC client can promote a dependent change" |
| 3258 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3259 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3260 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3261 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3262 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3263 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3264 | |
| 3265 | C.setDependsOn(B, 1) |
| 3266 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3267 | A.addApproval('Code-Review', 2) |
| 3268 | B.addApproval('Code-Review', 2) |
| 3269 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3270 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3271 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3272 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3273 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3274 | |
| 3275 | self.waitUntilSettled() |
| 3276 | |
| 3277 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3278 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3279 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3280 | r = client.promote(tenant='tenant-one', |
| 3281 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3282 | change_ids=['3,1']) |
| 3283 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3284 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3285 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3286 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3287 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3288 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3289 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3290 | self.waitUntilSettled() |
| 3291 | |
| 3292 | self.assertEqual(len(self.builds), 6) |
| 3293 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3294 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3295 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3296 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3297 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3298 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3299 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3300 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3301 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3302 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3303 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3304 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3305 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3306 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3307 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3308 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3309 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3310 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3311 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3312 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3313 | self.waitUntilSettled() |
| 3314 | |
| 3315 | self.assertEqual(A.data['status'], 'MERGED') |
| 3316 | self.assertEqual(A.reported, 2) |
| 3317 | self.assertEqual(B.data['status'], 'MERGED') |
| 3318 | self.assertEqual(B.reported, 2) |
| 3319 | self.assertEqual(C.data['status'], 'MERGED') |
| 3320 | self.assertEqual(C.reported, 2) |
| 3321 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3322 | self.assertEqual(r, True) |
| 3323 | |
| 3324 | def test_client_promote_negative(self): |
| 3325 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3326 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3327 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3328 | A.addApproval('Code-Review', 2) |
| 3329 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3330 | self.waitUntilSettled() |
| 3331 | |
| 3332 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3333 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3334 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3335 | |
| 3336 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3337 | r = client.promote(tenant='tenant-one', |
| 3338 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3339 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3340 | self.assertEqual(r, False) |
| 3341 | |
| 3342 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3343 | r = client.promote(tenant='tenant-one', |
| 3344 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3345 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3346 | self.assertEqual(r, False) |
| 3347 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3348 | self.executor_server.hold_jobs_in_build = False |
| 3349 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3350 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3351 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3352 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3353 | def test_queue_rate_limiting(self): |
| 3354 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3355 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3356 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3357 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3358 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3359 | |
| 3360 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3361 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3362 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3363 | A.addApproval('Code-Review', 2) |
| 3364 | B.addApproval('Code-Review', 2) |
| 3365 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3366 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3367 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3368 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3369 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | # Only A and B will have their merge jobs queued because |
| 3373 | # window is 2. |
| 3374 | self.assertEqual(len(self.builds), 2) |
| 3375 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3376 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3377 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3378 | # Release the merge jobs one at a time. |
| 3379 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3380 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3381 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3382 | self.waitUntilSettled() |
| 3383 | |
| 3384 | # Only A and B will have their test jobs queued because |
| 3385 | # window is 2. |
| 3386 | self.assertEqual(len(self.builds), 4) |
| 3387 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3388 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3389 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3390 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3391 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3392 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3393 | self.waitUntilSettled() |
| 3394 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3395 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3396 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3397 | # A failed so window is reduced by 1 to 1. |
| 3398 | self.assertEqual(queue.window, 1) |
| 3399 | self.assertEqual(queue.window_floor, 1) |
| 3400 | self.assertEqual(A.data['status'], 'NEW') |
| 3401 | |
| 3402 | # Gate is reset and only B's merge job is queued because |
| 3403 | # window shrunk to 1. |
| 3404 | self.assertEqual(len(self.builds), 1) |
| 3405 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3406 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3407 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3408 | self.waitUntilSettled() |
| 3409 | |
| 3410 | # Only B's test jobs are queued because window is still 1. |
| 3411 | self.assertEqual(len(self.builds), 2) |
| 3412 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3413 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3414 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3415 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3416 | self.waitUntilSettled() |
| 3417 | |
| 3418 | # B was successfully merged so window is increased to 2. |
| 3419 | self.assertEqual(queue.window, 2) |
| 3420 | self.assertEqual(queue.window_floor, 1) |
| 3421 | self.assertEqual(B.data['status'], 'MERGED') |
| 3422 | |
| 3423 | # Only C is left and its merge job is queued. |
| 3424 | self.assertEqual(len(self.builds), 1) |
| 3425 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3426 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3427 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3428 | self.waitUntilSettled() |
| 3429 | |
| 3430 | # After successful merge job the test jobs for C are queued. |
| 3431 | self.assertEqual(len(self.builds), 2) |
| 3432 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3433 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3434 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3435 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3436 | self.waitUntilSettled() |
| 3437 | |
| 3438 | # C successfully merged so window is bumped to 3. |
| 3439 | self.assertEqual(queue.window, 3) |
| 3440 | self.assertEqual(queue.window_floor, 1) |
| 3441 | self.assertEqual(C.data['status'], 'MERGED') |
| 3442 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3443 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3444 | def test_queue_rate_limiting_dependent(self): |
| 3445 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3446 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3447 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3448 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3449 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3450 | |
| 3451 | B.setDependsOn(A, 1) |
| 3452 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3453 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3454 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3455 | A.addApproval('Code-Review', 2) |
| 3456 | B.addApproval('Code-Review', 2) |
| 3457 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3458 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3459 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3460 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3461 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3462 | self.waitUntilSettled() |
| 3463 | |
| 3464 | # Only A and B will have their merge jobs queued because |
| 3465 | # window is 2. |
| 3466 | self.assertEqual(len(self.builds), 2) |
| 3467 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3468 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3469 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3470 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3471 | |
| 3472 | # Only A and B will have their test jobs queued because |
| 3473 | # window is 2. |
| 3474 | self.assertEqual(len(self.builds), 4) |
| 3475 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3476 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3477 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3478 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3479 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3480 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3481 | self.waitUntilSettled() |
| 3482 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3483 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3484 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | # A failed so window is reduced by 1 to 1. |
| 3486 | self.assertEqual(queue.window, 1) |
| 3487 | self.assertEqual(queue.window_floor, 1) |
| 3488 | self.assertEqual(A.data['status'], 'NEW') |
| 3489 | self.assertEqual(B.data['status'], 'NEW') |
| 3490 | |
| 3491 | # Gate is reset and only C's merge job is queued because |
| 3492 | # window shrunk to 1 and A and B were dequeued. |
| 3493 | self.assertEqual(len(self.builds), 1) |
| 3494 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3495 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3496 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3497 | |
| 3498 | # Only C's test jobs are queued because window is still 1. |
| 3499 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3500 | builds = self.getSortedBuilds() |
| 3501 | self.assertEqual(builds[0].name, 'project-test1') |
| 3502 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3503 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3504 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3505 | self.waitUntilSettled() |
| 3506 | |
| 3507 | # C was successfully merged so window is increased to 2. |
| 3508 | self.assertEqual(queue.window, 2) |
| 3509 | self.assertEqual(queue.window_floor, 1) |
| 3510 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3511 | |
| 3512 | def test_worker_update_metadata(self): |
| 3513 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3514 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3515 | |
| 3516 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3517 | A.addApproval('Code-Review', 2) |
| 3518 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3519 | self.waitUntilSettled() |
| 3520 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3521 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3522 | |
| 3523 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3524 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3525 | |
| 3526 | start = time.time() |
| 3527 | while True: |
| 3528 | if time.time() - start > 10: |
| 3529 | raise Exception("Timeout waiting for gearman server to report " |
| 3530 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3531 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3532 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3533 | break |
| 3534 | else: |
| 3535 | time.sleep(0) |
| 3536 | |
| 3537 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3538 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3539 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3540 | self.executor_server.hold_jobs_in_build = False |
| 3541 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3542 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3543 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3544 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3545 | def test_footer_message(self): |
| 3546 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3547 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3548 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3549 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3550 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3551 | self.waitUntilSettled() |
| 3552 | |
| 3553 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3554 | B.addApproval('Code-Review', 2) |
| 3555 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3556 | self.waitUntilSettled() |
| 3557 | |
| 3558 | self.assertEqual(2, len(self.smtp_messages)) |
| 3559 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3560 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3561 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3562 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3563 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3564 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3565 | For CI problems and help debugging, contact ci@example.org""" |
| 3566 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3567 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3568 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3569 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3570 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3571 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3572 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3573 | def test_unmanaged_project_start_message(self): |
| 3574 | "Test start reporting is not done for unmanaged projects." |
| 3575 | self.init_repo("org/project", tag='init') |
| 3576 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3577 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3578 | self.waitUntilSettled() |
| 3579 | |
| 3580 | self.assertEqual(0, len(A.messages)) |
| 3581 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3582 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3583 | def test_merge_failure_reporters(self): |
| 3584 | """Check that the config is set up correctly""" |
| 3585 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3586 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3587 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3588 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3589 | "dependencies was unable to be automatically merged with the " |
| 3590 | "current state of its repository. Please rebase the change and " |
| 3591 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3592 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3593 | self.assertEqual( |
| 3594 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3595 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3596 | |
| 3597 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3598 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3599 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3600 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3601 | |
| 3602 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3603 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3604 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3605 | |
| 3606 | self.assertTrue( |
| 3607 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3608 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3609 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3610 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3611 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3612 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3613 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3614 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3615 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3616 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3617 | gerritreporter.GerritReporter) and |
| 3618 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3619 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3620 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3621 | ) |
| 3622 | ) |
| 3623 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3624 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3625 | def test_merge_failure_reports(self): |
| 3626 | """Check that when a change fails to merge the correct message is sent |
| 3627 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3628 | self.updateConfigLayout( |
| 3629 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3630 | self.sched.reconfigure(self.config) |
| 3631 | self.registerJobs() |
| 3632 | |
| 3633 | # Check a test failure isn't reported to SMTP |
| 3634 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3635 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3636 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3637 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3638 | self.waitUntilSettled() |
| 3639 | |
| 3640 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3641 | self.assertEqual(0, len(self.smtp_messages)) |
| 3642 | |
| 3643 | # Check a merge failure is reported to SMTP |
| 3644 | # B should be merged, but C will conflict with B |
| 3645 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3646 | B.addPatchset(['conflict']) |
| 3647 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3648 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3649 | B.addApproval('Code-Review', 2) |
| 3650 | C.addApproval('Code-Review', 2) |
| 3651 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3652 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3653 | self.waitUntilSettled() |
| 3654 | |
| 3655 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3656 | self.assertEqual(1, len(self.smtp_messages)) |
| 3657 | self.assertEqual('The merge failed! For more information...', |
| 3658 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3659 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3660 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3661 | def test_default_merge_failure_reports(self): |
| 3662 | """Check that the default merge failure reports are correct.""" |
| 3663 | |
| 3664 | # A should report success, B should report merge failure. |
| 3665 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3666 | A.addPatchset(['conflict']) |
| 3667 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3668 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3669 | A.addApproval('Code-Review', 2) |
| 3670 | B.addApproval('Code-Review', 2) |
| 3671 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3672 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3673 | self.waitUntilSettled() |
| 3674 | |
| 3675 | self.assertEqual(3, len(self.history)) # A jobs |
| 3676 | self.assertEqual(A.reported, 2) |
| 3677 | self.assertEqual(B.reported, 2) |
| 3678 | self.assertEqual(A.data['status'], 'MERGED') |
| 3679 | self.assertEqual(B.data['status'], 'NEW') |
| 3680 | self.assertIn('Build succeeded', A.messages[1]) |
| 3681 | self.assertIn('Merge Failed', B.messages[1]) |
| 3682 | self.assertIn('automatically merged', B.messages[1]) |
| 3683 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3684 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3685 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3686 | def test_client_get_running_jobs(self): |
| 3687 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3688 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3690 | A.addApproval('Code-Review', 2) |
| 3691 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3692 | self.waitUntilSettled() |
| 3693 | |
| 3694 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3695 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3696 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3697 | |
| 3698 | # Wait for gearman server to send the initial workData back to zuul |
| 3699 | start = time.time() |
| 3700 | while True: |
| 3701 | if time.time() - start > 10: |
| 3702 | raise Exception("Timeout waiting for gearman server to report " |
| 3703 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3704 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3705 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3706 | break |
| 3707 | else: |
| 3708 | time.sleep(0) |
| 3709 | |
| 3710 | running_items = client.get_running_jobs() |
| 3711 | |
| 3712 | self.assertEqual(1, len(running_items)) |
| 3713 | running_item = running_items[0] |
| 3714 | self.assertEqual([], running_item['failing_reasons']) |
| 3715 | self.assertEqual([], running_item['items_behind']) |
| 3716 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3717 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3718 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3719 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3720 | self.assertEqual(True, running_item['active']) |
| 3721 | self.assertEqual('1,1', running_item['id']) |
| 3722 | |
| 3723 | self.assertEqual(3, len(running_item['jobs'])) |
| 3724 | for job in running_item['jobs']: |
| 3725 | if job['name'] == 'project-merge': |
| 3726 | self.assertEqual('project-merge', job['name']) |
| 3727 | self.assertEqual('gate', job['pipeline']) |
| 3728 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3729 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3730 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3731 | .format(uuid=job['uuid']), job['url']) |
| 3732 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3733 | 'finger://{hostname}/{uuid}'.format( |
| 3734 | hostname=self.executor_server.hostname, |
| 3735 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3736 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3737 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3738 | self.assertEqual(False, job['canceled']) |
| 3739 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3740 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3741 | self.assertEqual('gate', job['pipeline']) |
| 3742 | break |
| 3743 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3744 | self.executor_server.hold_jobs_in_build = False |
| 3745 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3746 | self.waitUntilSettled() |
| 3747 | |
| 3748 | running_items = client.get_running_jobs() |
| 3749 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3750 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3751 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3752 | def test_nonvoting_pipeline(self): |
| 3753 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3754 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3755 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3756 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3757 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3758 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3759 | |
| 3760 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3761 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3762 | self.assertEqual( |
| 3763 | self.getJobFromHistory('experimental-project-test').result, |
| 3764 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3765 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3766 | |
| 3767 | def test_crd_gate(self): |
| 3768 | "Test cross-repo dependencies" |
| 3769 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3770 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3771 | A.addApproval('Code-Review', 2) |
| 3772 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3773 | |
| 3774 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3775 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3776 | AM2.setMerged() |
| 3777 | AM1.setMerged() |
| 3778 | |
| 3779 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3780 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3781 | BM2.setMerged() |
| 3782 | BM1.setMerged() |
| 3783 | |
| 3784 | # A -> AM1 -> AM2 |
| 3785 | # B -> BM1 -> BM2 |
| 3786 | # A Depends-On: B |
| 3787 | # M2 is here to make sure it is never queried. If it is, it |
| 3788 | # means zuul is walking down the entire history of merged |
| 3789 | # changes. |
| 3790 | |
| 3791 | B.setDependsOn(BM1, 1) |
| 3792 | BM1.setDependsOn(BM2, 1) |
| 3793 | |
| 3794 | A.setDependsOn(AM1, 1) |
| 3795 | AM1.setDependsOn(AM2, 1) |
| 3796 | |
| 3797 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3798 | A.subject, B.data['id']) |
| 3799 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3800 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3801 | self.waitUntilSettled() |
| 3802 | |
| 3803 | self.assertEqual(A.data['status'], 'NEW') |
| 3804 | self.assertEqual(B.data['status'], 'NEW') |
| 3805 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3806 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3807 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3808 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3809 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3810 | B.addApproval('Approved', 1) |
| 3811 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3812 | self.waitUntilSettled() |
| 3813 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3814 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3815 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3816 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3817 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3818 | self.executor_server.hold_jobs_in_build = False |
| 3819 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3820 | self.waitUntilSettled() |
| 3821 | |
| 3822 | self.assertEqual(AM2.queried, 0) |
| 3823 | self.assertEqual(BM2.queried, 0) |
| 3824 | self.assertEqual(A.data['status'], 'MERGED') |
| 3825 | self.assertEqual(B.data['status'], 'MERGED') |
| 3826 | self.assertEqual(A.reported, 2) |
| 3827 | self.assertEqual(B.reported, 2) |
| 3828 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3829 | changes = self.getJobFromHistory( |
| 3830 | 'project-merge', 'org/project1').changes |
| 3831 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3832 | |
| 3833 | def test_crd_branch(self): |
| 3834 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3835 | |
| 3836 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3837 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3838 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3839 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3840 | C.data['id'] = B.data['id'] |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3841 | A.addApproval('Code-Review', 2) |
| 3842 | B.addApproval('Code-Review', 2) |
| 3843 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3844 | |
| 3845 | # A Depends-On: B+C |
| 3846 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3847 | A.subject, B.data['id']) |
| 3848 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3849 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3850 | B.addApproval('Approved', 1) |
| 3851 | C.addApproval('Approved', 1) |
| 3852 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3853 | self.waitUntilSettled() |
| 3854 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3855 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3856 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3857 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3858 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3859 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3860 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3861 | self.executor_server.hold_jobs_in_build = False |
| 3862 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3863 | self.waitUntilSettled() |
| 3864 | |
| 3865 | self.assertEqual(A.data['status'], 'MERGED') |
| 3866 | self.assertEqual(B.data['status'], 'MERGED') |
| 3867 | self.assertEqual(C.data['status'], 'MERGED') |
| 3868 | self.assertEqual(A.reported, 2) |
| 3869 | self.assertEqual(B.reported, 2) |
| 3870 | self.assertEqual(C.reported, 2) |
| 3871 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3872 | changes = self.getJobFromHistory( |
| 3873 | 'project-merge', 'org/project1').changes |
| 3874 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3875 | |
| 3876 | def test_crd_multiline(self): |
| 3877 | "Test multiple depends-on lines in commit" |
| 3878 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3879 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3880 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3881 | A.addApproval('Code-Review', 2) |
| 3882 | B.addApproval('Code-Review', 2) |
| 3883 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3884 | |
| 3885 | # A Depends-On: B+C |
| 3886 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3887 | A.subject, B.data['id'], C.data['id']) |
| 3888 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3889 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3890 | B.addApproval('Approved', 1) |
| 3891 | C.addApproval('Approved', 1) |
| 3892 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3893 | self.waitUntilSettled() |
| 3894 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3895 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3896 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3897 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3898 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3899 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3900 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3901 | self.executor_server.hold_jobs_in_build = False |
| 3902 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3903 | self.waitUntilSettled() |
| 3904 | |
| 3905 | self.assertEqual(A.data['status'], 'MERGED') |
| 3906 | self.assertEqual(B.data['status'], 'MERGED') |
| 3907 | self.assertEqual(C.data['status'], 'MERGED') |
| 3908 | self.assertEqual(A.reported, 2) |
| 3909 | self.assertEqual(B.reported, 2) |
| 3910 | self.assertEqual(C.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 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3915 | |
| 3916 | def test_crd_unshared_gate(self): |
| 3917 | "Test cross-repo dependencies in unshared gate queues" |
| 3918 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3919 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [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 Depends-On: B |
| 3924 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3925 | A.subject, B.data['id']) |
| 3926 | |
| 3927 | # A and B do not share a queue, make sure that A is unable to |
| 3928 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3929 | B.addApproval('Approved', 1) |
| 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.data['status'], 'NEW') |
| 3934 | self.assertEqual(B.data['status'], 'NEW') |
| 3935 | self.assertEqual(A.reported, 0) |
| 3936 | self.assertEqual(B.reported, 0) |
| 3937 | self.assertEqual(len(self.history), 0) |
| 3938 | |
| 3939 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3940 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3941 | self.waitUntilSettled() |
| 3942 | |
| 3943 | self.assertEqual(B.data['status'], 'MERGED') |
| 3944 | self.assertEqual(B.reported, 2) |
| 3945 | |
| 3946 | # Now that B is merged, A should be able to be enqueued and |
| 3947 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3948 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3949 | self.waitUntilSettled() |
| 3950 | |
| 3951 | self.assertEqual(A.data['status'], 'MERGED') |
| 3952 | self.assertEqual(A.reported, 2) |
| 3953 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3954 | def test_crd_gate_reverse(self): |
| 3955 | "Test reverse cross-repo dependencies" |
| 3956 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3957 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3958 | A.addApproval('Code-Review', 2) |
| 3959 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3960 | |
| 3961 | # A Depends-On: B |
| 3962 | |
| 3963 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3964 | A.subject, B.data['id']) |
| 3965 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3966 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3967 | self.waitUntilSettled() |
| 3968 | |
| 3969 | self.assertEqual(A.data['status'], 'NEW') |
| 3970 | self.assertEqual(B.data['status'], 'NEW') |
| 3971 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3972 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3973 | A.addApproval('Approved', 1) |
| 3974 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3975 | self.waitUntilSettled() |
| 3976 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3977 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3978 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3979 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3980 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3981 | self.executor_server.hold_jobs_in_build = False |
| 3982 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3983 | self.waitUntilSettled() |
| 3984 | |
| 3985 | self.assertEqual(A.data['status'], 'MERGED') |
| 3986 | self.assertEqual(B.data['status'], 'MERGED') |
| 3987 | self.assertEqual(A.reported, 2) |
| 3988 | self.assertEqual(B.reported, 2) |
| 3989 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3990 | changes = self.getJobFromHistory( |
| 3991 | 'project-merge', 'org/project1').changes |
| 3992 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3993 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3994 | def test_crd_cycle(self): |
| 3995 | "Test cross-repo dependency cycles" |
| 3996 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3997 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3998 | A.addApproval('Code-Review', 2) |
| 3999 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4000 | |
| 4001 | # A -> B -> A (via commit-depends) |
| 4002 | |
| 4003 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4004 | A.subject, B.data['id']) |
| 4005 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4006 | B.subject, A.data['id']) |
| 4007 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4008 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4009 | self.waitUntilSettled() |
| 4010 | |
| 4011 | self.assertEqual(A.reported, 0) |
| 4012 | self.assertEqual(B.reported, 0) |
| 4013 | self.assertEqual(A.data['status'], 'NEW') |
| 4014 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4015 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4016 | def test_crd_gate_unknown(self): |
| 4017 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4018 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4019 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4020 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4021 | A.addApproval('Code-Review', 2) |
| 4022 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4023 | |
| 4024 | # A Depends-On: B |
| 4025 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4026 | A.subject, B.data['id']) |
| 4027 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4028 | B.addApproval('Approved', 1) |
| 4029 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4030 | self.waitUntilSettled() |
| 4031 | |
| 4032 | # Unknown projects cannot share a queue with any other |
| 4033 | # since they don't have common jobs with any other (they have no jobs). |
| 4034 | # Changes which depend on unknown project changes |
| 4035 | # should not be processed in dependent pipeline |
| 4036 | self.assertEqual(A.data['status'], 'NEW') |
| 4037 | self.assertEqual(B.data['status'], 'NEW') |
| 4038 | self.assertEqual(A.reported, 0) |
| 4039 | self.assertEqual(B.reported, 0) |
| 4040 | self.assertEqual(len(self.history), 0) |
| 4041 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4042 | # Simulate change B being gated outside this layout Set the |
| 4043 | # change merged before submitting the event so that when the |
| 4044 | # event triggers a gerrit query to update the change, we get |
| 4045 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4046 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4047 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4048 | self.waitUntilSettled() |
| 4049 | self.assertEqual(len(self.history), 0) |
| 4050 | |
| 4051 | # Now that B is merged, A should be able to be enqueued and |
| 4052 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4053 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4054 | self.waitUntilSettled() |
| 4055 | |
| 4056 | self.assertEqual(A.data['status'], 'MERGED') |
| 4057 | self.assertEqual(A.reported, 2) |
| 4058 | self.assertEqual(B.data['status'], 'MERGED') |
| 4059 | self.assertEqual(B.reported, 0) |
| 4060 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4061 | def test_crd_check(self): |
| 4062 | "Test cross-repo dependencies in independent pipelines" |
| 4063 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4064 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4065 | self.gearman_server.hold_jobs_in_queue = True |
| 4066 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4067 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4068 | |
| 4069 | # A Depends-On: B |
| 4070 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4071 | A.subject, B.data['id']) |
| 4072 | |
| 4073 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4074 | self.waitUntilSettled() |
| 4075 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4076 | self.gearman_server.hold_jobs_in_queue = False |
| 4077 | self.gearman_server.release() |
| 4078 | self.waitUntilSettled() |
| 4079 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4080 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4081 | self.waitUntilSettled() |
| 4082 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4083 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4084 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4085 | self.executor_server.hold_jobs_in_build = False |
| 4086 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4087 | self.waitUntilSettled() |
| 4088 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4089 | self.assertEqual(A.data['status'], 'NEW') |
| 4090 | self.assertEqual(B.data['status'], 'NEW') |
| 4091 | self.assertEqual(A.reported, 1) |
| 4092 | self.assertEqual(B.reported, 0) |
| 4093 | |
| 4094 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4095 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4096 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4097 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4098 | def test_crd_check_git_depends(self): |
| 4099 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4100 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4101 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4102 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4103 | |
| 4104 | # Add two git-dependent changes and make sure they both report |
| 4105 | # success. |
| 4106 | B.setDependsOn(A, 1) |
| 4107 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4108 | self.waitUntilSettled() |
| 4109 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4110 | self.waitUntilSettled() |
| 4111 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4112 | self.orderedRelease() |
| 4113 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4114 | self.waitUntilSettled() |
| 4115 | |
| 4116 | self.assertEqual(A.data['status'], 'NEW') |
| 4117 | self.assertEqual(B.data['status'], 'NEW') |
| 4118 | self.assertEqual(A.reported, 1) |
| 4119 | self.assertEqual(B.reported, 1) |
| 4120 | |
| 4121 | self.assertEqual(self.history[0].changes, '1,1') |
| 4122 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4123 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4124 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4125 | |
| 4126 | self.assertIn('Build succeeded', A.messages[0]) |
| 4127 | self.assertIn('Build succeeded', B.messages[0]) |
| 4128 | |
| 4129 | def test_crd_check_duplicate(self): |
| 4130 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4131 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4132 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4133 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4134 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4135 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4136 | |
| 4137 | # Add two git-dependent changes... |
| 4138 | B.setDependsOn(A, 1) |
| 4139 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4140 | self.waitUntilSettled() |
| 4141 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4142 | |
| 4143 | # ...make sure the live one is not duplicated... |
| 4144 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4145 | self.waitUntilSettled() |
| 4146 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4147 | |
| 4148 | # ...but the non-live one is able to be. |
| 4149 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4150 | self.waitUntilSettled() |
| 4151 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4152 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4153 | # Release jobs in order to avoid races with change A jobs |
| 4154 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4155 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4156 | self.executor_server.hold_jobs_in_build = False |
| 4157 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4158 | self.waitUntilSettled() |
| 4159 | |
| 4160 | self.assertEqual(A.data['status'], 'NEW') |
| 4161 | self.assertEqual(B.data['status'], 'NEW') |
| 4162 | self.assertEqual(A.reported, 1) |
| 4163 | self.assertEqual(B.reported, 1) |
| 4164 | |
| 4165 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4166 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4167 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4168 | |
| 4169 | self.assertIn('Build succeeded', A.messages[0]) |
| 4170 | self.assertIn('Build succeeded', B.messages[0]) |
| 4171 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4172 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4173 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4174 | |
| 4175 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4176 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4177 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4178 | |
| 4179 | # A Depends-On: B |
| 4180 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4181 | A.subject, B.data['id']) |
| 4182 | |
| 4183 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4184 | self.waitUntilSettled() |
| 4185 | |
| 4186 | self.sched.reconfigure(self.config) |
| 4187 | |
| 4188 | # Make sure the items still share a change queue, and the |
| 4189 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4190 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4191 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4192 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4193 | first_item = queue.queue[0] |
| 4194 | for item in queue.queue: |
| 4195 | self.assertEqual(item.queue, first_item.queue) |
| 4196 | self.assertFalse(first_item.live) |
| 4197 | self.assertTrue(queue.queue[1].live) |
| 4198 | |
| 4199 | self.gearman_server.hold_jobs_in_queue = False |
| 4200 | self.gearman_server.release() |
| 4201 | self.waitUntilSettled() |
| 4202 | |
| 4203 | self.assertEqual(A.data['status'], 'NEW') |
| 4204 | self.assertEqual(B.data['status'], 'NEW') |
| 4205 | self.assertEqual(A.reported, 1) |
| 4206 | self.assertEqual(B.reported, 0) |
| 4207 | |
| 4208 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4209 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4210 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4211 | def test_crd_check_reconfiguration(self): |
| 4212 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4213 | |
| 4214 | def test_crd_undefined_project(self): |
| 4215 | """Test that undefined projects in dependencies are handled for |
| 4216 | independent pipelines""" |
| 4217 | # It's a hack for fake gerrit, |
| 4218 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4219 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4220 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4221 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4222 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4223 | def test_crd_check_ignore_dependencies(self): |
| 4224 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4225 | |
| 4226 | self.gearman_server.hold_jobs_in_queue = True |
| 4227 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4228 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4229 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4230 | |
| 4231 | # A Depends-On: B |
| 4232 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4233 | A.subject, B.data['id']) |
| 4234 | # C git-depends on B |
| 4235 | C.setDependsOn(B, 1) |
| 4236 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4237 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4238 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4239 | self.waitUntilSettled() |
| 4240 | |
| 4241 | # Make sure none of the items share a change queue, and all |
| 4242 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4243 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4244 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4245 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4246 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4247 | for item in check_pipeline.getAllItems(): |
| 4248 | self.assertTrue(item.live) |
| 4249 | |
| 4250 | self.gearman_server.hold_jobs_in_queue = False |
| 4251 | self.gearman_server.release() |
| 4252 | self.waitUntilSettled() |
| 4253 | |
| 4254 | self.assertEqual(A.data['status'], 'NEW') |
| 4255 | self.assertEqual(B.data['status'], 'NEW') |
| 4256 | self.assertEqual(C.data['status'], 'NEW') |
| 4257 | self.assertEqual(A.reported, 1) |
| 4258 | self.assertEqual(B.reported, 1) |
| 4259 | self.assertEqual(C.reported, 1) |
| 4260 | |
| 4261 | # Each job should have tested exactly one change |
| 4262 | for job in self.history: |
| 4263 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4264 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4265 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4266 | def test_crd_check_transitive(self): |
| 4267 | "Test transitive cross-repo dependencies" |
| 4268 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4269 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4270 | # and C,2 (not C,1 which would indicate stale data in the |
| 4271 | # cache for B). |
| 4272 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4273 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4274 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4275 | |
| 4276 | # A Depends-On: B |
| 4277 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4278 | A.subject, B.data['id']) |
| 4279 | |
| 4280 | # B Depends-On: C |
| 4281 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4282 | B.subject, C.data['id']) |
| 4283 | |
| 4284 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4285 | self.waitUntilSettled() |
| 4286 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4287 | |
| 4288 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4289 | self.waitUntilSettled() |
| 4290 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4291 | |
| 4292 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4293 | self.waitUntilSettled() |
| 4294 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4295 | |
| 4296 | C.addPatchset() |
| 4297 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4298 | self.waitUntilSettled() |
| 4299 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4300 | |
| 4301 | A.addPatchset() |
| 4302 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4303 | self.waitUntilSettled() |
| 4304 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4305 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4306 | def test_crd_check_unknown(self): |
| 4307 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4308 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4309 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4310 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4311 | # A Depends-On: B |
| 4312 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4313 | A.subject, B.data['id']) |
| 4314 | |
| 4315 | # Make sure zuul has seen an event on B. |
| 4316 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4317 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4318 | self.waitUntilSettled() |
| 4319 | |
| 4320 | self.assertEqual(A.data['status'], 'NEW') |
| 4321 | self.assertEqual(A.reported, 1) |
| 4322 | self.assertEqual(B.data['status'], 'NEW') |
| 4323 | self.assertEqual(B.reported, 0) |
| 4324 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4325 | def test_crd_cycle_join(self): |
| 4326 | "Test an updated change creates a cycle" |
| 4327 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4328 | |
| 4329 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4330 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4331 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4332 | |
| 4333 | # Create B->A |
| 4334 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4335 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4336 | B.subject, A.data['id']) |
| 4337 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4338 | self.waitUntilSettled() |
| 4339 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4340 | # Dep is there so zuul should have reported on B |
| 4341 | self.assertEqual(B.reported, 1) |
| 4342 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4343 | # Update A to add A->B (a cycle). |
| 4344 | A.addPatchset() |
| 4345 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4346 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4347 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4348 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4349 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4350 | # Dependency cycle injected so zuul should not have reported again on A |
| 4351 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4352 | |
| 4353 | # Now if we update B to remove the depends-on, everything |
| 4354 | # should be okay. B; A->B |
| 4355 | |
| 4356 | B.addPatchset() |
| 4357 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4358 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4359 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4360 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4361 | # Cycle was removed so now zuul should have reported again on A |
| 4362 | self.assertEqual(A.reported, 2) |
| 4363 | |
| 4364 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4365 | self.waitUntilSettled() |
| 4366 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4367 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4368 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4369 | def test_disable_at(self): |
| 4370 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4371 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4372 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4373 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4374 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4375 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4376 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4377 | |
| 4378 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4379 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4380 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4381 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4382 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4383 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4384 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4385 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4386 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4387 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4388 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4389 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4390 | self.executor_server.failJob('project-test1', A) |
| 4391 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4392 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4393 | self.executor_server.failJob('project-test1', D) |
| 4394 | self.executor_server.failJob('project-test1', E) |
| 4395 | self.executor_server.failJob('project-test1', F) |
| 4396 | self.executor_server.failJob('project-test1', G) |
| 4397 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4398 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4399 | self.executor_server.failJob('project-test1', J) |
| 4400 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4401 | |
| 4402 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4403 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4404 | self.waitUntilSettled() |
| 4405 | |
| 4406 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4407 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4408 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4409 | |
| 4410 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4411 | self.waitUntilSettled() |
| 4412 | |
| 4413 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4414 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4415 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4416 | |
| 4417 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4418 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4419 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4420 | self.waitUntilSettled() |
| 4421 | |
| 4422 | # We should be disabled now |
| 4423 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4424 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4425 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4426 | |
| 4427 | # We need to wait between each of these patches to make sure the |
| 4428 | # smtp messages come back in an expected order |
| 4429 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4430 | self.waitUntilSettled() |
| 4431 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4432 | self.waitUntilSettled() |
| 4433 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4434 | self.waitUntilSettled() |
| 4435 | |
| 4436 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4437 | # leaving a message on each change |
| 4438 | self.assertEqual(1, len(A.messages)) |
| 4439 | self.assertIn('Build failed.', A.messages[0]) |
| 4440 | self.assertEqual(1, len(B.messages)) |
| 4441 | self.assertIn('Build failed.', B.messages[0]) |
| 4442 | self.assertEqual(1, len(C.messages)) |
| 4443 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4444 | self.assertEqual(1, len(D.messages)) |
| 4445 | self.assertIn('Build failed.', D.messages[0]) |
| 4446 | self.assertEqual(1, len(E.messages)) |
| 4447 | self.assertIn('Build failed.', E.messages[0]) |
| 4448 | self.assertEqual(1, len(F.messages)) |
| 4449 | self.assertIn('Build failed.', F.messages[0]) |
| 4450 | |
| 4451 | # The last 3 (GHI) would have only reported via smtp. |
| 4452 | self.assertEqual(3, len(self.smtp_messages)) |
| 4453 | self.assertEqual(0, len(G.messages)) |
| 4454 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4455 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4456 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4457 | self.assertEqual(0, len(H.messages)) |
| 4458 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4459 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4460 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4461 | self.assertEqual(0, len(I.messages)) |
| 4462 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4463 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4464 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4465 | |
| 4466 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4467 | # comes out of disabled |
| 4468 | self.sched.reconfigure(self.config) |
| 4469 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4470 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4471 | |
| 4472 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4473 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4474 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4475 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4476 | |
| 4477 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4478 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4479 | self.waitUntilSettled() |
| 4480 | |
| 4481 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4482 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4483 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4484 | |
| 4485 | # J and K went back to gerrit |
| 4486 | self.assertEqual(1, len(J.messages)) |
| 4487 | self.assertIn('Build failed.', J.messages[0]) |
| 4488 | self.assertEqual(1, len(K.messages)) |
| 4489 | self.assertIn('Build failed.', K.messages[0]) |
| 4490 | # No more messages reported via smtp |
| 4491 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4492 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4493 | @simple_layout('layouts/one-job-project.yaml') |
| 4494 | def test_one_job_project(self): |
| 4495 | "Test that queueing works with one job" |
| 4496 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4497 | 'master', 'A') |
| 4498 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4499 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4500 | A.addApproval('Code-Review', 2) |
| 4501 | B.addApproval('Code-Review', 2) |
| 4502 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4503 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4504 | self.waitUntilSettled() |
| 4505 | |
| 4506 | self.assertEqual(A.data['status'], 'MERGED') |
| 4507 | self.assertEqual(A.reported, 2) |
| 4508 | self.assertEqual(B.data['status'], 'MERGED') |
| 4509 | self.assertEqual(B.reported, 2) |
| 4510 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4511 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4512 | "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] | 4513 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4514 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4515 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4516 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4517 | self.waitUntilSettled() |
| 4518 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4519 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4520 | self.waitUntilSettled() |
| 4521 | |
| 4522 | self.assertEqual(len(self.builds), 2) |
| 4523 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4524 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4525 | self.waitUntilSettled() |
| 4526 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4527 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4528 | self.assertEqual(len(self.builds), 1, |
| 4529 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4530 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4531 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4532 | self.waitUntilSettled() |
| 4533 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4534 | self.executor_server.hold_jobs_in_build = False |
| 4535 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4536 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4537 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4538 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4539 | self.assertEqual(A.reported, 1) |
| 4540 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4541 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4542 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4543 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4544 | |
| 4545 | self.fake_nodepool.paused = True |
| 4546 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4547 | A.addApproval('Code-Review', 2) |
| 4548 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4549 | self.waitUntilSettled() |
| 4550 | |
| 4551 | self.zk.client.stop() |
| 4552 | self.zk.client.start() |
| 4553 | self.fake_nodepool.paused = False |
| 4554 | self.waitUntilSettled() |
| 4555 | |
| 4556 | self.assertEqual(A.data['status'], 'MERGED') |
| 4557 | self.assertEqual(A.reported, 2) |
| 4558 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4559 | def test_nodepool_failure(self): |
| 4560 | "Test that jobs are reported after a nodepool failure" |
| 4561 | |
| 4562 | self.fake_nodepool.paused = True |
| 4563 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4564 | A.addApproval('Code-Review', 2) |
| 4565 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4566 | self.waitUntilSettled() |
| 4567 | |
| 4568 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4569 | self.fake_nodepool.addFailRequest(req) |
| 4570 | |
| 4571 | self.fake_nodepool.paused = False |
| 4572 | self.waitUntilSettled() |
| 4573 | |
| 4574 | self.assertEqual(A.data['status'], 'NEW') |
| 4575 | self.assertEqual(A.reported, 2) |
| 4576 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4577 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4578 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4579 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4580 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4581 | class TestExecutor(ZuulTestCase): |
| 4582 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4583 | |
| 4584 | def assertFinalState(self): |
| 4585 | # In this test, we expect to shut down in a non-final state, |
| 4586 | # so skip these checks. |
| 4587 | pass |
| 4588 | |
| 4589 | def assertCleanShutdown(self): |
| 4590 | self.log.debug("Assert clean shutdown") |
| 4591 | |
| 4592 | # After shutdown, make sure no jobs are running |
| 4593 | self.assertEqual({}, self.executor_server.job_workers) |
| 4594 | |
| 4595 | # Make sure that git.Repo objects have been garbage collected. |
| 4596 | repos = [] |
| 4597 | gc.collect() |
| 4598 | for obj in gc.get_objects(): |
| 4599 | if isinstance(obj, git.Repo): |
| 4600 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4601 | repos.append(obj) |
| 4602 | self.assertEqual(len(repos), 0) |
| 4603 | |
| 4604 | def test_executor_shutdown(self): |
| 4605 | "Test that the executor can shut down with jobs running" |
| 4606 | |
| 4607 | self.executor_server.hold_jobs_in_build = True |
| 4608 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4609 | A.addApproval('Code-Review', 2) |
| 4610 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4611 | self.waitUntilSettled() |
| 4612 | |
| 4613 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4614 | class TestDependencyGraph(ZuulTestCase): |
| 4615 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4616 | |
| 4617 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4618 | "Test a job in a dependency graph is queued only once" |
| 4619 | # Job dependencies, starting with A |
| 4620 | # A |
| 4621 | # / \ |
| 4622 | # B C |
| 4623 | # / \ / \ |
| 4624 | # D F E |
| 4625 | # | |
| 4626 | # G |
| 4627 | |
| 4628 | self.executor_server.hold_jobs_in_build = True |
| 4629 | change = self.fake_gerrit.addFakeChange( |
| 4630 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4631 | change.addApproval('Code-Review', 2) |
| 4632 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4633 | |
| 4634 | self.waitUntilSettled() |
| 4635 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4636 | |
| 4637 | self.executor_server.release('A') |
| 4638 | self.waitUntilSettled() |
| 4639 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4640 | |
| 4641 | self.executor_server.release('B') |
| 4642 | self.waitUntilSettled() |
| 4643 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4644 | |
| 4645 | self.executor_server.release('D') |
| 4646 | self.waitUntilSettled() |
| 4647 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4648 | |
| 4649 | self.executor_server.release('C') |
| 4650 | self.waitUntilSettled() |
| 4651 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4652 | |
| 4653 | self.executor_server.release('F') |
| 4654 | self.waitUntilSettled() |
| 4655 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4656 | |
| 4657 | self.executor_server.release('G') |
| 4658 | self.waitUntilSettled() |
| 4659 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4660 | |
| 4661 | self.executor_server.release('E') |
| 4662 | self.waitUntilSettled() |
| 4663 | self.assertEqual(len(self.builds), 0) |
| 4664 | |
| 4665 | self.executor_server.hold_jobs_in_build = False |
| 4666 | self.executor_server.release() |
| 4667 | self.waitUntilSettled() |
| 4668 | |
| 4669 | self.assertEqual(len(self.builds), 0) |
| 4670 | self.assertEqual(len(self.history), 7) |
| 4671 | |
| 4672 | self.assertEqual(change.data['status'], 'MERGED') |
| 4673 | self.assertEqual(change.reported, 2) |
| 4674 | |
| 4675 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4676 | "Test that a job waits till all dependencies are successful" |
| 4677 | # Job dependencies, starting with A |
| 4678 | # A |
| 4679 | # / \ |
| 4680 | # B C* |
| 4681 | # / \ / \ |
| 4682 | # D F E |
| 4683 | # | |
| 4684 | # G |
| 4685 | |
| 4686 | self.executor_server.hold_jobs_in_build = True |
| 4687 | change = self.fake_gerrit.addFakeChange( |
| 4688 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4689 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4690 | |
| 4691 | self.executor_server.failJob('C', change) |
| 4692 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4693 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4694 | |
| 4695 | self.waitUntilSettled() |
| 4696 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4697 | |
| 4698 | self.executor_server.release('A') |
| 4699 | self.waitUntilSettled() |
| 4700 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4701 | |
| 4702 | self.executor_server.release('B') |
| 4703 | self.waitUntilSettled() |
| 4704 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4705 | |
| 4706 | self.executor_server.release('D') |
| 4707 | self.waitUntilSettled() |
| 4708 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4709 | |
| 4710 | self.executor_server.release('C') |
| 4711 | self.waitUntilSettled() |
| 4712 | self.assertEqual(len(self.builds), 0) |
| 4713 | |
| 4714 | self.executor_server.hold_jobs_in_build = False |
| 4715 | self.executor_server.release() |
| 4716 | self.waitUntilSettled() |
| 4717 | |
| 4718 | self.assertEqual(len(self.builds), 0) |
| 4719 | self.assertEqual(len(self.history), 4) |
| 4720 | |
| 4721 | self.assertEqual(change.data['status'], 'NEW') |
| 4722 | self.assertEqual(change.reported, 2) |
| 4723 | |
| 4724 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4725 | class TestDuplicatePipeline(ZuulTestCase): |
| 4726 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4727 | |
| 4728 | def test_duplicate_pipelines(self): |
| 4729 | "Test that a change matching multiple pipelines works" |
| 4730 | |
| 4731 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4732 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4733 | self.waitUntilSettled() |
| 4734 | |
| 4735 | self.assertHistory([ |
| 4736 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4737 | pipeline='dup1'), |
| 4738 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4739 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4740 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4741 | |
| 4742 | self.assertEqual(len(A.messages), 2) |
| 4743 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4744 | if 'dup1' in A.messages[0]: |
| 4745 | self.assertIn('dup1', A.messages[0]) |
| 4746 | self.assertNotIn('dup2', A.messages[0]) |
| 4747 | self.assertIn('project-test1', A.messages[0]) |
| 4748 | self.assertIn('dup2', A.messages[1]) |
| 4749 | self.assertNotIn('dup1', A.messages[1]) |
| 4750 | self.assertIn('project-test1', A.messages[1]) |
| 4751 | else: |
| 4752 | self.assertIn('dup1', A.messages[1]) |
| 4753 | self.assertNotIn('dup2', A.messages[1]) |
| 4754 | self.assertIn('project-test1', A.messages[1]) |
| 4755 | self.assertIn('dup2', A.messages[0]) |
| 4756 | self.assertNotIn('dup1', A.messages[0]) |
| 4757 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4758 | |
| 4759 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4760 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4761 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4762 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4763 | def test_job_from_templates_executed(self): |
| 4764 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4765 | |
| 4766 | A = self.fake_gerrit.addFakeChange( |
| 4767 | 'org/templated-project', 'master', 'A') |
| 4768 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4769 | self.waitUntilSettled() |
| 4770 | |
| 4771 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4772 | 'SUCCESS') |
| 4773 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4774 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4775 | |
| 4776 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4777 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4778 | |
| 4779 | A = self.fake_gerrit.addFakeChange( |
| 4780 | 'org/layered-project', 'master', 'A') |
| 4781 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4782 | self.waitUntilSettled() |
| 4783 | |
| 4784 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4785 | 'SUCCESS') |
| 4786 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4787 | 'SUCCESS') |
| 4788 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4789 | ).result, 'SUCCESS') |
| 4790 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4791 | ).result, 'SUCCESS') |
| 4792 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4793 | ).result, 'SUCCESS') |
| 4794 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4795 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4796 | |
| 4797 | |
| 4798 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4799 | tenant_config_file = 'config/success-url/main.yaml' |
| 4800 | |
| 4801 | def test_success_url(self): |
| 4802 | "Ensure bad build params are ignored" |
| 4803 | self.sched.reconfigure(self.config) |
| 4804 | self.init_repo('org/docs') |
| 4805 | |
| 4806 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4807 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4808 | self.waitUntilSettled() |
| 4809 | |
| 4810 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4811 | self.assertEqual(len(self.history), 2) |
| 4812 | |
| 4813 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4814 | for build in self.history: |
| 4815 | if build.name == 'docs-draft-test': |
| 4816 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4817 | elif build.name == 'docs-draft-test2': |
| 4818 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4819 | |
| 4820 | # Two msgs: 'Starting...' + results |
| 4821 | self.assertEqual(len(self.smtp_messages), 2) |
| 4822 | body = self.smtp_messages[1]['body'].splitlines() |
| 4823 | self.assertEqual('Build succeeded.', body[0]) |
| 4824 | |
| 4825 | self.assertIn( |
| 4826 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4827 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4828 | body[2]) |
| 4829 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4830 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4831 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4832 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4833 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4834 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4835 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4836 | |
| 4837 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4838 | class TestSchedulerMerges(ZuulTestCase): |
| 4839 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4840 | |
| 4841 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4842 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4843 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4844 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4845 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4846 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4847 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4848 | A.addApproval('Code-Review', 2) |
| 4849 | B.addApproval('Code-Review', 2) |
| 4850 | C.addApproval('Code-Review', 2) |
| 4851 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4852 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4853 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4854 | self.waitUntilSettled() |
| 4855 | |
| 4856 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4857 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4858 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4859 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4860 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4861 | repo_messages.reverse() |
| 4862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4863 | self.executor_server.hold_jobs_in_build = False |
| 4864 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4865 | self.waitUntilSettled() |
| 4866 | |
| 4867 | return repo_messages |
| 4868 | |
| 4869 | def _test_merge(self, mode): |
| 4870 | us_path = os.path.join( |
| 4871 | self.upstream_root, 'org/project-%s' % mode) |
| 4872 | expected_messages = [ |
| 4873 | 'initial commit', |
| 4874 | 'add content from fixture', |
| 4875 | # the intermediate commits order is nondeterministic |
| 4876 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4877 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4878 | ] |
| 4879 | result = self._test_project_merge_mode(mode) |
| 4880 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4881 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4882 | |
| 4883 | def test_project_merge_mode_merge(self): |
| 4884 | self._test_merge('merge') |
| 4885 | |
| 4886 | def test_project_merge_mode_merge_resolve(self): |
| 4887 | self._test_merge('merge-resolve') |
| 4888 | |
| 4889 | def test_project_merge_mode_cherrypick(self): |
| 4890 | expected_messages = [ |
| 4891 | 'initial commit', |
| 4892 | 'add content from fixture', |
| 4893 | 'A-1', |
| 4894 | 'B-1', |
| 4895 | 'C-1'] |
| 4896 | result = self._test_project_merge_mode('cherry-pick') |
| 4897 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4898 | |
| 4899 | def test_merge_branch(self): |
| 4900 | "Test that the right commits are on alternate branches" |
| 4901 | self.create_branch('org/project-merge-branches', 'mp') |
| 4902 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4903 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4904 | A = self.fake_gerrit.addFakeChange( |
| 4905 | 'org/project-merge-branches', 'mp', 'A') |
| 4906 | B = self.fake_gerrit.addFakeChange( |
| 4907 | 'org/project-merge-branches', 'mp', 'B') |
| 4908 | C = self.fake_gerrit.addFakeChange( |
| 4909 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4910 | A.addApproval('Code-Review', 2) |
| 4911 | B.addApproval('Code-Review', 2) |
| 4912 | C.addApproval('Code-Review', 2) |
| 4913 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4914 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4915 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4916 | self.waitUntilSettled() |
| 4917 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4918 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4919 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4920 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4921 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4922 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4923 | self.waitUntilSettled() |
| 4924 | |
| 4925 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 4926 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4927 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4928 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4929 | repo = git.Repo(path) |
| 4930 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4931 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4932 | repo_messages.reverse() |
| 4933 | correct_messages = [ |
| 4934 | 'initial commit', |
| 4935 | 'add content from fixture', |
| 4936 | 'mp commit', |
| 4937 | 'A-1', 'B-1', 'C-1'] |
| 4938 | self.assertEqual(repo_messages, correct_messages) |
| 4939 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4940 | self.executor_server.hold_jobs_in_build = False |
| 4941 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4942 | self.waitUntilSettled() |
| 4943 | |
| 4944 | def test_merge_multi_branch(self): |
| 4945 | "Test that dependent changes on multiple branches are merged" |
| 4946 | self.create_branch('org/project-merge-branches', 'mp') |
| 4947 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4948 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4949 | A = self.fake_gerrit.addFakeChange( |
| 4950 | 'org/project-merge-branches', 'master', 'A') |
| 4951 | B = self.fake_gerrit.addFakeChange( |
| 4952 | 'org/project-merge-branches', 'mp', 'B') |
| 4953 | C = self.fake_gerrit.addFakeChange( |
| 4954 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4955 | A.addApproval('Code-Review', 2) |
| 4956 | B.addApproval('Code-Review', 2) |
| 4957 | C.addApproval('Code-Review', 2) |
| 4958 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4959 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4960 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4961 | self.waitUntilSettled() |
| 4962 | |
| 4963 | job_A = None |
| 4964 | for job in self.builds: |
| 4965 | if 'project-merge' in job.name: |
| 4966 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4967 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4968 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4969 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4970 | repo = git.Repo(path) |
| 4971 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4972 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4973 | repo_messages.reverse() |
| 4974 | correct_messages = [ |
| 4975 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4976 | self.assertEqual(repo_messages, correct_messages) |
| 4977 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4978 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4979 | self.waitUntilSettled() |
| 4980 | |
| 4981 | job_B = None |
| 4982 | for job in self.builds: |
| 4983 | if 'project-merge' in job.name: |
| 4984 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4985 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4986 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4987 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4988 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4989 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4990 | repo_messages.reverse() |
| 4991 | correct_messages = [ |
| 4992 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4993 | self.assertEqual(repo_messages, correct_messages) |
| 4994 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4995 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4996 | self.waitUntilSettled() |
| 4997 | |
| 4998 | job_C = None |
| 4999 | for job in self.builds: |
| 5000 | if 'project-merge' in job.name: |
| 5001 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 5002 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 5003 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 5004 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5005 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 5006 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5007 | |
| 5008 | repo_messages.reverse() |
| 5009 | correct_messages = [ |
| 5010 | 'initial commit', 'add content from fixture', |
| 5011 | 'A-1', 'C-1'] |
| 5012 | # Ensure the right commits are in the history for this ref |
| 5013 | self.assertEqual(repo_messages, correct_messages) |
| 5014 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5015 | self.executor_server.hold_jobs_in_build = False |
| 5016 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5017 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5018 | |
| 5019 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5020 | class TestSemaphore(ZuulTestCase): |
| 5021 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5022 | |
| 5023 | def test_semaphore_one(self): |
| 5024 | "Test semaphores with max=1 (mutex)" |
| 5025 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5026 | |
| 5027 | self.executor_server.hold_jobs_in_build = True |
| 5028 | |
| 5029 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5030 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5031 | self.assertFalse('test-semaphore' in |
| 5032 | tenant.semaphore_handler.semaphores) |
| 5033 | |
| 5034 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5035 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5036 | self.waitUntilSettled() |
| 5037 | |
| 5038 | self.assertEqual(len(self.builds), 3) |
| 5039 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5040 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5041 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5042 | |
| 5043 | self.executor_server.release('semaphore-one-test1') |
| 5044 | self.waitUntilSettled() |
| 5045 | |
| 5046 | self.assertEqual(len(self.builds), 3) |
| 5047 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5048 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5049 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5050 | self.assertTrue('test-semaphore' in |
| 5051 | tenant.semaphore_handler.semaphores) |
| 5052 | |
| 5053 | self.executor_server.release('semaphore-one-test2') |
| 5054 | self.waitUntilSettled() |
| 5055 | |
| 5056 | self.assertEqual(len(self.builds), 3) |
| 5057 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5058 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5059 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5060 | self.assertTrue('test-semaphore' in |
| 5061 | tenant.semaphore_handler.semaphores) |
| 5062 | |
| 5063 | self.executor_server.release('semaphore-one-test1') |
| 5064 | self.waitUntilSettled() |
| 5065 | |
| 5066 | self.assertEqual(len(self.builds), 3) |
| 5067 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5068 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5069 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5070 | self.assertTrue('test-semaphore' in |
| 5071 | tenant.semaphore_handler.semaphores) |
| 5072 | |
| 5073 | self.executor_server.release('semaphore-one-test2') |
| 5074 | self.waitUntilSettled() |
| 5075 | |
| 5076 | self.assertEqual(len(self.builds), 2) |
| 5077 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5078 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5079 | self.assertFalse('test-semaphore' in |
| 5080 | tenant.semaphore_handler.semaphores) |
| 5081 | |
| 5082 | self.executor_server.hold_jobs_in_build = False |
| 5083 | self.executor_server.release() |
| 5084 | |
| 5085 | self.waitUntilSettled() |
| 5086 | self.assertEqual(len(self.builds), 0) |
| 5087 | |
| 5088 | self.assertEqual(A.reported, 1) |
| 5089 | self.assertEqual(B.reported, 1) |
| 5090 | self.assertFalse('test-semaphore' in |
| 5091 | tenant.semaphore_handler.semaphores) |
| 5092 | |
| 5093 | def test_semaphore_two(self): |
| 5094 | "Test semaphores with max>1" |
| 5095 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5096 | |
| 5097 | self.executor_server.hold_jobs_in_build = True |
| 5098 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5099 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5100 | self.assertFalse('test-semaphore-two' in |
| 5101 | tenant.semaphore_handler.semaphores) |
| 5102 | |
| 5103 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5104 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5105 | self.waitUntilSettled() |
| 5106 | |
| 5107 | self.assertEqual(len(self.builds), 4) |
| 5108 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5109 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5110 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5111 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5112 | self.assertTrue('test-semaphore-two' in |
| 5113 | tenant.semaphore_handler.semaphores) |
| 5114 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5115 | 'test-semaphore-two', [])), 2) |
| 5116 | |
| 5117 | self.executor_server.release('semaphore-two-test1') |
| 5118 | self.waitUntilSettled() |
| 5119 | |
| 5120 | self.assertEqual(len(self.builds), 4) |
| 5121 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5122 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5123 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5124 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5125 | self.assertTrue('test-semaphore-two' in |
| 5126 | tenant.semaphore_handler.semaphores) |
| 5127 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5128 | 'test-semaphore-two', [])), 2) |
| 5129 | |
| 5130 | self.executor_server.release('semaphore-two-test2') |
| 5131 | self.waitUntilSettled() |
| 5132 | |
| 5133 | self.assertEqual(len(self.builds), 4) |
| 5134 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5135 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5136 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5137 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5138 | self.assertTrue('test-semaphore-two' in |
| 5139 | tenant.semaphore_handler.semaphores) |
| 5140 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5141 | 'test-semaphore-two', [])), 2) |
| 5142 | |
| 5143 | self.executor_server.release('semaphore-two-test1') |
| 5144 | self.waitUntilSettled() |
| 5145 | |
| 5146 | self.assertEqual(len(self.builds), 3) |
| 5147 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5148 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5149 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5150 | self.assertTrue('test-semaphore-two' in |
| 5151 | tenant.semaphore_handler.semaphores) |
| 5152 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5153 | 'test-semaphore-two', [])), 1) |
| 5154 | |
| 5155 | self.executor_server.release('semaphore-two-test2') |
| 5156 | self.waitUntilSettled() |
| 5157 | |
| 5158 | self.assertEqual(len(self.builds), 2) |
| 5159 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5160 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5161 | self.assertFalse('test-semaphore-two' in |
| 5162 | tenant.semaphore_handler.semaphores) |
| 5163 | |
| 5164 | self.executor_server.hold_jobs_in_build = False |
| 5165 | self.executor_server.release() |
| 5166 | |
| 5167 | self.waitUntilSettled() |
| 5168 | self.assertEqual(len(self.builds), 0) |
| 5169 | |
| 5170 | self.assertEqual(A.reported, 1) |
| 5171 | self.assertEqual(B.reported, 1) |
| 5172 | |
| 5173 | def test_semaphore_abandon(self): |
| 5174 | "Test abandon with job semaphores" |
| 5175 | self.executor_server.hold_jobs_in_build = True |
| 5176 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5177 | check_pipeline = tenant.layout.pipelines['check'] |
| 5178 | |
| 5179 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5180 | self.assertFalse('test-semaphore' in |
| 5181 | tenant.semaphore_handler.semaphores) |
| 5182 | |
| 5183 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5184 | self.waitUntilSettled() |
| 5185 | |
| 5186 | self.assertTrue('test-semaphore' in |
| 5187 | tenant.semaphore_handler.semaphores) |
| 5188 | |
| 5189 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5190 | self.waitUntilSettled() |
| 5191 | |
| 5192 | # The check pipeline should be empty |
| 5193 | items = check_pipeline.getAllItems() |
| 5194 | self.assertEqual(len(items), 0) |
| 5195 | |
| 5196 | # The semaphore should be released |
| 5197 | self.assertFalse('test-semaphore' in |
| 5198 | tenant.semaphore_handler.semaphores) |
| 5199 | |
| 5200 | self.executor_server.hold_jobs_in_build = False |
| 5201 | self.executor_server.release() |
| 5202 | self.waitUntilSettled() |
| 5203 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5204 | def test_semaphore_new_patchset(self): |
| 5205 | "Test new patchset with job semaphores" |
| 5206 | self.executor_server.hold_jobs_in_build = True |
| 5207 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5208 | check_pipeline = tenant.layout.pipelines['check'] |
| 5209 | |
| 5210 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5211 | self.assertFalse('test-semaphore' in |
| 5212 | tenant.semaphore_handler.semaphores) |
| 5213 | |
| 5214 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5215 | self.waitUntilSettled() |
| 5216 | |
| 5217 | self.assertTrue('test-semaphore' in |
| 5218 | tenant.semaphore_handler.semaphores) |
| 5219 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5220 | self.assertEqual(len(semaphore), 1) |
| 5221 | |
| 5222 | A.addPatchset() |
| 5223 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5224 | self.waitUntilSettled() |
| 5225 | |
| 5226 | self.assertTrue('test-semaphore' in |
| 5227 | tenant.semaphore_handler.semaphores) |
| 5228 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5229 | self.assertEqual(len(semaphore), 1) |
| 5230 | |
| 5231 | items = check_pipeline.getAllItems() |
| 5232 | self.assertEqual(items[0].change.number, '1') |
| 5233 | self.assertEqual(items[0].change.patchset, '2') |
| 5234 | self.assertTrue(items[0].live) |
| 5235 | |
| 5236 | self.executor_server.hold_jobs_in_build = False |
| 5237 | self.executor_server.release() |
| 5238 | self.waitUntilSettled() |
| 5239 | |
| 5240 | # The semaphore should be released |
| 5241 | self.assertFalse('test-semaphore' in |
| 5242 | tenant.semaphore_handler.semaphores) |
| 5243 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5244 | def test_semaphore_reconfigure(self): |
| 5245 | "Test reconfigure with job semaphores" |
| 5246 | self.executor_server.hold_jobs_in_build = True |
| 5247 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5248 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5249 | self.assertFalse('test-semaphore' in |
| 5250 | tenant.semaphore_handler.semaphores) |
| 5251 | |
| 5252 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5253 | self.waitUntilSettled() |
| 5254 | |
| 5255 | self.assertTrue('test-semaphore' in |
| 5256 | tenant.semaphore_handler.semaphores) |
| 5257 | |
| 5258 | # reconfigure without layout change |
| 5259 | self.sched.reconfigure(self.config) |
| 5260 | self.waitUntilSettled() |
| 5261 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5262 | |
| 5263 | # semaphore still must be held |
| 5264 | self.assertTrue('test-semaphore' in |
| 5265 | tenant.semaphore_handler.semaphores) |
| 5266 | |
| 5267 | self.commitConfigUpdate( |
| 5268 | 'common-config', |
| 5269 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5270 | self.sched.reconfigure(self.config) |
| 5271 | self.waitUntilSettled() |
| 5272 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5273 | |
| 5274 | self.executor_server.release('project-test1') |
| 5275 | self.waitUntilSettled() |
| 5276 | |
| 5277 | # There should be no builds anymore |
| 5278 | self.assertEqual(len(self.builds), 0) |
| 5279 | |
| 5280 | # The semaphore should be released |
| 5281 | self.assertFalse('test-semaphore' in |
| 5282 | tenant.semaphore_handler.semaphores) |
| 5283 | |
| 5284 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5285 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5286 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5287 | |
| 5288 | def test_semaphore_tenant_isolation(self): |
| 5289 | "Test semaphores in multiple tenants" |
| 5290 | |
| 5291 | self.waitUntilSettled() |
| 5292 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5293 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5294 | |
| 5295 | self.executor_server.hold_jobs_in_build = True |
| 5296 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5297 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5298 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5299 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5300 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5301 | self.assertFalse('test-semaphore' in |
| 5302 | tenant_one.semaphore_handler.semaphores) |
| 5303 | self.assertFalse('test-semaphore' in |
| 5304 | tenant_two.semaphore_handler.semaphores) |
| 5305 | |
| 5306 | # add patches to project1 of tenant-one |
| 5307 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5308 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5309 | self.waitUntilSettled() |
| 5310 | |
| 5311 | # one build of project1-test1 must run |
| 5312 | # semaphore of tenant-one must be acquired once |
| 5313 | # semaphore of tenant-two must not be acquired |
| 5314 | self.assertEqual(len(self.builds), 1) |
| 5315 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5316 | self.assertTrue('test-semaphore' in |
| 5317 | tenant_one.semaphore_handler.semaphores) |
| 5318 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5319 | 'test-semaphore', [])), 1) |
| 5320 | self.assertFalse('test-semaphore' in |
| 5321 | tenant_two.semaphore_handler.semaphores) |
| 5322 | |
| 5323 | # add patches to project2 of tenant-two |
| 5324 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5325 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5326 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5327 | self.waitUntilSettled() |
| 5328 | |
| 5329 | # one build of project1-test1 must run |
| 5330 | # two builds of project2-test1 must run |
| 5331 | # semaphore of tenant-one must be acquired once |
| 5332 | # semaphore of tenant-two must be acquired twice |
| 5333 | self.assertEqual(len(self.builds), 3) |
| 5334 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5335 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5336 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5337 | self.assertTrue('test-semaphore' in |
| 5338 | tenant_one.semaphore_handler.semaphores) |
| 5339 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5340 | 'test-semaphore', [])), 1) |
| 5341 | self.assertTrue('test-semaphore' in |
| 5342 | tenant_two.semaphore_handler.semaphores) |
| 5343 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5344 | 'test-semaphore', [])), 2) |
| 5345 | |
| 5346 | self.executor_server.release('project1-test1') |
| 5347 | self.waitUntilSettled() |
| 5348 | |
| 5349 | # one build of project1-test1 must run |
| 5350 | # two builds of project2-test1 must run |
| 5351 | # semaphore of tenant-one must be acquired once |
| 5352 | # semaphore of tenant-two must be acquired twice |
| 5353 | self.assertEqual(len(self.builds), 3) |
| 5354 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5355 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5356 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5357 | self.assertTrue('test-semaphore' in |
| 5358 | tenant_one.semaphore_handler.semaphores) |
| 5359 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5360 | 'test-semaphore', [])), 1) |
| 5361 | self.assertTrue('test-semaphore' in |
| 5362 | tenant_two.semaphore_handler.semaphores) |
| 5363 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5364 | 'test-semaphore', [])), 2) |
| 5365 | |
| 5366 | self.executor_server.release('project2-test1') |
| 5367 | self.waitUntilSettled() |
| 5368 | |
| 5369 | # one build of project1-test1 must run |
| 5370 | # one build of project2-test1 must run |
| 5371 | # semaphore of tenant-one must be acquired once |
| 5372 | # semaphore of tenant-two must be acquired once |
| 5373 | self.assertEqual(len(self.builds), 2) |
| 5374 | self.assertTrue('test-semaphore' in |
| 5375 | tenant_one.semaphore_handler.semaphores) |
| 5376 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5377 | 'test-semaphore', [])), 1) |
| 5378 | self.assertTrue('test-semaphore' in |
| 5379 | tenant_two.semaphore_handler.semaphores) |
| 5380 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5381 | 'test-semaphore', [])), 1) |
| 5382 | |
| 5383 | self.executor_server.hold_jobs_in_build = False |
| 5384 | self.executor_server.release() |
| 5385 | |
| 5386 | self.waitUntilSettled() |
| 5387 | |
| 5388 | # no build must run |
| 5389 | # semaphore of tenant-one must not be acquired |
| 5390 | # semaphore of tenant-two must not be acquired |
| 5391 | self.assertEqual(len(self.builds), 0) |
| 5392 | self.assertFalse('test-semaphore' in |
| 5393 | tenant_one.semaphore_handler.semaphores) |
| 5394 | self.assertFalse('test-semaphore' in |
| 5395 | tenant_two.semaphore_handler.semaphores) |
| 5396 | |
| 5397 | self.assertEqual(A.reported, 1) |
| 5398 | self.assertEqual(B.reported, 1) |
| 5399 | |
| 5400 | |
| 5401 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5402 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5403 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5404 | |
| 5405 | def test_semaphore_in_repo(self): |
| 5406 | "Test semaphores in repo config" |
| 5407 | |
| 5408 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5409 | # max value should not be evaluated dynamically but must be updated |
| 5410 | # after the change lands. |
| 5411 | |
| 5412 | self.waitUntilSettled() |
| 5413 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5414 | |
| 5415 | in_repo_conf = textwrap.dedent( |
| 5416 | """ |
| 5417 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5418 | name: project-test1 |
| 5419 | |
| 5420 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5421 | name: project-test2 |
| 5422 | semaphore: test-semaphore |
| 5423 | |
| 5424 | - project: |
| 5425 | name: org/project |
| 5426 | tenant-one-gate: |
| 5427 | jobs: |
| 5428 | - project-test2 |
| 5429 | |
| 5430 | # the max value in dynamic layout must be ignored |
| 5431 | - semaphore: |
| 5432 | name: test-semaphore |
| 5433 | max: 2 |
| 5434 | """) |
| 5435 | |
| 5436 | in_repo_playbook = textwrap.dedent( |
| 5437 | """ |
| 5438 | - hosts: all |
| 5439 | tasks: [] |
| 5440 | """) |
| 5441 | |
| 5442 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5443 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5444 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5445 | files=file_dict) |
| 5446 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5447 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5448 | B.setDependsOn(A, 1) |
| 5449 | C.setDependsOn(A, 1) |
| 5450 | |
| 5451 | self.executor_server.hold_jobs_in_build = True |
| 5452 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5453 | A.addApproval('Code-Review', 2) |
| 5454 | B.addApproval('Code-Review', 2) |
| 5455 | C.addApproval('Code-Review', 2) |
| 5456 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5457 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5458 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5459 | self.waitUntilSettled() |
| 5460 | |
| 5461 | # check that the layout in a queue item still has max value of 1 |
| 5462 | # for test-semaphore |
| 5463 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5464 | queue = None |
| 5465 | for queue_candidate in pipeline.queues: |
| 5466 | if queue_candidate.name == 'org/project': |
| 5467 | queue = queue_candidate |
| 5468 | break |
| 5469 | queue_item = queue.queue[0] |
| 5470 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5471 | dynamic_test_semaphore = \ |
| 5472 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5473 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5474 | |
| 5475 | # one build must be in queue, one semaphores acquired |
| 5476 | self.assertEqual(len(self.builds), 1) |
| 5477 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5478 | self.assertTrue('test-semaphore' in |
| 5479 | tenant.semaphore_handler.semaphores) |
| 5480 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5481 | 'test-semaphore', [])), 1) |
| 5482 | |
| 5483 | self.executor_server.release('project-test2') |
| 5484 | self.waitUntilSettled() |
| 5485 | |
| 5486 | # change A must be merged |
| 5487 | self.assertEqual(A.data['status'], 'MERGED') |
| 5488 | self.assertEqual(A.reported, 2) |
| 5489 | |
| 5490 | # send change-merged event as the gerrit mock doesn't send it |
| 5491 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5492 | self.waitUntilSettled() |
| 5493 | |
| 5494 | # now that change A was merged, the new semaphore max must be effective |
| 5495 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5496 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5497 | |
| 5498 | # two builds must be in queue, two semaphores acquired |
| 5499 | self.assertEqual(len(self.builds), 2) |
| 5500 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5501 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5502 | self.assertTrue('test-semaphore' in |
| 5503 | tenant.semaphore_handler.semaphores) |
| 5504 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5505 | 'test-semaphore', [])), 2) |
| 5506 | |
| 5507 | self.executor_server.release('project-test2') |
| 5508 | self.waitUntilSettled() |
| 5509 | |
| 5510 | self.assertEqual(len(self.builds), 0) |
| 5511 | self.assertFalse('test-semaphore' in |
| 5512 | tenant.semaphore_handler.semaphores) |
| 5513 | |
| 5514 | self.executor_server.hold_jobs_in_build = False |
| 5515 | self.executor_server.release() |
| 5516 | |
| 5517 | self.waitUntilSettled() |
| 5518 | self.assertEqual(len(self.builds), 0) |
| 5519 | |
| 5520 | self.assertEqual(A.reported, 2) |
| 5521 | self.assertEqual(B.reported, 2) |
| 5522 | self.assertEqual(C.reported, 2) |