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 | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2821 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2822 | def test_tags(self): |
| 2823 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2824 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2825 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2826 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2827 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2828 | self.waitUntilSettled() |
| 2829 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2830 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2831 | |
| 2832 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2833 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2834 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2835 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2836 | |
| 2837 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2838 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2839 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2840 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2841 | def test_timer(self): |
| 2842 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2843 | # This test can not use simple_layout because it must start |
| 2844 | # with a configuration which does not include a |
| 2845 | # timer-triggered job so that we have an opportunity to set |
| 2846 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2847 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2848 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2849 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2850 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2851 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2852 | # The pipeline triggers every second, so we should have seen |
| 2853 | # several by now. |
| 2854 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2855 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2856 | |
| 2857 | self.assertEqual(len(self.builds), 2) |
| 2858 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2859 | port = self.webapp.server.socket.getsockname()[1] |
| 2860 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2861 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2862 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2863 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2864 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2865 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2866 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2867 | # Stop queuing timer triggered jobs so that the assertions |
| 2868 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2869 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2870 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2871 | self.waitUntilSettled() |
| 2872 | # If APScheduler is in mid-event when we remove the job, we |
| 2873 | # can end up with one more event firing, so give it an extra |
| 2874 | # second to settle. |
| 2875 | time.sleep(1) |
| 2876 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2877 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2878 | self.waitUntilSettled() |
| 2879 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2880 | self.assertHistory([ |
| 2881 | dict(name='project-bitrot', result='SUCCESS', |
| 2882 | ref='refs/heads/master'), |
| 2883 | dict(name='project-bitrot', result='SUCCESS', |
| 2884 | ref='refs/heads/stable'), |
| 2885 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2886 | |
| 2887 | data = json.loads(data) |
| 2888 | status_jobs = set() |
| 2889 | for p in data['pipelines']: |
| 2890 | for q in p['change_queues']: |
| 2891 | for head in q['heads']: |
| 2892 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2893 | for job in change['jobs']: |
| 2894 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2895 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2896 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2897 | def test_idle(self): |
| 2898 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2899 | # This test can not use simple_layout because it must start |
| 2900 | # with a configuration which does not include a |
| 2901 | # timer-triggered job so that we have an opportunity to set |
| 2902 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2903 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2904 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2905 | for x in range(1, 3): |
| 2906 | # Test that timer triggers periodic jobs even across |
| 2907 | # layout config reloads. |
| 2908 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2909 | self.commitConfigUpdate('common-config', |
| 2910 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2911 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2912 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2913 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2914 | # The pipeline triggers every second, so we should have seen |
| 2915 | # several by now. |
| 2916 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2917 | |
| 2918 | # Stop queuing timer triggered jobs so that the assertions |
| 2919 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2920 | self.commitConfigUpdate('common-config', |
| 2921 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2922 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2923 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2924 | # If APScheduler is in mid-event when we remove the job, |
| 2925 | # we can end up with one more event firing, so give it an |
| 2926 | # extra second to settle. |
| 2927 | time.sleep(1) |
| 2928 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2929 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2930 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2931 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2932 | self.waitUntilSettled() |
| 2933 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2934 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2935 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2936 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2937 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2938 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2939 | self.waitUntilSettled() |
| 2940 | |
| 2941 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2942 | self.waitUntilSettled() |
| 2943 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2944 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2945 | |
| 2946 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2947 | # work on the knowledge of what the first message should be as |
| 2948 | # it is only configured to go to SMTP. |
| 2949 | |
| 2950 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2951 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2952 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2953 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2954 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2955 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2956 | |
| 2957 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2958 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2959 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2960 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2961 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2962 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2963 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2964 | def test_timer_smtp(self): |
| 2965 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2966 | # This test can not use simple_layout because it must start |
| 2967 | # with a configuration which does not include a |
| 2968 | # timer-triggered job so that we have an opportunity to set |
| 2969 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2970 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2971 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2972 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2973 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2974 | # The pipeline triggers every second, so we should have seen |
| 2975 | # several by now. |
| 2976 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2977 | self.waitUntilSettled() |
| 2978 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2979 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2980 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2981 | self.waitUntilSettled() |
| 2982 | self.assertEqual(len(self.history), 2) |
| 2983 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2984 | self.assertEqual(self.getJobFromHistory( |
| 2985 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2986 | self.assertEqual(self.getJobFromHistory( |
| 2987 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2988 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2989 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2990 | |
| 2991 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2992 | # work on the knowledge of what the first message should be as |
| 2993 | # it is only configured to go to SMTP. |
| 2994 | |
| 2995 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2996 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2997 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2998 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2999 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3000 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3001 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3002 | # Stop queuing timer triggered jobs and let any that may have |
| 3003 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 3004 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3005 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3006 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3007 | # If APScheduler is in mid-event when we remove the job, we |
| 3008 | # can end up with one more event firing, so give it an extra |
| 3009 | # second to settle. |
| 3010 | time.sleep(1) |
| 3011 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3012 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3013 | self.waitUntilSettled() |
| 3014 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3015 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3016 | def test_timer_sshkey(self): |
| 3017 | "Test that a periodic job can setup SSH key authentication" |
| 3018 | self.worker.hold_jobs_in_build = True |
| 3019 | self.config.set('zuul', 'layout_config', |
| 3020 | 'tests/fixtures/layout-timer.yaml') |
| 3021 | self.sched.reconfigure(self.config) |
| 3022 | self.registerJobs() |
| 3023 | |
| 3024 | # The pipeline triggers every second, so we should have seen |
| 3025 | # several by now. |
| 3026 | time.sleep(5) |
| 3027 | self.waitUntilSettled() |
| 3028 | |
| 3029 | self.assertEqual(len(self.builds), 2) |
| 3030 | |
| 3031 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3032 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3033 | with open(ssh_wrapper) as f: |
| 3034 | ssh_wrapper_content = f.read() |
| 3035 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3036 | # In the unit tests Merger runs in the same process, |
| 3037 | # so we see its' environment variables |
| 3038 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3039 | |
| 3040 | self.worker.release('.*') |
| 3041 | self.waitUntilSettled() |
| 3042 | self.assertEqual(len(self.history), 2) |
| 3043 | |
| 3044 | self.assertEqual(self.getJobFromHistory( |
| 3045 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3046 | self.assertEqual(self.getJobFromHistory( |
| 3047 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3048 | |
| 3049 | # Stop queuing timer triggered jobs and let any that may have |
| 3050 | # queued through so that end of test assertions pass. |
| 3051 | self.config.set('zuul', 'layout_config', |
| 3052 | 'tests/fixtures/layout-no-timer.yaml') |
| 3053 | self.sched.reconfigure(self.config) |
| 3054 | self.registerJobs() |
| 3055 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3056 | # If APScheduler is in mid-event when we remove the job, we |
| 3057 | # can end up with one more event firing, so give it an extra |
| 3058 | # second to settle. |
| 3059 | time.sleep(1) |
| 3060 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3061 | self.worker.release('.*') |
| 3062 | self.waitUntilSettled() |
| 3063 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3064 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3065 | "Test that the RPC client can enqueue a change" |
| 3066 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3067 | A.addApproval('Code-Review', 2) |
| 3068 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3069 | |
| 3070 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3071 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3072 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3073 | r = client.enqueue(tenant='tenant-one', |
| 3074 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3075 | project='org/project', |
| 3076 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3077 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3078 | self.waitUntilSettled() |
| 3079 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3080 | 'SUCCESS') |
| 3081 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3082 | 'SUCCESS') |
| 3083 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3084 | 'SUCCESS') |
| 3085 | self.assertEqual(A.data['status'], 'MERGED') |
| 3086 | self.assertEqual(A.reported, 2) |
| 3087 | self.assertEqual(r, True) |
| 3088 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3089 | def test_client_enqueue_ref(self): |
| 3090 | "Test that the RPC client can enqueue a ref" |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3091 | p = "review.example.com/org/project" |
| 3092 | upstream = self.getUpstreamRepos([p]) |
| 3093 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3094 | A.setMerged() |
| 3095 | A_commit = str(upstream[p].commit('master')) |
| 3096 | self.log.debug("A commit: %s" % A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3097 | |
| 3098 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3099 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3100 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3101 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3102 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3103 | pipeline='post', |
| 3104 | project='org/project', |
| 3105 | trigger='gerrit', |
| 3106 | ref='master', |
| 3107 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
James E. Blair | 289f593 | 2017-07-27 15:02:29 -0700 | [diff] [blame] | 3108 | newrev=A_commit) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3109 | self.waitUntilSettled() |
| 3110 | job_names = [x.name for x in self.history] |
| 3111 | self.assertEqual(len(self.history), 1) |
| 3112 | self.assertIn('project-post', job_names) |
| 3113 | self.assertEqual(r, True) |
| 3114 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3115 | def test_client_enqueue_negative(self): |
| 3116 | "Test that the RPC client returns errors" |
| 3117 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3118 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3119 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3120 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3121 | "Invalid tenant"): |
| 3122 | r = client.enqueue(tenant='tenant-foo', |
| 3123 | pipeline='gate', |
| 3124 | project='org/project', |
| 3125 | trigger='gerrit', |
| 3126 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3127 | self.assertEqual(r, False) |
| 3128 | |
| 3129 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3130 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3131 | r = client.enqueue(tenant='tenant-one', |
| 3132 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3133 | project='project-does-not-exist', |
| 3134 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3135 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3136 | self.assertEqual(r, False) |
| 3137 | |
| 3138 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3139 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3140 | r = client.enqueue(tenant='tenant-one', |
| 3141 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3142 | project='org/project', |
| 3143 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3144 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3145 | self.assertEqual(r, False) |
| 3146 | |
| 3147 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3148 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3149 | r = client.enqueue(tenant='tenant-one', |
| 3150 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3151 | project='org/project', |
| 3152 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3153 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3154 | self.assertEqual(r, False) |
| 3155 | |
| 3156 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3157 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3158 | r = client.enqueue(tenant='tenant-one', |
| 3159 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3160 | project='org/project', |
| 3161 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3162 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3163 | self.assertEqual(r, False) |
| 3164 | |
| 3165 | self.waitUntilSettled() |
| 3166 | self.assertEqual(len(self.history), 0) |
| 3167 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3168 | |
| 3169 | def test_client_promote(self): |
| 3170 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3171 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3172 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3173 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3174 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3175 | A.addApproval('Code-Review', 2) |
| 3176 | B.addApproval('Code-Review', 2) |
| 3177 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3178 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3179 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3180 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3181 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3182 | |
| 3183 | self.waitUntilSettled() |
| 3184 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3185 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3186 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3187 | enqueue_times = {} |
| 3188 | for item in items: |
| 3189 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3190 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3191 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3192 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3193 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3194 | r = client.promote(tenant='tenant-one', |
| 3195 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3196 | change_ids=['2,1', '3,1']) |
| 3197 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3198 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3199 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3200 | for item in items: |
| 3201 | self.assertEqual( |
| 3202 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3203 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3204 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3205 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3206 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3207 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3208 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3209 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | self.waitUntilSettled() |
| 3211 | |
| 3212 | self.assertEqual(len(self.builds), 6) |
| 3213 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3214 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3215 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3216 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3217 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3218 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3219 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3220 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3221 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3222 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3223 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3224 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3225 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3226 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3227 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3228 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3229 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3230 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3232 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3233 | self.waitUntilSettled() |
| 3234 | |
| 3235 | self.assertEqual(A.data['status'], 'MERGED') |
| 3236 | self.assertEqual(A.reported, 2) |
| 3237 | self.assertEqual(B.data['status'], 'MERGED') |
| 3238 | self.assertEqual(B.reported, 2) |
| 3239 | self.assertEqual(C.data['status'], 'MERGED') |
| 3240 | self.assertEqual(C.reported, 2) |
| 3241 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3242 | self.assertEqual(r, True) |
| 3243 | |
| 3244 | def test_client_promote_dependent(self): |
| 3245 | "Test that the RPC client can promote a dependent change" |
| 3246 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3247 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3248 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3249 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3250 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3251 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3252 | |
| 3253 | C.setDependsOn(B, 1) |
| 3254 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3255 | A.addApproval('Code-Review', 2) |
| 3256 | B.addApproval('Code-Review', 2) |
| 3257 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3258 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3259 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3260 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3261 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3262 | |
| 3263 | self.waitUntilSettled() |
| 3264 | |
| 3265 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3266 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3267 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3268 | r = client.promote(tenant='tenant-one', |
| 3269 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3270 | change_ids=['3,1']) |
| 3271 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3272 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3273 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3274 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3275 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3276 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3277 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3278 | self.waitUntilSettled() |
| 3279 | |
| 3280 | self.assertEqual(len(self.builds), 6) |
| 3281 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3282 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3283 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3284 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3285 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3286 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3287 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3288 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3289 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3290 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3291 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3292 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3293 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3294 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3295 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3296 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3297 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3298 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3299 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3300 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3301 | self.waitUntilSettled() |
| 3302 | |
| 3303 | self.assertEqual(A.data['status'], 'MERGED') |
| 3304 | self.assertEqual(A.reported, 2) |
| 3305 | self.assertEqual(B.data['status'], 'MERGED') |
| 3306 | self.assertEqual(B.reported, 2) |
| 3307 | self.assertEqual(C.data['status'], 'MERGED') |
| 3308 | self.assertEqual(C.reported, 2) |
| 3309 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3310 | self.assertEqual(r, True) |
| 3311 | |
| 3312 | def test_client_promote_negative(self): |
| 3313 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3314 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3315 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3316 | A.addApproval('Code-Review', 2) |
| 3317 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3318 | self.waitUntilSettled() |
| 3319 | |
| 3320 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3321 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3322 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3323 | |
| 3324 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3325 | r = client.promote(tenant='tenant-one', |
| 3326 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3327 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3328 | self.assertEqual(r, False) |
| 3329 | |
| 3330 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3331 | r = client.promote(tenant='tenant-one', |
| 3332 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3333 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3334 | self.assertEqual(r, False) |
| 3335 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3336 | self.executor_server.hold_jobs_in_build = False |
| 3337 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3338 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3339 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3340 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3341 | def test_queue_rate_limiting(self): |
| 3342 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3343 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3344 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3345 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3346 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3347 | |
| 3348 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3349 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3350 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3351 | A.addApproval('Code-Review', 2) |
| 3352 | B.addApproval('Code-Review', 2) |
| 3353 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3354 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3355 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3356 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3357 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3358 | self.waitUntilSettled() |
| 3359 | |
| 3360 | # Only A and B will have their merge jobs queued because |
| 3361 | # window is 2. |
| 3362 | self.assertEqual(len(self.builds), 2) |
| 3363 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3364 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3365 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3366 | # Release the merge jobs one at a time. |
| 3367 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3368 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3369 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3370 | self.waitUntilSettled() |
| 3371 | |
| 3372 | # Only A and B will have their test jobs queued because |
| 3373 | # window is 2. |
| 3374 | self.assertEqual(len(self.builds), 4) |
| 3375 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3376 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3377 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3378 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3379 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3380 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3381 | self.waitUntilSettled() |
| 3382 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3383 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3384 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3385 | # A failed so window is reduced by 1 to 1. |
| 3386 | self.assertEqual(queue.window, 1) |
| 3387 | self.assertEqual(queue.window_floor, 1) |
| 3388 | self.assertEqual(A.data['status'], 'NEW') |
| 3389 | |
| 3390 | # Gate is reset and only B's merge job is queued because |
| 3391 | # window shrunk to 1. |
| 3392 | self.assertEqual(len(self.builds), 1) |
| 3393 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3394 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3395 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3396 | self.waitUntilSettled() |
| 3397 | |
| 3398 | # Only B's test jobs are queued because window is still 1. |
| 3399 | self.assertEqual(len(self.builds), 2) |
| 3400 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3401 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3402 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3403 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3404 | self.waitUntilSettled() |
| 3405 | |
| 3406 | # B was successfully merged so window is increased to 2. |
| 3407 | self.assertEqual(queue.window, 2) |
| 3408 | self.assertEqual(queue.window_floor, 1) |
| 3409 | self.assertEqual(B.data['status'], 'MERGED') |
| 3410 | |
| 3411 | # Only C is left and its merge job is queued. |
| 3412 | self.assertEqual(len(self.builds), 1) |
| 3413 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3414 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3415 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3416 | self.waitUntilSettled() |
| 3417 | |
| 3418 | # After successful merge job the test jobs for C are queued. |
| 3419 | self.assertEqual(len(self.builds), 2) |
| 3420 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3421 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3422 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3423 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3424 | self.waitUntilSettled() |
| 3425 | |
| 3426 | # C successfully merged so window is bumped to 3. |
| 3427 | self.assertEqual(queue.window, 3) |
| 3428 | self.assertEqual(queue.window_floor, 1) |
| 3429 | self.assertEqual(C.data['status'], 'MERGED') |
| 3430 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3431 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3432 | def test_queue_rate_limiting_dependent(self): |
| 3433 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3434 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3435 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3436 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3437 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3438 | |
| 3439 | B.setDependsOn(A, 1) |
| 3440 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3441 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3442 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3443 | A.addApproval('Code-Review', 2) |
| 3444 | B.addApproval('Code-Review', 2) |
| 3445 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3446 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3447 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3448 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3449 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3450 | self.waitUntilSettled() |
| 3451 | |
| 3452 | # Only A and B will have their merge jobs queued because |
| 3453 | # window is 2. |
| 3454 | self.assertEqual(len(self.builds), 2) |
| 3455 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3456 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3457 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3458 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3459 | |
| 3460 | # Only A and B will have their test jobs queued because |
| 3461 | # window is 2. |
| 3462 | self.assertEqual(len(self.builds), 4) |
| 3463 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3464 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3465 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3466 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3467 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3468 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3469 | self.waitUntilSettled() |
| 3470 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3471 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3472 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3473 | # A failed so window is reduced by 1 to 1. |
| 3474 | self.assertEqual(queue.window, 1) |
| 3475 | self.assertEqual(queue.window_floor, 1) |
| 3476 | self.assertEqual(A.data['status'], 'NEW') |
| 3477 | self.assertEqual(B.data['status'], 'NEW') |
| 3478 | |
| 3479 | # Gate is reset and only C's merge job is queued because |
| 3480 | # window shrunk to 1 and A and B were dequeued. |
| 3481 | self.assertEqual(len(self.builds), 1) |
| 3482 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3483 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3484 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3485 | |
| 3486 | # Only C's test jobs are queued because window is still 1. |
| 3487 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3488 | builds = self.getSortedBuilds() |
| 3489 | self.assertEqual(builds[0].name, 'project-test1') |
| 3490 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3491 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3492 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3493 | self.waitUntilSettled() |
| 3494 | |
| 3495 | # C was successfully merged so window is increased to 2. |
| 3496 | self.assertEqual(queue.window, 2) |
| 3497 | self.assertEqual(queue.window_floor, 1) |
| 3498 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3499 | |
| 3500 | def test_worker_update_metadata(self): |
| 3501 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3502 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3503 | |
| 3504 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3505 | A.addApproval('Code-Review', 2) |
| 3506 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3507 | self.waitUntilSettled() |
| 3508 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3509 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3510 | |
| 3511 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3512 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3513 | |
| 3514 | start = time.time() |
| 3515 | while True: |
| 3516 | if time.time() - start > 10: |
| 3517 | raise Exception("Timeout waiting for gearman server to report " |
| 3518 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3519 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3520 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3521 | break |
| 3522 | else: |
| 3523 | time.sleep(0) |
| 3524 | |
| 3525 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3526 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3528 | self.executor_server.hold_jobs_in_build = False |
| 3529 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3530 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3531 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3532 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3533 | def test_footer_message(self): |
| 3534 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3535 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3536 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3537 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3538 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3539 | self.waitUntilSettled() |
| 3540 | |
| 3541 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3542 | B.addApproval('Code-Review', 2) |
| 3543 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3544 | self.waitUntilSettled() |
| 3545 | |
| 3546 | self.assertEqual(2, len(self.smtp_messages)) |
| 3547 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3548 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3549 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3550 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3551 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3552 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3553 | For CI problems and help debugging, contact ci@example.org""" |
| 3554 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3555 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3556 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3557 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3558 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3559 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3560 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3561 | def test_unmanaged_project_start_message(self): |
| 3562 | "Test start reporting is not done for unmanaged projects." |
| 3563 | self.init_repo("org/project", tag='init') |
| 3564 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3565 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3566 | self.waitUntilSettled() |
| 3567 | |
| 3568 | self.assertEqual(0, len(A.messages)) |
| 3569 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3570 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3571 | def test_merge_failure_reporters(self): |
| 3572 | """Check that the config is set up correctly""" |
| 3573 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3574 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3575 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3576 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3577 | "dependencies was unable to be automatically merged with the " |
| 3578 | "current state of its repository. Please rebase the change and " |
| 3579 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3580 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3581 | self.assertEqual( |
| 3582 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3583 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3584 | |
| 3585 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3586 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3587 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3588 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3589 | |
| 3590 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3591 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3592 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3593 | |
| 3594 | self.assertTrue( |
| 3595 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3596 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3597 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3598 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3599 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3600 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3601 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3602 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3603 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3604 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3605 | gerritreporter.GerritReporter) and |
| 3606 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3607 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3608 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3609 | ) |
| 3610 | ) |
| 3611 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3612 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3613 | def test_merge_failure_reports(self): |
| 3614 | """Check that when a change fails to merge the correct message is sent |
| 3615 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3616 | self.updateConfigLayout( |
| 3617 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3618 | self.sched.reconfigure(self.config) |
| 3619 | self.registerJobs() |
| 3620 | |
| 3621 | # Check a test failure isn't reported to SMTP |
| 3622 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3623 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3624 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3625 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3626 | self.waitUntilSettled() |
| 3627 | |
| 3628 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3629 | self.assertEqual(0, len(self.smtp_messages)) |
| 3630 | |
| 3631 | # Check a merge failure is reported to SMTP |
| 3632 | # B should be merged, but C will conflict with B |
| 3633 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3634 | B.addPatchset(['conflict']) |
| 3635 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3636 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3637 | B.addApproval('Code-Review', 2) |
| 3638 | C.addApproval('Code-Review', 2) |
| 3639 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3640 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3641 | self.waitUntilSettled() |
| 3642 | |
| 3643 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3644 | self.assertEqual(1, len(self.smtp_messages)) |
| 3645 | self.assertEqual('The merge failed! For more information...', |
| 3646 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3647 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3648 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3649 | def test_default_merge_failure_reports(self): |
| 3650 | """Check that the default merge failure reports are correct.""" |
| 3651 | |
| 3652 | # A should report success, B should report merge failure. |
| 3653 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3654 | A.addPatchset(['conflict']) |
| 3655 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3656 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3657 | A.addApproval('Code-Review', 2) |
| 3658 | B.addApproval('Code-Review', 2) |
| 3659 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3660 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3661 | self.waitUntilSettled() |
| 3662 | |
| 3663 | self.assertEqual(3, len(self.history)) # A jobs |
| 3664 | self.assertEqual(A.reported, 2) |
| 3665 | self.assertEqual(B.reported, 2) |
| 3666 | self.assertEqual(A.data['status'], 'MERGED') |
| 3667 | self.assertEqual(B.data['status'], 'NEW') |
| 3668 | self.assertIn('Build succeeded', A.messages[1]) |
| 3669 | self.assertIn('Merge Failed', B.messages[1]) |
| 3670 | self.assertIn('automatically merged', B.messages[1]) |
| 3671 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3672 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3673 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3674 | def test_client_get_running_jobs(self): |
| 3675 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3676 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3677 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3678 | A.addApproval('Code-Review', 2) |
| 3679 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3680 | self.waitUntilSettled() |
| 3681 | |
| 3682 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3683 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3684 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3685 | |
| 3686 | # Wait for gearman server to send the initial workData back to zuul |
| 3687 | start = time.time() |
| 3688 | while True: |
| 3689 | if time.time() - start > 10: |
| 3690 | raise Exception("Timeout waiting for gearman server to report " |
| 3691 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3692 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3693 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3694 | break |
| 3695 | else: |
| 3696 | time.sleep(0) |
| 3697 | |
| 3698 | running_items = client.get_running_jobs() |
| 3699 | |
| 3700 | self.assertEqual(1, len(running_items)) |
| 3701 | running_item = running_items[0] |
| 3702 | self.assertEqual([], running_item['failing_reasons']) |
| 3703 | self.assertEqual([], running_item['items_behind']) |
| 3704 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3705 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3706 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3707 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3708 | self.assertEqual(True, running_item['active']) |
| 3709 | self.assertEqual('1,1', running_item['id']) |
| 3710 | |
| 3711 | self.assertEqual(3, len(running_item['jobs'])) |
| 3712 | for job in running_item['jobs']: |
| 3713 | if job['name'] == 'project-merge': |
| 3714 | self.assertEqual('project-merge', job['name']) |
| 3715 | self.assertEqual('gate', job['pipeline']) |
| 3716 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3717 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3718 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3719 | .format(uuid=job['uuid']), job['url']) |
| 3720 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3721 | 'finger://{hostname}/{uuid}'.format( |
| 3722 | hostname=self.executor_server.hostname, |
| 3723 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3724 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3725 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3726 | self.assertEqual(False, job['canceled']) |
| 3727 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3728 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3729 | self.assertEqual('gate', job['pipeline']) |
| 3730 | break |
| 3731 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3732 | self.executor_server.hold_jobs_in_build = False |
| 3733 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3734 | self.waitUntilSettled() |
| 3735 | |
| 3736 | running_items = client.get_running_jobs() |
| 3737 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3738 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3739 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3740 | def test_nonvoting_pipeline(self): |
| 3741 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3742 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3743 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3744 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3745 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3746 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3747 | |
| 3748 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3749 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3750 | self.assertEqual( |
| 3751 | self.getJobFromHistory('experimental-project-test').result, |
| 3752 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3753 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3754 | |
| 3755 | def test_crd_gate(self): |
| 3756 | "Test cross-repo dependencies" |
| 3757 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3758 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3759 | A.addApproval('Code-Review', 2) |
| 3760 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3761 | |
| 3762 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3763 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3764 | AM2.setMerged() |
| 3765 | AM1.setMerged() |
| 3766 | |
| 3767 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3768 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3769 | BM2.setMerged() |
| 3770 | BM1.setMerged() |
| 3771 | |
| 3772 | # A -> AM1 -> AM2 |
| 3773 | # B -> BM1 -> BM2 |
| 3774 | # A Depends-On: B |
| 3775 | # M2 is here to make sure it is never queried. If it is, it |
| 3776 | # means zuul is walking down the entire history of merged |
| 3777 | # changes. |
| 3778 | |
| 3779 | B.setDependsOn(BM1, 1) |
| 3780 | BM1.setDependsOn(BM2, 1) |
| 3781 | |
| 3782 | A.setDependsOn(AM1, 1) |
| 3783 | AM1.setDependsOn(AM2, 1) |
| 3784 | |
| 3785 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3786 | A.subject, B.data['id']) |
| 3787 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3788 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3789 | self.waitUntilSettled() |
| 3790 | |
| 3791 | self.assertEqual(A.data['status'], 'NEW') |
| 3792 | self.assertEqual(B.data['status'], 'NEW') |
| 3793 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3794 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3795 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3796 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3797 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3798 | B.addApproval('Approved', 1) |
| 3799 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3800 | self.waitUntilSettled() |
| 3801 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3802 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3803 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3804 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3805 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3806 | self.executor_server.hold_jobs_in_build = False |
| 3807 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3808 | self.waitUntilSettled() |
| 3809 | |
| 3810 | self.assertEqual(AM2.queried, 0) |
| 3811 | self.assertEqual(BM2.queried, 0) |
| 3812 | self.assertEqual(A.data['status'], 'MERGED') |
| 3813 | self.assertEqual(B.data['status'], 'MERGED') |
| 3814 | self.assertEqual(A.reported, 2) |
| 3815 | self.assertEqual(B.reported, 2) |
| 3816 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3817 | changes = self.getJobFromHistory( |
| 3818 | 'project-merge', 'org/project1').changes |
| 3819 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3820 | |
| 3821 | def test_crd_branch(self): |
| 3822 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3823 | |
| 3824 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3825 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3826 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3827 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3828 | C.data['id'] = B.data['id'] |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3829 | A.addApproval('Code-Review', 2) |
| 3830 | B.addApproval('Code-Review', 2) |
| 3831 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3832 | |
| 3833 | # A Depends-On: B+C |
| 3834 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3835 | A.subject, B.data['id']) |
| 3836 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3837 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3838 | B.addApproval('Approved', 1) |
| 3839 | C.addApproval('Approved', 1) |
| 3840 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3841 | self.waitUntilSettled() |
| 3842 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3843 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3844 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3845 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3846 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3847 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3848 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3849 | self.executor_server.hold_jobs_in_build = False |
| 3850 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3851 | self.waitUntilSettled() |
| 3852 | |
| 3853 | self.assertEqual(A.data['status'], 'MERGED') |
| 3854 | self.assertEqual(B.data['status'], 'MERGED') |
| 3855 | self.assertEqual(C.data['status'], 'MERGED') |
| 3856 | self.assertEqual(A.reported, 2) |
| 3857 | self.assertEqual(B.reported, 2) |
| 3858 | self.assertEqual(C.reported, 2) |
| 3859 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3860 | changes = self.getJobFromHistory( |
| 3861 | 'project-merge', 'org/project1').changes |
| 3862 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3863 | |
| 3864 | def test_crd_multiline(self): |
| 3865 | "Test multiple depends-on lines in commit" |
| 3866 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3867 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3868 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3869 | A.addApproval('Code-Review', 2) |
| 3870 | B.addApproval('Code-Review', 2) |
| 3871 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3872 | |
| 3873 | # A Depends-On: B+C |
| 3874 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3875 | A.subject, B.data['id'], C.data['id']) |
| 3876 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3877 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3878 | B.addApproval('Approved', 1) |
| 3879 | C.addApproval('Approved', 1) |
| 3880 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3881 | self.waitUntilSettled() |
| 3882 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3883 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3884 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3885 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3886 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3887 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3888 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3889 | self.executor_server.hold_jobs_in_build = False |
| 3890 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3891 | self.waitUntilSettled() |
| 3892 | |
| 3893 | self.assertEqual(A.data['status'], 'MERGED') |
| 3894 | self.assertEqual(B.data['status'], 'MERGED') |
| 3895 | self.assertEqual(C.data['status'], 'MERGED') |
| 3896 | self.assertEqual(A.reported, 2) |
| 3897 | self.assertEqual(B.reported, 2) |
| 3898 | self.assertEqual(C.reported, 2) |
| 3899 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3900 | changes = self.getJobFromHistory( |
| 3901 | 'project-merge', 'org/project1').changes |
| 3902 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3903 | |
| 3904 | def test_crd_unshared_gate(self): |
| 3905 | "Test cross-repo dependencies in unshared gate queues" |
| 3906 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3907 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3908 | A.addApproval('Code-Review', 2) |
| 3909 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3910 | |
| 3911 | # A Depends-On: B |
| 3912 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3913 | A.subject, B.data['id']) |
| 3914 | |
| 3915 | # A and B do not share a queue, make sure that A is unable to |
| 3916 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3917 | B.addApproval('Approved', 1) |
| 3918 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3919 | self.waitUntilSettled() |
| 3920 | |
| 3921 | self.assertEqual(A.data['status'], 'NEW') |
| 3922 | self.assertEqual(B.data['status'], 'NEW') |
| 3923 | self.assertEqual(A.reported, 0) |
| 3924 | self.assertEqual(B.reported, 0) |
| 3925 | self.assertEqual(len(self.history), 0) |
| 3926 | |
| 3927 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3928 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3929 | self.waitUntilSettled() |
| 3930 | |
| 3931 | self.assertEqual(B.data['status'], 'MERGED') |
| 3932 | self.assertEqual(B.reported, 2) |
| 3933 | |
| 3934 | # Now that B is merged, A should be able to be enqueued and |
| 3935 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3936 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3937 | self.waitUntilSettled() |
| 3938 | |
| 3939 | self.assertEqual(A.data['status'], 'MERGED') |
| 3940 | self.assertEqual(A.reported, 2) |
| 3941 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3942 | def test_crd_gate_reverse(self): |
| 3943 | "Test reverse cross-repo dependencies" |
| 3944 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3945 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3946 | A.addApproval('Code-Review', 2) |
| 3947 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3948 | |
| 3949 | # A Depends-On: B |
| 3950 | |
| 3951 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3952 | A.subject, B.data['id']) |
| 3953 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3954 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3955 | self.waitUntilSettled() |
| 3956 | |
| 3957 | self.assertEqual(A.data['status'], 'NEW') |
| 3958 | self.assertEqual(B.data['status'], 'NEW') |
| 3959 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3960 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3961 | A.addApproval('Approved', 1) |
| 3962 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3963 | self.waitUntilSettled() |
| 3964 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3965 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3966 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3967 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3968 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3969 | self.executor_server.hold_jobs_in_build = False |
| 3970 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3971 | self.waitUntilSettled() |
| 3972 | |
| 3973 | self.assertEqual(A.data['status'], 'MERGED') |
| 3974 | self.assertEqual(B.data['status'], 'MERGED') |
| 3975 | self.assertEqual(A.reported, 2) |
| 3976 | self.assertEqual(B.reported, 2) |
| 3977 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3978 | changes = self.getJobFromHistory( |
| 3979 | 'project-merge', 'org/project1').changes |
| 3980 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3981 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3982 | def test_crd_cycle(self): |
| 3983 | "Test cross-repo dependency cycles" |
| 3984 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3985 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3986 | A.addApproval('Code-Review', 2) |
| 3987 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3988 | |
| 3989 | # A -> B -> A (via commit-depends) |
| 3990 | |
| 3991 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3992 | A.subject, B.data['id']) |
| 3993 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3994 | B.subject, A.data['id']) |
| 3995 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3996 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3997 | self.waitUntilSettled() |
| 3998 | |
| 3999 | self.assertEqual(A.reported, 0) |
| 4000 | self.assertEqual(B.reported, 0) |
| 4001 | self.assertEqual(A.data['status'], 'NEW') |
| 4002 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4003 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4004 | def test_crd_gate_unknown(self): |
| 4005 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4006 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4007 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4008 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4009 | A.addApproval('Code-Review', 2) |
| 4010 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4011 | |
| 4012 | # A Depends-On: B |
| 4013 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4014 | A.subject, B.data['id']) |
| 4015 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4016 | B.addApproval('Approved', 1) |
| 4017 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4018 | self.waitUntilSettled() |
| 4019 | |
| 4020 | # Unknown projects cannot share a queue with any other |
| 4021 | # since they don't have common jobs with any other (they have no jobs). |
| 4022 | # Changes which depend on unknown project changes |
| 4023 | # should not be processed in dependent pipeline |
| 4024 | self.assertEqual(A.data['status'], 'NEW') |
| 4025 | self.assertEqual(B.data['status'], 'NEW') |
| 4026 | self.assertEqual(A.reported, 0) |
| 4027 | self.assertEqual(B.reported, 0) |
| 4028 | self.assertEqual(len(self.history), 0) |
| 4029 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4030 | # Simulate change B being gated outside this layout Set the |
| 4031 | # change merged before submitting the event so that when the |
| 4032 | # event triggers a gerrit query to update the change, we get |
| 4033 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4034 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4035 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4036 | self.waitUntilSettled() |
| 4037 | self.assertEqual(len(self.history), 0) |
| 4038 | |
| 4039 | # Now that B is merged, A should be able to be enqueued and |
| 4040 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4041 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4042 | self.waitUntilSettled() |
| 4043 | |
| 4044 | self.assertEqual(A.data['status'], 'MERGED') |
| 4045 | self.assertEqual(A.reported, 2) |
| 4046 | self.assertEqual(B.data['status'], 'MERGED') |
| 4047 | self.assertEqual(B.reported, 0) |
| 4048 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4049 | def test_crd_check(self): |
| 4050 | "Test cross-repo dependencies in independent pipelines" |
| 4051 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4052 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4053 | self.gearman_server.hold_jobs_in_queue = True |
| 4054 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4055 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4056 | |
| 4057 | # A Depends-On: B |
| 4058 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4059 | A.subject, B.data['id']) |
| 4060 | |
| 4061 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4062 | self.waitUntilSettled() |
| 4063 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4064 | self.gearman_server.hold_jobs_in_queue = False |
| 4065 | self.gearman_server.release() |
| 4066 | self.waitUntilSettled() |
| 4067 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4068 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4069 | self.waitUntilSettled() |
| 4070 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4071 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4072 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4073 | self.executor_server.hold_jobs_in_build = False |
| 4074 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4075 | self.waitUntilSettled() |
| 4076 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4077 | self.assertEqual(A.data['status'], 'NEW') |
| 4078 | self.assertEqual(B.data['status'], 'NEW') |
| 4079 | self.assertEqual(A.reported, 1) |
| 4080 | self.assertEqual(B.reported, 0) |
| 4081 | |
| 4082 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4083 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4084 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4085 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4086 | def test_crd_check_git_depends(self): |
| 4087 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4088 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4089 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4090 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4091 | |
| 4092 | # Add two git-dependent changes and make sure they both report |
| 4093 | # success. |
| 4094 | B.setDependsOn(A, 1) |
| 4095 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4096 | self.waitUntilSettled() |
| 4097 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4098 | self.waitUntilSettled() |
| 4099 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4100 | self.orderedRelease() |
| 4101 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4102 | self.waitUntilSettled() |
| 4103 | |
| 4104 | self.assertEqual(A.data['status'], 'NEW') |
| 4105 | self.assertEqual(B.data['status'], 'NEW') |
| 4106 | self.assertEqual(A.reported, 1) |
| 4107 | self.assertEqual(B.reported, 1) |
| 4108 | |
| 4109 | self.assertEqual(self.history[0].changes, '1,1') |
| 4110 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4111 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4112 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4113 | |
| 4114 | self.assertIn('Build succeeded', A.messages[0]) |
| 4115 | self.assertIn('Build succeeded', B.messages[0]) |
| 4116 | |
| 4117 | def test_crd_check_duplicate(self): |
| 4118 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4119 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4120 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4121 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4122 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4123 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4124 | |
| 4125 | # Add two git-dependent changes... |
| 4126 | B.setDependsOn(A, 1) |
| 4127 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4128 | self.waitUntilSettled() |
| 4129 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4130 | |
| 4131 | # ...make sure the live one is not duplicated... |
| 4132 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4133 | self.waitUntilSettled() |
| 4134 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4135 | |
| 4136 | # ...but the non-live one is able to be. |
| 4137 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4138 | self.waitUntilSettled() |
| 4139 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4140 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4141 | # Release jobs in order to avoid races with change A jobs |
| 4142 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4143 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4144 | self.executor_server.hold_jobs_in_build = False |
| 4145 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4146 | self.waitUntilSettled() |
| 4147 | |
| 4148 | self.assertEqual(A.data['status'], 'NEW') |
| 4149 | self.assertEqual(B.data['status'], 'NEW') |
| 4150 | self.assertEqual(A.reported, 1) |
| 4151 | self.assertEqual(B.reported, 1) |
| 4152 | |
| 4153 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4154 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4155 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4156 | |
| 4157 | self.assertIn('Build succeeded', A.messages[0]) |
| 4158 | self.assertIn('Build succeeded', B.messages[0]) |
| 4159 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4160 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4161 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4162 | |
| 4163 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4164 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4165 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4166 | |
| 4167 | # A Depends-On: B |
| 4168 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4169 | A.subject, B.data['id']) |
| 4170 | |
| 4171 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4172 | self.waitUntilSettled() |
| 4173 | |
| 4174 | self.sched.reconfigure(self.config) |
| 4175 | |
| 4176 | # Make sure the items still share a change queue, and the |
| 4177 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4178 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4179 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4180 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4181 | first_item = queue.queue[0] |
| 4182 | for item in queue.queue: |
| 4183 | self.assertEqual(item.queue, first_item.queue) |
| 4184 | self.assertFalse(first_item.live) |
| 4185 | self.assertTrue(queue.queue[1].live) |
| 4186 | |
| 4187 | self.gearman_server.hold_jobs_in_queue = False |
| 4188 | self.gearman_server.release() |
| 4189 | self.waitUntilSettled() |
| 4190 | |
| 4191 | self.assertEqual(A.data['status'], 'NEW') |
| 4192 | self.assertEqual(B.data['status'], 'NEW') |
| 4193 | self.assertEqual(A.reported, 1) |
| 4194 | self.assertEqual(B.reported, 0) |
| 4195 | |
| 4196 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4197 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4198 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4199 | def test_crd_check_reconfiguration(self): |
| 4200 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4201 | |
| 4202 | def test_crd_undefined_project(self): |
| 4203 | """Test that undefined projects in dependencies are handled for |
| 4204 | independent pipelines""" |
| 4205 | # It's a hack for fake gerrit, |
| 4206 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4207 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4208 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4209 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4210 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4211 | def test_crd_check_ignore_dependencies(self): |
| 4212 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4213 | |
| 4214 | self.gearman_server.hold_jobs_in_queue = True |
| 4215 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4216 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4217 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4218 | |
| 4219 | # A Depends-On: B |
| 4220 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4221 | A.subject, B.data['id']) |
| 4222 | # C git-depends on B |
| 4223 | C.setDependsOn(B, 1) |
| 4224 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4225 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4226 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4227 | self.waitUntilSettled() |
| 4228 | |
| 4229 | # Make sure none of the items share a change queue, and all |
| 4230 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4231 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4232 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4233 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4234 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4235 | for item in check_pipeline.getAllItems(): |
| 4236 | self.assertTrue(item.live) |
| 4237 | |
| 4238 | self.gearman_server.hold_jobs_in_queue = False |
| 4239 | self.gearman_server.release() |
| 4240 | self.waitUntilSettled() |
| 4241 | |
| 4242 | self.assertEqual(A.data['status'], 'NEW') |
| 4243 | self.assertEqual(B.data['status'], 'NEW') |
| 4244 | self.assertEqual(C.data['status'], 'NEW') |
| 4245 | self.assertEqual(A.reported, 1) |
| 4246 | self.assertEqual(B.reported, 1) |
| 4247 | self.assertEqual(C.reported, 1) |
| 4248 | |
| 4249 | # Each job should have tested exactly one change |
| 4250 | for job in self.history: |
| 4251 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4252 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4253 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4254 | def test_crd_check_transitive(self): |
| 4255 | "Test transitive cross-repo dependencies" |
| 4256 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4257 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4258 | # and C,2 (not C,1 which would indicate stale data in the |
| 4259 | # cache for B). |
| 4260 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4261 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4262 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4263 | |
| 4264 | # A Depends-On: B |
| 4265 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4266 | A.subject, B.data['id']) |
| 4267 | |
| 4268 | # B Depends-On: C |
| 4269 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4270 | B.subject, C.data['id']) |
| 4271 | |
| 4272 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4273 | self.waitUntilSettled() |
| 4274 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4275 | |
| 4276 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4277 | self.waitUntilSettled() |
| 4278 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4279 | |
| 4280 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4281 | self.waitUntilSettled() |
| 4282 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4283 | |
| 4284 | C.addPatchset() |
| 4285 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4286 | self.waitUntilSettled() |
| 4287 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4288 | |
| 4289 | A.addPatchset() |
| 4290 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4291 | self.waitUntilSettled() |
| 4292 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4293 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4294 | def test_crd_check_unknown(self): |
| 4295 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4296 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4297 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4298 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4299 | # A Depends-On: B |
| 4300 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4301 | A.subject, B.data['id']) |
| 4302 | |
| 4303 | # Make sure zuul has seen an event on B. |
| 4304 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4305 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4306 | self.waitUntilSettled() |
| 4307 | |
| 4308 | self.assertEqual(A.data['status'], 'NEW') |
| 4309 | self.assertEqual(A.reported, 1) |
| 4310 | self.assertEqual(B.data['status'], 'NEW') |
| 4311 | self.assertEqual(B.reported, 0) |
| 4312 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4313 | def test_crd_cycle_join(self): |
| 4314 | "Test an updated change creates a cycle" |
| 4315 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4316 | |
| 4317 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4318 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4319 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4320 | |
| 4321 | # Create B->A |
| 4322 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4323 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4324 | B.subject, A.data['id']) |
| 4325 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4326 | self.waitUntilSettled() |
| 4327 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4328 | # Dep is there so zuul should have reported on B |
| 4329 | self.assertEqual(B.reported, 1) |
| 4330 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4331 | # Update A to add A->B (a cycle). |
| 4332 | A.addPatchset() |
| 4333 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4334 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4335 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4336 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4337 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4338 | # Dependency cycle injected so zuul should not have reported again on A |
| 4339 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4340 | |
| 4341 | # Now if we update B to remove the depends-on, everything |
| 4342 | # should be okay. B; A->B |
| 4343 | |
| 4344 | B.addPatchset() |
| 4345 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4346 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4347 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4348 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4349 | # Cycle was removed so now zuul should have reported again on A |
| 4350 | self.assertEqual(A.reported, 2) |
| 4351 | |
| 4352 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4353 | self.waitUntilSettled() |
| 4354 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4355 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4356 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4357 | def test_disable_at(self): |
| 4358 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4359 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4360 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4361 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4362 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4363 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4364 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4365 | |
| 4366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4367 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4368 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4369 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4370 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4371 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4372 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4373 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4374 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4375 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4376 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4377 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4378 | self.executor_server.failJob('project-test1', A) |
| 4379 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4380 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4381 | self.executor_server.failJob('project-test1', D) |
| 4382 | self.executor_server.failJob('project-test1', E) |
| 4383 | self.executor_server.failJob('project-test1', F) |
| 4384 | self.executor_server.failJob('project-test1', G) |
| 4385 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4386 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4387 | self.executor_server.failJob('project-test1', J) |
| 4388 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4389 | |
| 4390 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4391 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4392 | self.waitUntilSettled() |
| 4393 | |
| 4394 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4395 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4396 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4397 | |
| 4398 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4399 | self.waitUntilSettled() |
| 4400 | |
| 4401 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4402 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4403 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4404 | |
| 4405 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4406 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4407 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4408 | self.waitUntilSettled() |
| 4409 | |
| 4410 | # We should be disabled now |
| 4411 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4412 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4413 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4414 | |
| 4415 | # We need to wait between each of these patches to make sure the |
| 4416 | # smtp messages come back in an expected order |
| 4417 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4418 | self.waitUntilSettled() |
| 4419 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4420 | self.waitUntilSettled() |
| 4421 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4422 | self.waitUntilSettled() |
| 4423 | |
| 4424 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4425 | # leaving a message on each change |
| 4426 | self.assertEqual(1, len(A.messages)) |
| 4427 | self.assertIn('Build failed.', A.messages[0]) |
| 4428 | self.assertEqual(1, len(B.messages)) |
| 4429 | self.assertIn('Build failed.', B.messages[0]) |
| 4430 | self.assertEqual(1, len(C.messages)) |
| 4431 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4432 | self.assertEqual(1, len(D.messages)) |
| 4433 | self.assertIn('Build failed.', D.messages[0]) |
| 4434 | self.assertEqual(1, len(E.messages)) |
| 4435 | self.assertIn('Build failed.', E.messages[0]) |
| 4436 | self.assertEqual(1, len(F.messages)) |
| 4437 | self.assertIn('Build failed.', F.messages[0]) |
| 4438 | |
| 4439 | # The last 3 (GHI) would have only reported via smtp. |
| 4440 | self.assertEqual(3, len(self.smtp_messages)) |
| 4441 | self.assertEqual(0, len(G.messages)) |
| 4442 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4443 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4444 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4445 | self.assertEqual(0, len(H.messages)) |
| 4446 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4447 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4448 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4449 | self.assertEqual(0, len(I.messages)) |
| 4450 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4451 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4452 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4453 | |
| 4454 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4455 | # comes out of disabled |
| 4456 | self.sched.reconfigure(self.config) |
| 4457 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4458 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4459 | |
| 4460 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4461 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4462 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4463 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4464 | |
| 4465 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4466 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4467 | self.waitUntilSettled() |
| 4468 | |
| 4469 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4470 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4471 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4472 | |
| 4473 | # J and K went back to gerrit |
| 4474 | self.assertEqual(1, len(J.messages)) |
| 4475 | self.assertIn('Build failed.', J.messages[0]) |
| 4476 | self.assertEqual(1, len(K.messages)) |
| 4477 | self.assertIn('Build failed.', K.messages[0]) |
| 4478 | # No more messages reported via smtp |
| 4479 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4480 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4481 | @simple_layout('layouts/one-job-project.yaml') |
| 4482 | def test_one_job_project(self): |
| 4483 | "Test that queueing works with one job" |
| 4484 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4485 | 'master', 'A') |
| 4486 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4487 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4488 | A.addApproval('Code-Review', 2) |
| 4489 | B.addApproval('Code-Review', 2) |
| 4490 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4491 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4492 | self.waitUntilSettled() |
| 4493 | |
| 4494 | self.assertEqual(A.data['status'], 'MERGED') |
| 4495 | self.assertEqual(A.reported, 2) |
| 4496 | self.assertEqual(B.data['status'], 'MERGED') |
| 4497 | self.assertEqual(B.reported, 2) |
| 4498 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4499 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4500 | "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] | 4501 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4502 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4503 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4504 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4505 | self.waitUntilSettled() |
| 4506 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4507 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4508 | self.waitUntilSettled() |
| 4509 | |
| 4510 | self.assertEqual(len(self.builds), 2) |
| 4511 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4512 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4513 | self.waitUntilSettled() |
| 4514 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4515 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4516 | self.assertEqual(len(self.builds), 1, |
| 4517 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4518 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4519 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4520 | self.waitUntilSettled() |
| 4521 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4522 | self.executor_server.hold_jobs_in_build = False |
| 4523 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4524 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4525 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4526 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4527 | self.assertEqual(A.reported, 1) |
| 4528 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4529 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4530 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4531 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4532 | |
| 4533 | self.fake_nodepool.paused = True |
| 4534 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4535 | A.addApproval('Code-Review', 2) |
| 4536 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4537 | self.waitUntilSettled() |
| 4538 | |
| 4539 | self.zk.client.stop() |
| 4540 | self.zk.client.start() |
| 4541 | self.fake_nodepool.paused = False |
| 4542 | self.waitUntilSettled() |
| 4543 | |
| 4544 | self.assertEqual(A.data['status'], 'MERGED') |
| 4545 | self.assertEqual(A.reported, 2) |
| 4546 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4547 | def test_nodepool_failure(self): |
| 4548 | "Test that jobs are reported after a nodepool failure" |
| 4549 | |
| 4550 | self.fake_nodepool.paused = True |
| 4551 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4552 | A.addApproval('Code-Review', 2) |
| 4553 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4554 | self.waitUntilSettled() |
| 4555 | |
| 4556 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4557 | self.fake_nodepool.addFailRequest(req) |
| 4558 | |
| 4559 | self.fake_nodepool.paused = False |
| 4560 | self.waitUntilSettled() |
| 4561 | |
| 4562 | self.assertEqual(A.data['status'], 'NEW') |
| 4563 | self.assertEqual(A.reported, 2) |
| 4564 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4565 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4566 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4567 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4568 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4569 | class TestExecutor(ZuulTestCase): |
| 4570 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4571 | |
| 4572 | def assertFinalState(self): |
| 4573 | # In this test, we expect to shut down in a non-final state, |
| 4574 | # so skip these checks. |
| 4575 | pass |
| 4576 | |
| 4577 | def assertCleanShutdown(self): |
| 4578 | self.log.debug("Assert clean shutdown") |
| 4579 | |
| 4580 | # After shutdown, make sure no jobs are running |
| 4581 | self.assertEqual({}, self.executor_server.job_workers) |
| 4582 | |
| 4583 | # Make sure that git.Repo objects have been garbage collected. |
| 4584 | repos = [] |
| 4585 | gc.collect() |
| 4586 | for obj in gc.get_objects(): |
| 4587 | if isinstance(obj, git.Repo): |
| 4588 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4589 | repos.append(obj) |
| 4590 | self.assertEqual(len(repos), 0) |
| 4591 | |
| 4592 | def test_executor_shutdown(self): |
| 4593 | "Test that the executor can shut down with jobs running" |
| 4594 | |
| 4595 | self.executor_server.hold_jobs_in_build = True |
| 4596 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4597 | A.addApproval('Code-Review', 2) |
| 4598 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4599 | self.waitUntilSettled() |
| 4600 | |
| 4601 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4602 | class TestDependencyGraph(ZuulTestCase): |
| 4603 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4604 | |
| 4605 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4606 | "Test a job in a dependency graph is queued only once" |
| 4607 | # Job dependencies, starting with A |
| 4608 | # A |
| 4609 | # / \ |
| 4610 | # B C |
| 4611 | # / \ / \ |
| 4612 | # D F E |
| 4613 | # | |
| 4614 | # G |
| 4615 | |
| 4616 | self.executor_server.hold_jobs_in_build = True |
| 4617 | change = self.fake_gerrit.addFakeChange( |
| 4618 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4619 | change.addApproval('Code-Review', 2) |
| 4620 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4621 | |
| 4622 | self.waitUntilSettled() |
| 4623 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4624 | |
| 4625 | self.executor_server.release('A') |
| 4626 | self.waitUntilSettled() |
| 4627 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4628 | |
| 4629 | self.executor_server.release('B') |
| 4630 | self.waitUntilSettled() |
| 4631 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4632 | |
| 4633 | self.executor_server.release('D') |
| 4634 | self.waitUntilSettled() |
| 4635 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4636 | |
| 4637 | self.executor_server.release('C') |
| 4638 | self.waitUntilSettled() |
| 4639 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4640 | |
| 4641 | self.executor_server.release('F') |
| 4642 | self.waitUntilSettled() |
| 4643 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4644 | |
| 4645 | self.executor_server.release('G') |
| 4646 | self.waitUntilSettled() |
| 4647 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4648 | |
| 4649 | self.executor_server.release('E') |
| 4650 | self.waitUntilSettled() |
| 4651 | self.assertEqual(len(self.builds), 0) |
| 4652 | |
| 4653 | self.executor_server.hold_jobs_in_build = False |
| 4654 | self.executor_server.release() |
| 4655 | self.waitUntilSettled() |
| 4656 | |
| 4657 | self.assertEqual(len(self.builds), 0) |
| 4658 | self.assertEqual(len(self.history), 7) |
| 4659 | |
| 4660 | self.assertEqual(change.data['status'], 'MERGED') |
| 4661 | self.assertEqual(change.reported, 2) |
| 4662 | |
| 4663 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4664 | "Test that a job waits till all dependencies are successful" |
| 4665 | # Job dependencies, starting with A |
| 4666 | # A |
| 4667 | # / \ |
| 4668 | # B C* |
| 4669 | # / \ / \ |
| 4670 | # D F E |
| 4671 | # | |
| 4672 | # G |
| 4673 | |
| 4674 | self.executor_server.hold_jobs_in_build = True |
| 4675 | change = self.fake_gerrit.addFakeChange( |
| 4676 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4677 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4678 | |
| 4679 | self.executor_server.failJob('C', change) |
| 4680 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4681 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4682 | |
| 4683 | self.waitUntilSettled() |
| 4684 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4685 | |
| 4686 | self.executor_server.release('A') |
| 4687 | self.waitUntilSettled() |
| 4688 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4689 | |
| 4690 | self.executor_server.release('B') |
| 4691 | self.waitUntilSettled() |
| 4692 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4693 | |
| 4694 | self.executor_server.release('D') |
| 4695 | self.waitUntilSettled() |
| 4696 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4697 | |
| 4698 | self.executor_server.release('C') |
| 4699 | self.waitUntilSettled() |
| 4700 | self.assertEqual(len(self.builds), 0) |
| 4701 | |
| 4702 | self.executor_server.hold_jobs_in_build = False |
| 4703 | self.executor_server.release() |
| 4704 | self.waitUntilSettled() |
| 4705 | |
| 4706 | self.assertEqual(len(self.builds), 0) |
| 4707 | self.assertEqual(len(self.history), 4) |
| 4708 | |
| 4709 | self.assertEqual(change.data['status'], 'NEW') |
| 4710 | self.assertEqual(change.reported, 2) |
| 4711 | |
| 4712 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4713 | class TestDuplicatePipeline(ZuulTestCase): |
| 4714 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4715 | |
| 4716 | def test_duplicate_pipelines(self): |
| 4717 | "Test that a change matching multiple pipelines works" |
| 4718 | |
| 4719 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4720 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4721 | self.waitUntilSettled() |
| 4722 | |
| 4723 | self.assertHistory([ |
| 4724 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4725 | pipeline='dup1'), |
| 4726 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4727 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4728 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4729 | |
| 4730 | self.assertEqual(len(A.messages), 2) |
| 4731 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4732 | if 'dup1' in A.messages[0]: |
| 4733 | self.assertIn('dup1', A.messages[0]) |
| 4734 | self.assertNotIn('dup2', A.messages[0]) |
| 4735 | self.assertIn('project-test1', A.messages[0]) |
| 4736 | self.assertIn('dup2', A.messages[1]) |
| 4737 | self.assertNotIn('dup1', A.messages[1]) |
| 4738 | self.assertIn('project-test1', A.messages[1]) |
| 4739 | else: |
| 4740 | self.assertIn('dup1', A.messages[1]) |
| 4741 | self.assertNotIn('dup2', A.messages[1]) |
| 4742 | self.assertIn('project-test1', A.messages[1]) |
| 4743 | self.assertIn('dup2', A.messages[0]) |
| 4744 | self.assertNotIn('dup1', A.messages[0]) |
| 4745 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4746 | |
| 4747 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4748 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4749 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4750 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4751 | def test_job_from_templates_executed(self): |
| 4752 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4753 | |
| 4754 | A = self.fake_gerrit.addFakeChange( |
| 4755 | 'org/templated-project', 'master', 'A') |
| 4756 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4757 | self.waitUntilSettled() |
| 4758 | |
| 4759 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4760 | 'SUCCESS') |
| 4761 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4762 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4763 | |
| 4764 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4765 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4766 | |
| 4767 | A = self.fake_gerrit.addFakeChange( |
| 4768 | 'org/layered-project', 'master', 'A') |
| 4769 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4770 | self.waitUntilSettled() |
| 4771 | |
| 4772 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4773 | 'SUCCESS') |
| 4774 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4775 | 'SUCCESS') |
| 4776 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4777 | ).result, 'SUCCESS') |
| 4778 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4779 | ).result, 'SUCCESS') |
| 4780 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4781 | ).result, 'SUCCESS') |
| 4782 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4783 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4784 | |
| 4785 | |
| 4786 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4787 | tenant_config_file = 'config/success-url/main.yaml' |
| 4788 | |
| 4789 | def test_success_url(self): |
| 4790 | "Ensure bad build params are ignored" |
| 4791 | self.sched.reconfigure(self.config) |
| 4792 | self.init_repo('org/docs') |
| 4793 | |
| 4794 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4795 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4796 | self.waitUntilSettled() |
| 4797 | |
| 4798 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4799 | self.assertEqual(len(self.history), 2) |
| 4800 | |
| 4801 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4802 | for build in self.history: |
| 4803 | if build.name == 'docs-draft-test': |
| 4804 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4805 | elif build.name == 'docs-draft-test2': |
| 4806 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4807 | |
| 4808 | # Two msgs: 'Starting...' + results |
| 4809 | self.assertEqual(len(self.smtp_messages), 2) |
| 4810 | body = self.smtp_messages[1]['body'].splitlines() |
| 4811 | self.assertEqual('Build succeeded.', body[0]) |
| 4812 | |
| 4813 | self.assertIn( |
| 4814 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4815 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4816 | body[2]) |
| 4817 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4818 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4819 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4820 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4821 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4822 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4823 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4824 | |
| 4825 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4826 | class TestSchedulerMerges(ZuulTestCase): |
| 4827 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4828 | |
| 4829 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4830 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4831 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4832 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4833 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4834 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4835 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4836 | A.addApproval('Code-Review', 2) |
| 4837 | B.addApproval('Code-Review', 2) |
| 4838 | C.addApproval('Code-Review', 2) |
| 4839 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4840 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4841 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4842 | self.waitUntilSettled() |
| 4843 | |
| 4844 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4845 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4846 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4847 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4848 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4849 | repo_messages.reverse() |
| 4850 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4851 | self.executor_server.hold_jobs_in_build = False |
| 4852 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4853 | self.waitUntilSettled() |
| 4854 | |
| 4855 | return repo_messages |
| 4856 | |
| 4857 | def _test_merge(self, mode): |
| 4858 | us_path = os.path.join( |
| 4859 | self.upstream_root, 'org/project-%s' % mode) |
| 4860 | expected_messages = [ |
| 4861 | 'initial commit', |
| 4862 | 'add content from fixture', |
| 4863 | # the intermediate commits order is nondeterministic |
| 4864 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4865 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4866 | ] |
| 4867 | result = self._test_project_merge_mode(mode) |
| 4868 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4869 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4870 | |
| 4871 | def test_project_merge_mode_merge(self): |
| 4872 | self._test_merge('merge') |
| 4873 | |
| 4874 | def test_project_merge_mode_merge_resolve(self): |
| 4875 | self._test_merge('merge-resolve') |
| 4876 | |
| 4877 | def test_project_merge_mode_cherrypick(self): |
| 4878 | expected_messages = [ |
| 4879 | 'initial commit', |
| 4880 | 'add content from fixture', |
| 4881 | 'A-1', |
| 4882 | 'B-1', |
| 4883 | 'C-1'] |
| 4884 | result = self._test_project_merge_mode('cherry-pick') |
| 4885 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4886 | |
| 4887 | def test_merge_branch(self): |
| 4888 | "Test that the right commits are on alternate branches" |
| 4889 | self.create_branch('org/project-merge-branches', 'mp') |
| 4890 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4891 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4892 | A = self.fake_gerrit.addFakeChange( |
| 4893 | 'org/project-merge-branches', 'mp', 'A') |
| 4894 | B = self.fake_gerrit.addFakeChange( |
| 4895 | 'org/project-merge-branches', 'mp', 'B') |
| 4896 | C = self.fake_gerrit.addFakeChange( |
| 4897 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4898 | A.addApproval('Code-Review', 2) |
| 4899 | B.addApproval('Code-Review', 2) |
| 4900 | C.addApproval('Code-Review', 2) |
| 4901 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4902 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4903 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4904 | self.waitUntilSettled() |
| 4905 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4906 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4907 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4908 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4909 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4910 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4911 | self.waitUntilSettled() |
| 4912 | |
| 4913 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 4914 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4915 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4916 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4917 | repo = git.Repo(path) |
| 4918 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4919 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4920 | repo_messages.reverse() |
| 4921 | correct_messages = [ |
| 4922 | 'initial commit', |
| 4923 | 'add content from fixture', |
| 4924 | 'mp commit', |
| 4925 | 'A-1', 'B-1', 'C-1'] |
| 4926 | self.assertEqual(repo_messages, correct_messages) |
| 4927 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4928 | self.executor_server.hold_jobs_in_build = False |
| 4929 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4930 | self.waitUntilSettled() |
| 4931 | |
| 4932 | def test_merge_multi_branch(self): |
| 4933 | "Test that dependent changes on multiple branches are merged" |
| 4934 | self.create_branch('org/project-merge-branches', 'mp') |
| 4935 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4936 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4937 | A = self.fake_gerrit.addFakeChange( |
| 4938 | 'org/project-merge-branches', 'master', 'A') |
| 4939 | B = self.fake_gerrit.addFakeChange( |
| 4940 | 'org/project-merge-branches', 'mp', 'B') |
| 4941 | C = self.fake_gerrit.addFakeChange( |
| 4942 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4943 | A.addApproval('Code-Review', 2) |
| 4944 | B.addApproval('Code-Review', 2) |
| 4945 | C.addApproval('Code-Review', 2) |
| 4946 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4947 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4948 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4949 | self.waitUntilSettled() |
| 4950 | |
| 4951 | job_A = None |
| 4952 | for job in self.builds: |
| 4953 | if 'project-merge' in job.name: |
| 4954 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4955 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4956 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4957 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4958 | repo = git.Repo(path) |
| 4959 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4960 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4961 | repo_messages.reverse() |
| 4962 | correct_messages = [ |
| 4963 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4964 | self.assertEqual(repo_messages, correct_messages) |
| 4965 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4966 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4967 | self.waitUntilSettled() |
| 4968 | |
| 4969 | job_B = None |
| 4970 | for job in self.builds: |
| 4971 | if 'project-merge' in job.name: |
| 4972 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4973 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4974 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4975 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4976 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4977 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4978 | repo_messages.reverse() |
| 4979 | correct_messages = [ |
| 4980 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4981 | self.assertEqual(repo_messages, correct_messages) |
| 4982 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4983 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4984 | self.waitUntilSettled() |
| 4985 | |
| 4986 | job_C = None |
| 4987 | for job in self.builds: |
| 4988 | if 'project-merge' in job.name: |
| 4989 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 4990 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4991 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4992 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4993 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4994 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4995 | |
| 4996 | repo_messages.reverse() |
| 4997 | correct_messages = [ |
| 4998 | 'initial commit', 'add content from fixture', |
| 4999 | 'A-1', 'C-1'] |
| 5000 | # Ensure the right commits are in the history for this ref |
| 5001 | self.assertEqual(repo_messages, correct_messages) |
| 5002 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 5003 | self.executor_server.hold_jobs_in_build = False |
| 5004 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 5005 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5006 | |
| 5007 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5008 | class TestSemaphore(ZuulTestCase): |
| 5009 | tenant_config_file = 'config/semaphore/main.yaml' |
| 5010 | |
| 5011 | def test_semaphore_one(self): |
| 5012 | "Test semaphores with max=1 (mutex)" |
| 5013 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5014 | |
| 5015 | self.executor_server.hold_jobs_in_build = True |
| 5016 | |
| 5017 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5018 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5019 | self.assertFalse('test-semaphore' in |
| 5020 | tenant.semaphore_handler.semaphores) |
| 5021 | |
| 5022 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5023 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5024 | self.waitUntilSettled() |
| 5025 | |
| 5026 | self.assertEqual(len(self.builds), 3) |
| 5027 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5028 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5029 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5030 | |
| 5031 | self.executor_server.release('semaphore-one-test1') |
| 5032 | self.waitUntilSettled() |
| 5033 | |
| 5034 | self.assertEqual(len(self.builds), 3) |
| 5035 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5036 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5037 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5038 | self.assertTrue('test-semaphore' in |
| 5039 | tenant.semaphore_handler.semaphores) |
| 5040 | |
| 5041 | self.executor_server.release('semaphore-one-test2') |
| 5042 | self.waitUntilSettled() |
| 5043 | |
| 5044 | self.assertEqual(len(self.builds), 3) |
| 5045 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5046 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5047 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5048 | self.assertTrue('test-semaphore' in |
| 5049 | tenant.semaphore_handler.semaphores) |
| 5050 | |
| 5051 | self.executor_server.release('semaphore-one-test1') |
| 5052 | self.waitUntilSettled() |
| 5053 | |
| 5054 | self.assertEqual(len(self.builds), 3) |
| 5055 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5056 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5057 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5058 | self.assertTrue('test-semaphore' in |
| 5059 | tenant.semaphore_handler.semaphores) |
| 5060 | |
| 5061 | self.executor_server.release('semaphore-one-test2') |
| 5062 | self.waitUntilSettled() |
| 5063 | |
| 5064 | self.assertEqual(len(self.builds), 2) |
| 5065 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5066 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5067 | self.assertFalse('test-semaphore' in |
| 5068 | tenant.semaphore_handler.semaphores) |
| 5069 | |
| 5070 | self.executor_server.hold_jobs_in_build = False |
| 5071 | self.executor_server.release() |
| 5072 | |
| 5073 | self.waitUntilSettled() |
| 5074 | self.assertEqual(len(self.builds), 0) |
| 5075 | |
| 5076 | self.assertEqual(A.reported, 1) |
| 5077 | self.assertEqual(B.reported, 1) |
| 5078 | self.assertFalse('test-semaphore' in |
| 5079 | tenant.semaphore_handler.semaphores) |
| 5080 | |
| 5081 | def test_semaphore_two(self): |
| 5082 | "Test semaphores with max>1" |
| 5083 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5084 | |
| 5085 | self.executor_server.hold_jobs_in_build = True |
| 5086 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5087 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5088 | self.assertFalse('test-semaphore-two' in |
| 5089 | tenant.semaphore_handler.semaphores) |
| 5090 | |
| 5091 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5092 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5093 | self.waitUntilSettled() |
| 5094 | |
| 5095 | self.assertEqual(len(self.builds), 4) |
| 5096 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5097 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5098 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5099 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5100 | self.assertTrue('test-semaphore-two' in |
| 5101 | tenant.semaphore_handler.semaphores) |
| 5102 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5103 | 'test-semaphore-two', [])), 2) |
| 5104 | |
| 5105 | self.executor_server.release('semaphore-two-test1') |
| 5106 | self.waitUntilSettled() |
| 5107 | |
| 5108 | self.assertEqual(len(self.builds), 4) |
| 5109 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5110 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5111 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5112 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5113 | self.assertTrue('test-semaphore-two' in |
| 5114 | tenant.semaphore_handler.semaphores) |
| 5115 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5116 | 'test-semaphore-two', [])), 2) |
| 5117 | |
| 5118 | self.executor_server.release('semaphore-two-test2') |
| 5119 | self.waitUntilSettled() |
| 5120 | |
| 5121 | self.assertEqual(len(self.builds), 4) |
| 5122 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5123 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5124 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5125 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5126 | self.assertTrue('test-semaphore-two' in |
| 5127 | tenant.semaphore_handler.semaphores) |
| 5128 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5129 | 'test-semaphore-two', [])), 2) |
| 5130 | |
| 5131 | self.executor_server.release('semaphore-two-test1') |
| 5132 | self.waitUntilSettled() |
| 5133 | |
| 5134 | self.assertEqual(len(self.builds), 3) |
| 5135 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5136 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5137 | self.assertEqual(self.builds[2].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', [])), 1) |
| 5142 | |
| 5143 | self.executor_server.release('semaphore-two-test2') |
| 5144 | self.waitUntilSettled() |
| 5145 | |
| 5146 | self.assertEqual(len(self.builds), 2) |
| 5147 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5148 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5149 | self.assertFalse('test-semaphore-two' in |
| 5150 | tenant.semaphore_handler.semaphores) |
| 5151 | |
| 5152 | self.executor_server.hold_jobs_in_build = False |
| 5153 | self.executor_server.release() |
| 5154 | |
| 5155 | self.waitUntilSettled() |
| 5156 | self.assertEqual(len(self.builds), 0) |
| 5157 | |
| 5158 | self.assertEqual(A.reported, 1) |
| 5159 | self.assertEqual(B.reported, 1) |
| 5160 | |
| 5161 | def test_semaphore_abandon(self): |
| 5162 | "Test abandon with job semaphores" |
| 5163 | self.executor_server.hold_jobs_in_build = True |
| 5164 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5165 | check_pipeline = tenant.layout.pipelines['check'] |
| 5166 | |
| 5167 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5168 | self.assertFalse('test-semaphore' in |
| 5169 | tenant.semaphore_handler.semaphores) |
| 5170 | |
| 5171 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5172 | self.waitUntilSettled() |
| 5173 | |
| 5174 | self.assertTrue('test-semaphore' in |
| 5175 | tenant.semaphore_handler.semaphores) |
| 5176 | |
| 5177 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5178 | self.waitUntilSettled() |
| 5179 | |
| 5180 | # The check pipeline should be empty |
| 5181 | items = check_pipeline.getAllItems() |
| 5182 | self.assertEqual(len(items), 0) |
| 5183 | |
| 5184 | # The semaphore should be released |
| 5185 | self.assertFalse('test-semaphore' in |
| 5186 | tenant.semaphore_handler.semaphores) |
| 5187 | |
| 5188 | self.executor_server.hold_jobs_in_build = False |
| 5189 | self.executor_server.release() |
| 5190 | self.waitUntilSettled() |
| 5191 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5192 | def test_semaphore_new_patchset(self): |
| 5193 | "Test new patchset with job semaphores" |
| 5194 | self.executor_server.hold_jobs_in_build = True |
| 5195 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5196 | check_pipeline = tenant.layout.pipelines['check'] |
| 5197 | |
| 5198 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5199 | self.assertFalse('test-semaphore' in |
| 5200 | tenant.semaphore_handler.semaphores) |
| 5201 | |
| 5202 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5203 | self.waitUntilSettled() |
| 5204 | |
| 5205 | self.assertTrue('test-semaphore' in |
| 5206 | tenant.semaphore_handler.semaphores) |
| 5207 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5208 | self.assertEqual(len(semaphore), 1) |
| 5209 | |
| 5210 | A.addPatchset() |
| 5211 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5212 | self.waitUntilSettled() |
| 5213 | |
| 5214 | self.assertTrue('test-semaphore' in |
| 5215 | tenant.semaphore_handler.semaphores) |
| 5216 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5217 | self.assertEqual(len(semaphore), 1) |
| 5218 | |
| 5219 | items = check_pipeline.getAllItems() |
| 5220 | self.assertEqual(items[0].change.number, '1') |
| 5221 | self.assertEqual(items[0].change.patchset, '2') |
| 5222 | self.assertTrue(items[0].live) |
| 5223 | |
| 5224 | self.executor_server.hold_jobs_in_build = False |
| 5225 | self.executor_server.release() |
| 5226 | self.waitUntilSettled() |
| 5227 | |
| 5228 | # The semaphore should be released |
| 5229 | self.assertFalse('test-semaphore' in |
| 5230 | tenant.semaphore_handler.semaphores) |
| 5231 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5232 | def test_semaphore_reconfigure(self): |
| 5233 | "Test reconfigure with job semaphores" |
| 5234 | self.executor_server.hold_jobs_in_build = True |
| 5235 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5236 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5237 | self.assertFalse('test-semaphore' in |
| 5238 | tenant.semaphore_handler.semaphores) |
| 5239 | |
| 5240 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5241 | self.waitUntilSettled() |
| 5242 | |
| 5243 | self.assertTrue('test-semaphore' in |
| 5244 | tenant.semaphore_handler.semaphores) |
| 5245 | |
| 5246 | # reconfigure without layout change |
| 5247 | self.sched.reconfigure(self.config) |
| 5248 | self.waitUntilSettled() |
| 5249 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5250 | |
| 5251 | # semaphore still must be held |
| 5252 | self.assertTrue('test-semaphore' in |
| 5253 | tenant.semaphore_handler.semaphores) |
| 5254 | |
| 5255 | self.commitConfigUpdate( |
| 5256 | 'common-config', |
| 5257 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5258 | self.sched.reconfigure(self.config) |
| 5259 | self.waitUntilSettled() |
| 5260 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5261 | |
| 5262 | self.executor_server.release('project-test1') |
| 5263 | self.waitUntilSettled() |
| 5264 | |
| 5265 | # There should be no builds anymore |
| 5266 | self.assertEqual(len(self.builds), 0) |
| 5267 | |
| 5268 | # The semaphore should be released |
| 5269 | self.assertFalse('test-semaphore' in |
| 5270 | tenant.semaphore_handler.semaphores) |
| 5271 | |
| 5272 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5273 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5274 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5275 | |
| 5276 | def test_semaphore_tenant_isolation(self): |
| 5277 | "Test semaphores in multiple tenants" |
| 5278 | |
| 5279 | self.waitUntilSettled() |
| 5280 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5281 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5282 | |
| 5283 | self.executor_server.hold_jobs_in_build = True |
| 5284 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5285 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5286 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5287 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5288 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5289 | self.assertFalse('test-semaphore' in |
| 5290 | tenant_one.semaphore_handler.semaphores) |
| 5291 | self.assertFalse('test-semaphore' in |
| 5292 | tenant_two.semaphore_handler.semaphores) |
| 5293 | |
| 5294 | # add patches to project1 of tenant-one |
| 5295 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5296 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5297 | self.waitUntilSettled() |
| 5298 | |
| 5299 | # one build of project1-test1 must run |
| 5300 | # semaphore of tenant-one must be acquired once |
| 5301 | # semaphore of tenant-two must not be acquired |
| 5302 | self.assertEqual(len(self.builds), 1) |
| 5303 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5304 | self.assertTrue('test-semaphore' in |
| 5305 | tenant_one.semaphore_handler.semaphores) |
| 5306 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5307 | 'test-semaphore', [])), 1) |
| 5308 | self.assertFalse('test-semaphore' in |
| 5309 | tenant_two.semaphore_handler.semaphores) |
| 5310 | |
| 5311 | # add patches to project2 of tenant-two |
| 5312 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5313 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5314 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5315 | self.waitUntilSettled() |
| 5316 | |
| 5317 | # one build of project1-test1 must run |
| 5318 | # two builds of project2-test1 must run |
| 5319 | # semaphore of tenant-one must be acquired once |
| 5320 | # semaphore of tenant-two must be acquired twice |
| 5321 | self.assertEqual(len(self.builds), 3) |
| 5322 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5323 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5324 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5325 | self.assertTrue('test-semaphore' in |
| 5326 | tenant_one.semaphore_handler.semaphores) |
| 5327 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5328 | 'test-semaphore', [])), 1) |
| 5329 | self.assertTrue('test-semaphore' in |
| 5330 | tenant_two.semaphore_handler.semaphores) |
| 5331 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5332 | 'test-semaphore', [])), 2) |
| 5333 | |
| 5334 | self.executor_server.release('project1-test1') |
| 5335 | self.waitUntilSettled() |
| 5336 | |
| 5337 | # one build of project1-test1 must run |
| 5338 | # two builds of project2-test1 must run |
| 5339 | # semaphore of tenant-one must be acquired once |
| 5340 | # semaphore of tenant-two must be acquired twice |
| 5341 | self.assertEqual(len(self.builds), 3) |
| 5342 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5343 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5344 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5345 | self.assertTrue('test-semaphore' in |
| 5346 | tenant_one.semaphore_handler.semaphores) |
| 5347 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5348 | 'test-semaphore', [])), 1) |
| 5349 | self.assertTrue('test-semaphore' in |
| 5350 | tenant_two.semaphore_handler.semaphores) |
| 5351 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5352 | 'test-semaphore', [])), 2) |
| 5353 | |
| 5354 | self.executor_server.release('project2-test1') |
| 5355 | self.waitUntilSettled() |
| 5356 | |
| 5357 | # one build of project1-test1 must run |
| 5358 | # one build of project2-test1 must run |
| 5359 | # semaphore of tenant-one must be acquired once |
| 5360 | # semaphore of tenant-two must be acquired once |
| 5361 | self.assertEqual(len(self.builds), 2) |
| 5362 | self.assertTrue('test-semaphore' in |
| 5363 | tenant_one.semaphore_handler.semaphores) |
| 5364 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5365 | 'test-semaphore', [])), 1) |
| 5366 | self.assertTrue('test-semaphore' in |
| 5367 | tenant_two.semaphore_handler.semaphores) |
| 5368 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5369 | 'test-semaphore', [])), 1) |
| 5370 | |
| 5371 | self.executor_server.hold_jobs_in_build = False |
| 5372 | self.executor_server.release() |
| 5373 | |
| 5374 | self.waitUntilSettled() |
| 5375 | |
| 5376 | # no build must run |
| 5377 | # semaphore of tenant-one must not be acquired |
| 5378 | # semaphore of tenant-two must not be acquired |
| 5379 | self.assertEqual(len(self.builds), 0) |
| 5380 | self.assertFalse('test-semaphore' in |
| 5381 | tenant_one.semaphore_handler.semaphores) |
| 5382 | self.assertFalse('test-semaphore' in |
| 5383 | tenant_two.semaphore_handler.semaphores) |
| 5384 | |
| 5385 | self.assertEqual(A.reported, 1) |
| 5386 | self.assertEqual(B.reported, 1) |
| 5387 | |
| 5388 | |
| 5389 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5390 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5391 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5392 | |
| 5393 | def test_semaphore_in_repo(self): |
| 5394 | "Test semaphores in repo config" |
| 5395 | |
| 5396 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5397 | # max value should not be evaluated dynamically but must be updated |
| 5398 | # after the change lands. |
| 5399 | |
| 5400 | self.waitUntilSettled() |
| 5401 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5402 | |
| 5403 | in_repo_conf = textwrap.dedent( |
| 5404 | """ |
| 5405 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5406 | name: project-test1 |
| 5407 | |
| 5408 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5409 | name: project-test2 |
| 5410 | semaphore: test-semaphore |
| 5411 | |
| 5412 | - project: |
| 5413 | name: org/project |
| 5414 | tenant-one-gate: |
| 5415 | jobs: |
| 5416 | - project-test2 |
| 5417 | |
| 5418 | # the max value in dynamic layout must be ignored |
| 5419 | - semaphore: |
| 5420 | name: test-semaphore |
| 5421 | max: 2 |
| 5422 | """) |
| 5423 | |
| 5424 | in_repo_playbook = textwrap.dedent( |
| 5425 | """ |
| 5426 | - hosts: all |
| 5427 | tasks: [] |
| 5428 | """) |
| 5429 | |
| 5430 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5431 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5433 | files=file_dict) |
| 5434 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5435 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5436 | B.setDependsOn(A, 1) |
| 5437 | C.setDependsOn(A, 1) |
| 5438 | |
| 5439 | self.executor_server.hold_jobs_in_build = True |
| 5440 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5441 | A.addApproval('Code-Review', 2) |
| 5442 | B.addApproval('Code-Review', 2) |
| 5443 | C.addApproval('Code-Review', 2) |
| 5444 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5445 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5446 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5447 | self.waitUntilSettled() |
| 5448 | |
| 5449 | # check that the layout in a queue item still has max value of 1 |
| 5450 | # for test-semaphore |
| 5451 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5452 | queue = None |
| 5453 | for queue_candidate in pipeline.queues: |
| 5454 | if queue_candidate.name == 'org/project': |
| 5455 | queue = queue_candidate |
| 5456 | break |
| 5457 | queue_item = queue.queue[0] |
| 5458 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5459 | dynamic_test_semaphore = \ |
| 5460 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5461 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5462 | |
| 5463 | # one build must be in queue, one semaphores acquired |
| 5464 | self.assertEqual(len(self.builds), 1) |
| 5465 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5466 | self.assertTrue('test-semaphore' in |
| 5467 | tenant.semaphore_handler.semaphores) |
| 5468 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5469 | 'test-semaphore', [])), 1) |
| 5470 | |
| 5471 | self.executor_server.release('project-test2') |
| 5472 | self.waitUntilSettled() |
| 5473 | |
| 5474 | # change A must be merged |
| 5475 | self.assertEqual(A.data['status'], 'MERGED') |
| 5476 | self.assertEqual(A.reported, 2) |
| 5477 | |
| 5478 | # send change-merged event as the gerrit mock doesn't send it |
| 5479 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5480 | self.waitUntilSettled() |
| 5481 | |
| 5482 | # now that change A was merged, the new semaphore max must be effective |
| 5483 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5484 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5485 | |
| 5486 | # two builds must be in queue, two semaphores acquired |
| 5487 | self.assertEqual(len(self.builds), 2) |
| 5488 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5489 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5490 | self.assertTrue('test-semaphore' in |
| 5491 | tenant.semaphore_handler.semaphores) |
| 5492 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5493 | 'test-semaphore', [])), 2) |
| 5494 | |
| 5495 | self.executor_server.release('project-test2') |
| 5496 | self.waitUntilSettled() |
| 5497 | |
| 5498 | self.assertEqual(len(self.builds), 0) |
| 5499 | self.assertFalse('test-semaphore' in |
| 5500 | tenant.semaphore_handler.semaphores) |
| 5501 | |
| 5502 | self.executor_server.hold_jobs_in_build = False |
| 5503 | self.executor_server.release() |
| 5504 | |
| 5505 | self.waitUntilSettled() |
| 5506 | self.assertEqual(len(self.builds), 0) |
| 5507 | |
| 5508 | self.assertEqual(A.reported, 2) |
| 5509 | self.assertEqual(B.reported, 2) |
| 5510 | self.assertEqual(C.reported, 2) |