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') |
| 65 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
| 66 | |
| 67 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 68 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 69 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 70 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 71 | def test_jobs_executed(self): |
| 72 | "Test that jobs are executed and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 73 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 74 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 75 | A.addApproval('Code-Review', 2) |
| 76 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 77 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 78 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 79 | 'SUCCESS') |
| 80 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 81 | 'SUCCESS') |
| 82 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 83 | 'SUCCESS') |
| 84 | self.assertEqual(A.data['status'], 'MERGED') |
| 85 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 86 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 87 | 'label1') |
Adam Gandelman | eace469 | 2017-02-07 15:18:36 -0800 | [diff] [blame] | 88 | self.assertIsNone(self.getJobFromHistory('project-test2').node) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 89 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 90 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
Monty Taylor | f138504 | 2017-05-27 12:25:05 -0500 | [diff] [blame] | 91 | # Per-driver |
| 92 | self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c') |
| 93 | # Per-driver per-connection |
| 94 | self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added', |
| 95 | value='1|c') |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 96 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 97 | value='1|g') |
| 98 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 99 | kind='ms') |
| 100 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 101 | value='1|c') |
| 102 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 103 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 104 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 105 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 106 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 107 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 108 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 109 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 110 | for build in self.history: |
| 111 | self.assertTrue(build.parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 112 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 113 | def test_initial_pipeline_gauges(self): |
| 114 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 115 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 116 | value='0|g') |
| 117 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 118 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 119 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 120 | def test_job_branch(self): |
| 121 | "Test the correct variant of a job runs on a branch" |
| 122 | self.create_branch('org/project', 'stable') |
| 123 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 124 | A.addApproval('Code-Review', 2) |
| 125 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 126 | self.waitUntilSettled() |
| 127 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 128 | 'SUCCESS') |
| 129 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 130 | 'SUCCESS') |
| 131 | self.assertEqual(A.data['status'], 'MERGED') |
| 132 | self.assertEqual(A.reported, 2, |
| 133 | "A should report start and success") |
| 134 | self.assertIn('gate', A.messages[1], |
| 135 | "A should transit gate") |
| 136 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
James E. Blair | 16d96a0 | 2017-06-08 11:32:56 -0700 | [diff] [blame] | 137 | 'label2') |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 138 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 139 | def test_parallel_changes(self): |
| 140 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 141 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 142 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 143 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 144 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 145 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 146 | A.addApproval('Code-Review', 2) |
| 147 | B.addApproval('Code-Review', 2) |
| 148 | C.addApproval('Code-Review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 149 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 150 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 151 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 152 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 153 | |
| 154 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 155 | self.assertEqual(len(self.builds), 1) |
| 156 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 157 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 158 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 159 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 160 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(len(self.builds), 3) |
| 162 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 163 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 164 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 165 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 166 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 167 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 169 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 170 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(len(self.builds), 5) |
| 172 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 173 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 174 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 175 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 176 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 177 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 178 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 180 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 182 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 183 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 184 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 185 | self.executor_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 186 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 187 | self.assertEqual(len(self.builds), 6) |
| 188 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 189 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 190 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 191 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 192 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 193 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 194 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 197 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 198 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 199 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 200 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 201 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 203 | self.executor_server.hold_jobs_in_build = False |
| 204 | self.executor_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 205 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 206 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 207 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 208 | self.assertEqual(len(self.history), 9) |
| 209 | self.assertEqual(A.data['status'], 'MERGED') |
| 210 | self.assertEqual(B.data['status'], 'MERGED') |
| 211 | self.assertEqual(C.data['status'], 'MERGED') |
| 212 | self.assertEqual(A.reported, 2) |
| 213 | self.assertEqual(B.reported, 2) |
| 214 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 215 | |
| 216 | def test_failed_changes(self): |
| 217 | "Test that a change behind a failed change is retested" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 218 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 219 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 220 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 221 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 222 | A.addApproval('Code-Review', 2) |
| 223 | B.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 224 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 225 | self.executor_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 227 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 228 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 229 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 230 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 231 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 232 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 233 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 234 | # A/project-merge is complete |
| 235 | self.assertBuilds([ |
| 236 | dict(name='project-test1', changes='1,1'), |
| 237 | dict(name='project-test2', changes='1,1'), |
| 238 | dict(name='project-merge', changes='1,1 2,1'), |
| 239 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 240 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 241 | self.executor_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 242 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 243 | # A/project-merge is complete |
| 244 | # B/project-merge is complete |
| 245 | self.assertBuilds([ |
| 246 | dict(name='project-test1', changes='1,1'), |
| 247 | dict(name='project-test2', changes='1,1'), |
| 248 | dict(name='project-test1', changes='1,1 2,1'), |
| 249 | dict(name='project-test2', changes='1,1 2,1'), |
| 250 | ]) |
| 251 | |
| 252 | # Release project-test1 for A which will fail. This will |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 253 | # abort both running B jobs and reexecute project-merge for B. |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 254 | self.builds[0].release() |
| 255 | self.waitUntilSettled() |
| 256 | |
| 257 | self.orderedRelease() |
| 258 | self.assertHistory([ |
| 259 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 260 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 261 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 262 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 263 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 264 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 265 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 266 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 267 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 268 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 269 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 270 | self.assertEqual(A.data['status'], 'NEW') |
| 271 | self.assertEqual(B.data['status'], 'MERGED') |
| 272 | self.assertEqual(A.reported, 2) |
| 273 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 274 | |
| 275 | def test_independent_queues(self): |
| 276 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 277 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 278 | self.executor_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 279 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 280 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 281 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 282 | A.addApproval('Code-Review', 2) |
| 283 | B.addApproval('Code-Review', 2) |
| 284 | C.addApproval('Code-Review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 285 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 286 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 287 | self.waitUntilSettled() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 288 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 289 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f59f3cf | 2017-02-19 14:50:26 -0800 | [diff] [blame] | 290 | self.waitUntilSettled() |
| 291 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 292 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 293 | self.waitUntilSettled() |
| 294 | |
| 295 | # There should be one merge job at the head of each queue running |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 296 | self.assertBuilds([ |
| 297 | dict(name='project-merge', changes='1,1'), |
| 298 | dict(name='project-merge', changes='2,1'), |
| 299 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 300 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 301 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 302 | self.builds[0].release() |
| 303 | self.waitUntilSettled() |
| 304 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 305 | self.waitUntilSettled() |
| 306 | # Release the merge job for project2 which is behind project1 |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 307 | self.executor_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 308 | self.waitUntilSettled() |
| 309 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 310 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 311 | self.assertBuilds([ |
| 312 | dict(name='project-test1', changes='1,1'), |
| 313 | dict(name='project-test2', changes='1,1'), |
| 314 | dict(name='project-test1', changes='2,1'), |
| 315 | dict(name='project-test2', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 316 | dict(name='project1-project2-integration', changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 317 | dict(name='project-test1', changes='2,1 3,1'), |
| 318 | dict(name='project-test2', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 319 | dict(name='project1-project2-integration', changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 320 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 321 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 322 | self.orderedRelease() |
| 323 | self.assertHistory([ |
| 324 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 325 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 326 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 327 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 328 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 329 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 330 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 331 | dict( |
| 332 | name='project1-project2-integration', |
| 333 | result='SUCCESS', |
| 334 | changes='2,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 335 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 336 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
Clint Byrum | cd9393f | 2016-12-21 12:21:07 -0800 | [diff] [blame] | 337 | dict(name='project1-project2-integration', |
| 338 | result='SUCCESS', |
| 339 | changes='2,1 3,1'), |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 340 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 341 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 342 | self.assertEqual(A.data['status'], 'MERGED') |
| 343 | self.assertEqual(B.data['status'], 'MERGED') |
| 344 | self.assertEqual(C.data['status'], 'MERGED') |
| 345 | self.assertEqual(A.reported, 2) |
| 346 | self.assertEqual(B.reported, 2) |
| 347 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 348 | |
| 349 | def test_failed_change_at_head(self): |
| 350 | "Test that if a change at the head fails, jobs behind it are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 351 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 352 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 353 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 354 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 355 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 356 | A.addApproval('Code-Review', 2) |
| 357 | B.addApproval('Code-Review', 2) |
| 358 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 359 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 360 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 361 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 362 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 363 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 364 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 365 | |
| 366 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 367 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 368 | self.assertBuilds([ |
| 369 | dict(name='project-merge', changes='1,1'), |
| 370 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 371 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 372 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 373 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 374 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 375 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 376 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 377 | self.waitUntilSettled() |
| 378 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 379 | self.assertBuilds([ |
| 380 | dict(name='project-test1', changes='1,1'), |
| 381 | dict(name='project-test2', changes='1,1'), |
| 382 | dict(name='project-test1', changes='1,1 2,1'), |
| 383 | dict(name='project-test2', changes='1,1 2,1'), |
| 384 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 385 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 386 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 387 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 388 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 389 | self.waitUntilSettled() |
| 390 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 391 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 392 | self.assertBuilds([ |
| 393 | dict(name='project-test2', changes='1,1'), |
| 394 | dict(name='project-merge', changes='2,1'), |
| 395 | ]) |
| 396 | # Unordered history comparison because the aborts can finish |
| 397 | # in any order. |
| 398 | self.assertHistory([ |
| 399 | dict(name='project-merge', result='SUCCESS', |
| 400 | changes='1,1'), |
| 401 | dict(name='project-merge', result='SUCCESS', |
| 402 | changes='1,1 2,1'), |
| 403 | dict(name='project-merge', result='SUCCESS', |
| 404 | changes='1,1 2,1 3,1'), |
| 405 | dict(name='project-test1', result='FAILURE', |
| 406 | changes='1,1'), |
| 407 | dict(name='project-test1', result='ABORTED', |
| 408 | changes='1,1 2,1'), |
| 409 | dict(name='project-test2', result='ABORTED', |
| 410 | changes='1,1 2,1'), |
| 411 | dict(name='project-test1', result='ABORTED', |
| 412 | changes='1,1 2,1 3,1'), |
| 413 | dict(name='project-test2', result='ABORTED', |
| 414 | changes='1,1 2,1 3,1'), |
| 415 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 416 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 417 | self.executor_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 418 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 419 | self.executor_server.release('.*-merge') |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 420 | self.waitUntilSettled() |
| 421 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 422 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame] | 423 | self.assertBuilds([]) |
| 424 | self.assertHistory([ |
| 425 | dict(name='project-merge', result='SUCCESS', |
| 426 | changes='1,1'), |
| 427 | dict(name='project-merge', result='SUCCESS', |
| 428 | changes='1,1 2,1'), |
| 429 | dict(name='project-merge', result='SUCCESS', |
| 430 | changes='1,1 2,1 3,1'), |
| 431 | dict(name='project-test1', result='FAILURE', |
| 432 | changes='1,1'), |
| 433 | dict(name='project-test1', result='ABORTED', |
| 434 | changes='1,1 2,1'), |
| 435 | dict(name='project-test2', result='ABORTED', |
| 436 | changes='1,1 2,1'), |
| 437 | dict(name='project-test1', result='ABORTED', |
| 438 | changes='1,1 2,1 3,1'), |
| 439 | dict(name='project-test2', result='ABORTED', |
| 440 | changes='1,1 2,1 3,1'), |
| 441 | dict(name='project-merge', result='SUCCESS', |
| 442 | changes='2,1'), |
| 443 | dict(name='project-merge', result='SUCCESS', |
| 444 | changes='2,1 3,1'), |
| 445 | dict(name='project-test2', result='SUCCESS', |
| 446 | changes='1,1'), |
| 447 | dict(name='project-test1', result='SUCCESS', |
| 448 | changes='2,1'), |
| 449 | dict(name='project-test2', result='SUCCESS', |
| 450 | changes='2,1'), |
| 451 | dict(name='project-test1', result='SUCCESS', |
| 452 | changes='2,1 3,1'), |
| 453 | dict(name='project-test2', result='SUCCESS', |
| 454 | changes='2,1 3,1'), |
| 455 | ], ordered=False) |
| 456 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 457 | self.assertEqual(A.data['status'], 'NEW') |
| 458 | self.assertEqual(B.data['status'], 'MERGED') |
| 459 | self.assertEqual(C.data['status'], 'MERGED') |
| 460 | self.assertEqual(A.reported, 2) |
| 461 | self.assertEqual(B.reported, 2) |
| 462 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 463 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 464 | def test_failed_change_in_middle(self): |
| 465 | "Test a failed change in the middle of the queue" |
| 466 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 467 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 468 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 469 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 470 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 471 | A.addApproval('Code-Review', 2) |
| 472 | B.addApproval('Code-Review', 2) |
| 473 | C.addApproval('Code-Review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 474 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 475 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 476 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 477 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 478 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 479 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 480 | |
| 481 | self.waitUntilSettled() |
| 482 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 483 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 484 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 485 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 486 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 487 | self.executor_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 488 | self.waitUntilSettled() |
| 489 | |
| 490 | self.assertEqual(len(self.builds), 6) |
| 491 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 492 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 493 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 494 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 495 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 496 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 497 | |
| 498 | self.release(self.builds[2]) |
| 499 | self.waitUntilSettled() |
| 500 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 501 | # project-test1 and project-test2 for A |
| 502 | # project-test2 for B |
| 503 | # project-merge for C (without B) |
| 504 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 505 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 506 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 507 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 508 | self.waitUntilSettled() |
| 509 | |
| 510 | # project-test1 and project-test2 for A |
| 511 | # project-test2 for B |
| 512 | # project-test1 and project-test2 for C |
| 513 | self.assertEqual(len(self.builds), 5) |
| 514 | |
Paul Belanger | 2e2a049 | 2016-10-30 18:33:37 -0400 | [diff] [blame] | 515 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 516 | items = tenant.layout.pipelines['gate'].getAllItems() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 517 | builds = items[0].current_build_set.getBuilds() |
| 518 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 519 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 520 | builds = items[1].current_build_set.getBuilds() |
| 521 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 522 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 523 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 524 | builds = items[2].current_build_set.getBuilds() |
| 525 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 526 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 527 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 528 | self.executor_server.hold_jobs_in_build = False |
| 529 | self.executor_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 530 | self.waitUntilSettled() |
| 531 | |
| 532 | self.assertEqual(len(self.builds), 0) |
| 533 | self.assertEqual(len(self.history), 12) |
| 534 | self.assertEqual(A.data['status'], 'MERGED') |
| 535 | self.assertEqual(B.data['status'], 'NEW') |
| 536 | self.assertEqual(C.data['status'], 'MERGED') |
| 537 | self.assertEqual(A.reported, 2) |
| 538 | self.assertEqual(B.reported, 2) |
| 539 | self.assertEqual(C.reported, 2) |
| 540 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 541 | def test_failed_change_at_head_with_queue(self): |
| 542 | "Test that if a change at the head fails, queued jobs are canceled" |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 544 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 545 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 546 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 547 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 548 | A.addApproval('Code-Review', 2) |
| 549 | B.addApproval('Code-Review', 2) |
| 550 | C.addApproval('Code-Review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 551 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 552 | self.executor_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 553 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 554 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 555 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 556 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 557 | |
| 558 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 559 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 560 | self.assertEqual(len(self.builds), 0) |
| 561 | self.assertEqual(len(queue), 1) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 562 | self.assertEqual(queue[0].name, b'executor:execute') |
| 563 | job_args = json.loads(queue[0].arguments.decode('utf8')) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 564 | self.assertEqual(job_args['job'], 'project-merge') |
| 565 | self.assertEqual(job_args['items'][0]['number'], '%d' % A.number) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 566 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 567 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 568 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 569 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 570 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 571 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 572 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 573 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 574 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 575 | self.assertEqual(len(self.builds), 0) |
| 576 | self.assertEqual(len(queue), 6) |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 577 | |
| 578 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 579 | json.loads(queue[0].arguments.decode('utf8'))['job'], |
| 580 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 581 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 582 | json.loads(queue[1].arguments.decode('utf8'))['job'], |
| 583 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 584 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 585 | json.loads(queue[2].arguments.decode('utf8'))['job'], |
| 586 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 587 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 588 | json.loads(queue[3].arguments.decode('utf8'))['job'], |
| 589 | 'project-test2') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 590 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 591 | json.loads(queue[4].arguments.decode('utf8'))['job'], |
| 592 | 'project-test1') |
Clint Byrum | 8b2bc0c | 2016-11-16 16:28:50 -0800 | [diff] [blame] | 593 | self.assertEqual( |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 594 | json.loads(queue[5].arguments.decode('utf8'))['job'], |
| 595 | 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 596 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 597 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 598 | self.waitUntilSettled() |
| 599 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 600 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 601 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 602 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 603 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 604 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 605 | self.gearman_server.hold_jobs_in_queue = False |
| 606 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 607 | self.waitUntilSettled() |
| 608 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 609 | self.assertEqual(len(self.builds), 0) |
| 610 | self.assertEqual(len(self.history), 11) |
| 611 | self.assertEqual(A.data['status'], 'NEW') |
| 612 | self.assertEqual(B.data['status'], 'MERGED') |
| 613 | self.assertEqual(C.data['status'], 'MERGED') |
| 614 | self.assertEqual(A.reported, 2) |
| 615 | self.assertEqual(B.reported, 2) |
| 616 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 617 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 618 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 619 | def _test_time_database(self, iteration): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 620 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 621 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 622 | A.addApproval('Code-Review', 2) |
| 623 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 624 | self.waitUntilSettled() |
| 625 | time.sleep(2) |
| 626 | |
| 627 | data = json.loads(self.sched.formatStatusJSON()) |
| 628 | found_job = None |
| 629 | for pipeline in data['pipelines']: |
| 630 | if pipeline['name'] != 'gate': |
| 631 | continue |
| 632 | for queue in pipeline['change_queues']: |
| 633 | for head in queue['heads']: |
| 634 | for item in head: |
| 635 | for job in item['jobs']: |
| 636 | if job['name'] == 'project-merge': |
| 637 | found_job = job |
| 638 | break |
| 639 | |
| 640 | self.assertIsNotNone(found_job) |
| 641 | if iteration == 1: |
| 642 | self.assertIsNotNone(found_job['estimated_time']) |
| 643 | self.assertIsNone(found_job['remaining_time']) |
| 644 | else: |
| 645 | self.assertIsNotNone(found_job['estimated_time']) |
| 646 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 647 | self.assertIsNotNone(found_job['remaining_time']) |
| 648 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 649 | self.executor_server.hold_jobs_in_build = False |
| 650 | self.executor_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 651 | self.waitUntilSettled() |
| 652 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 653 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 654 | def test_time_database(self): |
| 655 | "Test the time database" |
| 656 | |
| 657 | self._test_time_database(1) |
| 658 | self._test_time_database(2) |
| 659 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 660 | def test_two_failed_changes_at_head(self): |
| 661 | "Test that changes are reparented correctly if 2 fail at head" |
| 662 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 663 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 664 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 665 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 666 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 667 | A.addApproval('Code-Review', 2) |
| 668 | B.addApproval('Code-Review', 2) |
| 669 | C.addApproval('Code-Review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 670 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 671 | self.executor_server.failJob('project-test1', A) |
| 672 | self.executor_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 673 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 674 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 675 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 676 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 677 | self.waitUntilSettled() |
| 678 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 679 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 680 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 681 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 682 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 683 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 684 | self.waitUntilSettled() |
| 685 | |
| 686 | self.assertEqual(len(self.builds), 6) |
| 687 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 688 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 689 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 690 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 691 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 692 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 693 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 694 | self.assertTrue(self.builds[0].hasChanges(A)) |
| 695 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 696 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 697 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 698 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 699 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 700 | |
| 701 | # Fail change B first |
| 702 | self.release(self.builds[2]) |
| 703 | self.waitUntilSettled() |
| 704 | |
| 705 | # restart of C after B failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 706 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 707 | self.waitUntilSettled() |
| 708 | |
| 709 | self.assertEqual(len(self.builds), 5) |
| 710 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 711 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 712 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 713 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 714 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 715 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 716 | self.assertTrue(self.builds[1].hasChanges(A)) |
| 717 | self.assertTrue(self.builds[2].hasChanges(A)) |
| 718 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 719 | self.assertTrue(self.builds[4].hasChanges(A)) |
| 720 | self.assertFalse(self.builds[4].hasChanges(B)) |
| 721 | self.assertTrue(self.builds[4].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 722 | |
| 723 | # Finish running all passing jobs for change A |
| 724 | self.release(self.builds[1]) |
| 725 | self.waitUntilSettled() |
| 726 | # Fail and report change A |
| 727 | self.release(self.builds[0]) |
| 728 | self.waitUntilSettled() |
| 729 | |
| 730 | # restart of B,C after A failure |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 731 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 732 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 733 | self.executor_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 734 | self.waitUntilSettled() |
| 735 | |
| 736 | self.assertEqual(len(self.builds), 4) |
| 737 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 738 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 739 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 740 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 741 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 742 | self.assertFalse(self.builds[1].hasChanges(A)) |
| 743 | self.assertTrue(self.builds[1].hasChanges(B)) |
| 744 | self.assertFalse(self.builds[1].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 745 | |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 746 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 747 | # After A failed and B and C restarted, B should be back in |
| 748 | # C's tests because it has not failed yet. |
Paul Belanger | 71dd2fc | 2016-11-04 19:05:55 -0400 | [diff] [blame] | 749 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 750 | self.assertTrue(self.builds[2].hasChanges(C)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 751 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 752 | self.executor_server.hold_jobs_in_build = False |
| 753 | self.executor_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 754 | self.waitUntilSettled() |
| 755 | |
| 756 | self.assertEqual(len(self.builds), 0) |
| 757 | self.assertEqual(len(self.history), 21) |
| 758 | self.assertEqual(A.data['status'], 'NEW') |
| 759 | self.assertEqual(B.data['status'], 'NEW') |
| 760 | self.assertEqual(C.data['status'], 'MERGED') |
| 761 | self.assertEqual(A.reported, 2) |
| 762 | self.assertEqual(B.reported, 2) |
| 763 | self.assertEqual(C.reported, 2) |
| 764 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 765 | def test_patch_order(self): |
| 766 | "Test that dependent patches are tested in the right order" |
| 767 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 768 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 769 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 770 | A.addApproval('Code-Review', 2) |
| 771 | B.addApproval('Code-Review', 2) |
| 772 | C.addApproval('Code-Review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 773 | |
| 774 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 775 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 776 | M2.setMerged() |
| 777 | M1.setMerged() |
| 778 | |
| 779 | # C -> B -> A -> M1 -> M2 |
| 780 | # M2 is here to make sure it is never queried. If it is, it |
| 781 | # means zuul is walking down the entire history of merged |
| 782 | # changes. |
| 783 | |
| 784 | C.setDependsOn(B, 1) |
| 785 | B.setDependsOn(A, 1) |
| 786 | A.setDependsOn(M1, 1) |
| 787 | M1.setDependsOn(M2, 1) |
| 788 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 789 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 790 | |
| 791 | self.waitUntilSettled() |
| 792 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 793 | self.assertEqual(A.data['status'], 'NEW') |
| 794 | self.assertEqual(B.data['status'], 'NEW') |
| 795 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 796 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 797 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 798 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 799 | |
| 800 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 801 | self.assertEqual(M2.queried, 0) |
| 802 | self.assertEqual(A.data['status'], 'MERGED') |
| 803 | self.assertEqual(B.data['status'], 'MERGED') |
| 804 | self.assertEqual(C.data['status'], 'MERGED') |
| 805 | self.assertEqual(A.reported, 2) |
| 806 | self.assertEqual(B.reported, 2) |
| 807 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 808 | |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 809 | def test_needed_changes_enqueue(self): |
| 810 | "Test that a needed change is enqueued ahead" |
| 811 | # A Given a git tree like this, if we enqueue |
| 812 | # / \ change C, we should walk up and down the tree |
| 813 | # B G and enqueue changes in the order ABCDEFG. |
| 814 | # /|\ This is also the order that you would get if |
| 815 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 816 | # / the ordering is stable across re-enqueue events. |
| 817 | # D |
| 818 | |
| 819 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 820 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 821 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 822 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 823 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 824 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 825 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 826 | B.setDependsOn(A, 1) |
| 827 | C.setDependsOn(B, 1) |
| 828 | D.setDependsOn(C, 1) |
| 829 | E.setDependsOn(B, 1) |
| 830 | F.setDependsOn(B, 1) |
| 831 | G.setDependsOn(A, 1) |
| 832 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 833 | A.addApproval('Code-Review', 2) |
| 834 | B.addApproval('Code-Review', 2) |
| 835 | C.addApproval('Code-Review', 2) |
| 836 | D.addApproval('Code-Review', 2) |
| 837 | E.addApproval('Code-Review', 2) |
| 838 | F.addApproval('Code-Review', 2) |
| 839 | G.addApproval('Code-Review', 2) |
| 840 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 841 | |
| 842 | self.waitUntilSettled() |
| 843 | |
| 844 | self.assertEqual(A.data['status'], 'NEW') |
| 845 | self.assertEqual(B.data['status'], 'NEW') |
| 846 | self.assertEqual(C.data['status'], 'NEW') |
| 847 | self.assertEqual(D.data['status'], 'NEW') |
| 848 | self.assertEqual(E.data['status'], 'NEW') |
| 849 | self.assertEqual(F.data['status'], 'NEW') |
| 850 | self.assertEqual(G.data['status'], 'NEW') |
| 851 | |
| 852 | # We're about to add approvals to changes without adding the |
| 853 | # triggering events to Zuul, so that we can be sure that it is |
| 854 | # enqueing the changes based on dependencies, not because of |
| 855 | # triggering events. Since it will have the changes cached |
| 856 | # already (without approvals), we need to clear the cache |
| 857 | # first. |
Paul Belanger | 593480a | 2016-11-02 19:06:28 -0400 | [diff] [blame] | 858 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 859 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 860 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 861 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 862 | A.addApproval('Approved', 1) |
| 863 | B.addApproval('Approved', 1) |
| 864 | D.addApproval('Approved', 1) |
| 865 | E.addApproval('Approved', 1) |
| 866 | F.addApproval('Approved', 1) |
| 867 | G.addApproval('Approved', 1) |
| 868 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 869 | |
| 870 | for x in range(8): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 871 | self.executor_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 872 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 873 | self.executor_server.hold_jobs_in_build = False |
| 874 | self.executor_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 875 | self.waitUntilSettled() |
| 876 | |
| 877 | self.assertEqual(A.data['status'], 'MERGED') |
| 878 | self.assertEqual(B.data['status'], 'MERGED') |
| 879 | self.assertEqual(C.data['status'], 'MERGED') |
| 880 | self.assertEqual(D.data['status'], 'MERGED') |
| 881 | self.assertEqual(E.data['status'], 'MERGED') |
| 882 | self.assertEqual(F.data['status'], 'MERGED') |
| 883 | self.assertEqual(G.data['status'], 'MERGED') |
| 884 | self.assertEqual(A.reported, 2) |
| 885 | self.assertEqual(B.reported, 2) |
| 886 | self.assertEqual(C.reported, 2) |
| 887 | self.assertEqual(D.reported, 2) |
| 888 | self.assertEqual(E.reported, 2) |
| 889 | self.assertEqual(F.reported, 2) |
| 890 | self.assertEqual(G.reported, 2) |
| 891 | self.assertEqual(self.history[6].changes, |
| 892 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 893 | |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 894 | def test_source_cache(self): |
| 895 | "Test that the source cache operates correctly" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 896 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 897 | |
| 898 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 899 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 900 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 901 | A.addApproval('Code-Review', 2) |
| 902 | B.addApproval('Code-Review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 903 | |
| 904 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 905 | M1.setMerged() |
| 906 | |
| 907 | B.setDependsOn(A, 1) |
| 908 | A.setDependsOn(M1, 1) |
| 909 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 910 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 911 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 912 | |
| 913 | self.waitUntilSettled() |
| 914 | |
| 915 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 916 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 917 | build.release() |
| 918 | self.waitUntilSettled() |
| 919 | for build in self.builds: |
James E. Blair | e675d68 | 2017-07-21 15:29:35 -0700 | [diff] [blame] | 920 | if build.pipeline == 'check': |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 921 | build.release() |
| 922 | self.waitUntilSettled() |
| 923 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 924 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 925 | self.waitUntilSettled() |
| 926 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 927 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 928 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 929 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 930 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 931 | self.executor_server.hold_jobs_in_build = False |
| 932 | self.executor_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 933 | self.waitUntilSettled() |
| 934 | |
| 935 | self.assertEqual(A.data['status'], 'MERGED') |
| 936 | self.assertEqual(B.data['status'], 'MERGED') |
| 937 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 938 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 939 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 940 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 941 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 942 | # TODO: move to test_gerrit (this is a unit test!) |
| 943 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 944 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 945 | (trusted, project) = tenant.getProject('org/project') |
| 946 | source = project.source |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 947 | |
| 948 | # TODO(pabelanger): As we add more source / trigger APIs we should make |
| 949 | # it easier for users to create events for testing. |
| 950 | event = zuul.model.TriggerEvent() |
| 951 | event.trigger_name = 'gerrit' |
| 952 | event.change_number = '1' |
| 953 | event.patch_number = '2' |
| 954 | |
| 955 | a = source.getChange(event) |
| 956 | mgr = tenant.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 957 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 958 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 959 | A.addApproval('Code-Review', 2) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 960 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 961 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 962 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 963 | A.addApproval('Approved', 1) |
Paul Belanger | 9bba490 | 2016-11-02 16:07:33 -0400 | [diff] [blame] | 964 | a = source.getChange(event, refresh=True) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 965 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 966 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 967 | def test_project_merge_conflict(self): |
| 968 | "Test that gate merge conflicts are handled properly" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 969 | |
| 970 | self.gearman_server.hold_jobs_in_queue = True |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 971 | A = self.fake_gerrit.addFakeChange('org/project', |
| 972 | 'master', 'A', |
| 973 | files={'conflict': 'foo'}) |
| 974 | B = self.fake_gerrit.addFakeChange('org/project', |
| 975 | 'master', 'B', |
| 976 | files={'conflict': 'bar'}) |
| 977 | C = self.fake_gerrit.addFakeChange('org/project', |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 978 | 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 979 | A.addApproval('Code-Review', 2) |
| 980 | B.addApproval('Code-Review', 2) |
| 981 | C.addApproval('Code-Review', 2) |
| 982 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 983 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 984 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 985 | self.waitUntilSettled() |
| 986 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 987 | self.assertEqual(A.reported, 1) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 988 | self.assertEqual(C.reported, 1) |
| 989 | |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 990 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 991 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 992 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 993 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 994 | self.gearman_server.release('project-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 995 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 996 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 997 | self.gearman_server.hold_jobs_in_queue = False |
| 998 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 999 | self.waitUntilSettled() |
| 1000 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1001 | self.assertEqual(A.data['status'], 'MERGED') |
| 1002 | self.assertEqual(B.data['status'], 'NEW') |
| 1003 | self.assertEqual(C.data['status'], 'MERGED') |
| 1004 | self.assertEqual(A.reported, 2) |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 1005 | self.assertIn('Merge Failed', B.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1006 | self.assertEqual(C.reported, 2) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1007 | |
| 1008 | self.assertHistory([ |
| 1009 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1010 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1011 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1012 | dict(name='project-merge', result='SUCCESS', changes='1,1 3,1'), |
| 1013 | dict(name='project-test1', result='SUCCESS', changes='1,1 3,1'), |
| 1014 | dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'), |
| 1015 | ], ordered=False) |
| 1016 | |
| 1017 | def test_delayed_merge_conflict(self): |
| 1018 | "Test that delayed check merge conflicts are handled properly" |
| 1019 | |
| 1020 | # Hold jobs in the gearman queue so that we can test whether |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1021 | # the executor sucesfully merges a change based on an old |
| 1022 | # repo state (frozen by the scheduler) which would otherwise |
| 1023 | # conflict. |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1024 | self.gearman_server.hold_jobs_in_queue = True |
| 1025 | A = self.fake_gerrit.addFakeChange('org/project', |
| 1026 | 'master', 'A', |
| 1027 | files={'conflict': 'foo'}) |
| 1028 | B = self.fake_gerrit.addFakeChange('org/project', |
| 1029 | 'master', 'B', |
| 1030 | files={'conflict': 'bar'}) |
| 1031 | C = self.fake_gerrit.addFakeChange('org/project', |
| 1032 | 'master', 'C') |
| 1033 | C.setDependsOn(B, 1) |
| 1034 | |
| 1035 | # A enters the gate queue; B and C enter the check queue |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1036 | A.addApproval('Code-Review', 2) |
| 1037 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1038 | self.waitUntilSettled() |
| 1039 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1040 | self.waitUntilSettled() |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1041 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1042 | self.waitUntilSettled() |
| 1043 | |
| 1044 | self.assertEqual(A.reported, 1) |
| 1045 | self.assertEqual(B.reported, 0) # Check does not report start |
| 1046 | self.assertEqual(C.reported, 0) # Check does not report start |
| 1047 | |
| 1048 | # A merges while B and C are queued in check |
| 1049 | # Release A project-merge |
| 1050 | queue = self.gearman_server.getQueue() |
| 1051 | self.release(queue[0]) |
| 1052 | self.waitUntilSettled() |
| 1053 | |
| 1054 | # Release A project-test* |
| 1055 | # gate has higher precedence, so A's test jobs are added in |
| 1056 | # front of the merge jobs for B and C |
| 1057 | queue = self.gearman_server.getQueue() |
| 1058 | self.release(queue[0]) |
| 1059 | self.release(queue[1]) |
| 1060 | self.waitUntilSettled() |
| 1061 | |
| 1062 | self.assertEqual(A.data['status'], 'MERGED') |
| 1063 | self.assertEqual(B.data['status'], 'NEW') |
| 1064 | self.assertEqual(C.data['status'], 'NEW') |
| 1065 | self.assertEqual(A.reported, 2) |
| 1066 | self.assertEqual(B.reported, 0) |
| 1067 | self.assertEqual(C.reported, 0) |
| 1068 | self.assertHistory([ |
| 1069 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1070 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1071 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 1072 | ], ordered=False) |
| 1073 | |
| 1074 | # B and C report merge conflicts |
| 1075 | # Release B project-merge |
| 1076 | queue = self.gearman_server.getQueue() |
| 1077 | self.release(queue[0]) |
| 1078 | self.waitUntilSettled() |
| 1079 | |
| 1080 | # Release C |
| 1081 | self.gearman_server.hold_jobs_in_queue = False |
| 1082 | self.gearman_server.release() |
| 1083 | self.waitUntilSettled() |
| 1084 | |
| 1085 | self.assertEqual(A.data['status'], 'MERGED') |
| 1086 | self.assertEqual(B.data['status'], 'NEW') |
| 1087 | self.assertEqual(C.data['status'], 'NEW') |
| 1088 | self.assertEqual(A.reported, 2) |
| 1089 | self.assertEqual(B.reported, 1) |
| 1090 | self.assertEqual(C.reported, 1) |
| 1091 | |
| 1092 | self.assertHistory([ |
| 1093 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 1094 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 1095 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
James E. Blair | 1960d68 | 2017-04-28 15:44:14 -0700 | [diff] [blame] | 1096 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 1097 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 1098 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 1099 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 1100 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 1101 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
K Jonathan Harker | ae04e4c | 2017-03-15 19:07:11 -0700 | [diff] [blame] | 1102 | ], ordered=False) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1103 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1104 | def test_post(self): |
| 1105 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1106 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1107 | e = { |
| 1108 | "type": "ref-updated", |
| 1109 | "submitter": { |
| 1110 | "name": "User Name", |
| 1111 | }, |
| 1112 | "refUpdate": { |
| 1113 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1114 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1115 | "refName": "master", |
| 1116 | "project": "org/project", |
| 1117 | } |
| 1118 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1119 | self.fake_gerrit.addEvent(e) |
| 1120 | self.waitUntilSettled() |
| 1121 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1122 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1123 | self.assertEqual(len(self.history), 1) |
| 1124 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1125 | |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1126 | def test_post_ignore_deletes(self): |
| 1127 | "Test that deleting refs does not trigger post jobs" |
| 1128 | |
| 1129 | e = { |
| 1130 | "type": "ref-updated", |
| 1131 | "submitter": { |
| 1132 | "name": "User Name", |
| 1133 | }, |
| 1134 | "refUpdate": { |
| 1135 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1136 | "newRev": "0000000000000000000000000000000000000000", |
| 1137 | "refName": "master", |
| 1138 | "project": "org/project", |
| 1139 | } |
| 1140 | } |
| 1141 | self.fake_gerrit.addEvent(e) |
| 1142 | self.waitUntilSettled() |
| 1143 | |
| 1144 | job_names = [x.name for x in self.history] |
| 1145 | self.assertEqual(len(self.history), 0) |
| 1146 | self.assertNotIn('project-post', job_names) |
| 1147 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 1148 | @simple_layout('layouts/dont-ignore-ref-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1149 | def test_post_ignore_deletes_negative(self): |
| 1150 | "Test that deleting refs does trigger post jobs" |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1151 | e = { |
| 1152 | "type": "ref-updated", |
| 1153 | "submitter": { |
| 1154 | "name": "User Name", |
| 1155 | }, |
| 1156 | "refUpdate": { |
| 1157 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1158 | "newRev": "0000000000000000000000000000000000000000", |
| 1159 | "refName": "master", |
| 1160 | "project": "org/project", |
| 1161 | } |
| 1162 | } |
| 1163 | self.fake_gerrit.addEvent(e) |
| 1164 | self.waitUntilSettled() |
| 1165 | |
| 1166 | job_names = [x.name for x in self.history] |
| 1167 | self.assertEqual(len(self.history), 1) |
| 1168 | self.assertIn('project-post', job_names) |
| 1169 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1170 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1171 | def test_build_configuration_branch_interaction(self): |
| 1172 | "Test that switching between branches works" |
| 1173 | self.test_build_configuration() |
| 1174 | self.test_build_configuration_branch() |
| 1175 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1176 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1177 | repo = git.Repo(path) |
| 1178 | repo.heads.master.commit = repo.commit('init') |
| 1179 | self.test_build_configuration() |
| 1180 | |
James E. Blair | db93b30 | 2017-07-19 15:33:11 -0700 | [diff] [blame] | 1181 | def test_dependent_changes_rebase(self): |
| 1182 | # Test that no errors occur when we walk a dependency tree |
| 1183 | # with an unused leaf node due to a rebase. |
| 1184 | # Start by constructing: C -> B -> A |
| 1185 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1186 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1187 | B.setDependsOn(A, 1) |
| 1188 | |
| 1189 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1190 | C.setDependsOn(B, 1) |
| 1191 | |
| 1192 | # Then rebase to form: D -> C -> A |
| 1193 | C.addPatchset() # C,2 |
| 1194 | C.setDependsOn(A, 1) |
| 1195 | |
| 1196 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1197 | D.setDependsOn(C, 2) |
| 1198 | |
| 1199 | # Walk the entire tree |
| 1200 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1201 | self.waitUntilSettled() |
| 1202 | self.assertEqual(len(self.history), 3) |
| 1203 | |
| 1204 | # Verify that walking just part of the tree still works |
| 1205 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 1206 | self.waitUntilSettled() |
| 1207 | self.assertEqual(len(self.history), 6) |
| 1208 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1209 | def test_dependent_changes_dequeue(self): |
| 1210 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1211 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1212 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1213 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1214 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1215 | A.addApproval('Code-Review', 2) |
| 1216 | B.addApproval('Code-Review', 2) |
| 1217 | C.addApproval('Code-Review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1218 | |
| 1219 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1220 | M1.setMerged() |
| 1221 | |
| 1222 | # C -> B -> A -> M1 |
| 1223 | |
| 1224 | C.setDependsOn(B, 1) |
| 1225 | B.setDependsOn(A, 1) |
| 1226 | A.setDependsOn(M1, 1) |
| 1227 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1228 | self.executor_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1229 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1230 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1231 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1232 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1233 | |
| 1234 | self.waitUntilSettled() |
| 1235 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1236 | self.assertEqual(A.data['status'], 'NEW') |
| 1237 | self.assertEqual(A.reported, 2) |
| 1238 | self.assertEqual(B.data['status'], 'NEW') |
| 1239 | self.assertEqual(B.reported, 2) |
| 1240 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 0d3e83b | 2017-06-05 13:51:57 -0700 | [diff] [blame] | 1241 | self.assertIn('This change depends on a change that failed to merge.', |
| 1242 | C.messages[-1]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1243 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1244 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1245 | def test_failing_dependent_changes(self): |
| 1246 | "Test that failing dependent patches are taken out of stream" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1247 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1248 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1249 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1250 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1251 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1252 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1253 | A.addApproval('Code-Review', 2) |
| 1254 | B.addApproval('Code-Review', 2) |
| 1255 | C.addApproval('Code-Review', 2) |
| 1256 | D.addApproval('Code-Review', 2) |
| 1257 | E.addApproval('Code-Review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1258 | |
| 1259 | # E, D -> C -> B, A |
| 1260 | |
| 1261 | D.setDependsOn(C, 1) |
| 1262 | C.setDependsOn(B, 1) |
| 1263 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1264 | self.executor_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1265 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1266 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1267 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
| 1268 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1269 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1270 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1271 | |
| 1272 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1273 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1274 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1275 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1276 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1277 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1278 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1279 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1280 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1281 | self.executor_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1282 | self.waitUntilSettled() |
| 1283 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1284 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1285 | for build in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 1286 | if build.parameters['zuul']['change'] != '1': |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1287 | build.release() |
| 1288 | self.waitUntilSettled() |
| 1289 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1290 | self.executor_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1291 | self.waitUntilSettled() |
| 1292 | |
| 1293 | self.assertEqual(A.data['status'], 'MERGED') |
| 1294 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1295 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1296 | self.assertEqual(B.data['status'], 'NEW') |
| 1297 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1298 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1299 | self.assertEqual(C.data['status'], 'NEW') |
| 1300 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1301 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1302 | self.assertEqual(D.data['status'], 'NEW') |
| 1303 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1304 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1305 | self.assertEqual(E.data['status'], 'MERGED') |
| 1306 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1307 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1308 | self.assertEqual(len(self.history), 18) |
| 1309 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1310 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1311 | "Test that if a change at the head fails it is dequeued only once" |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1312 | # If it's dequeued more than once, we should see extra |
| 1313 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1314 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1315 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1316 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1317 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1318 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1319 | A.addApproval('Code-Review', 2) |
| 1320 | B.addApproval('Code-Review', 2) |
| 1321 | C.addApproval('Code-Review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1322 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1323 | self.executor_server.failJob('project-test1', A) |
| 1324 | self.executor_server.failJob('project-test2', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1325 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1326 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1327 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1328 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1329 | |
| 1330 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1331 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1332 | self.assertEqual(len(self.builds), 1) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1333 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1334 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1335 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1336 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1337 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1338 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1339 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1340 | self.executor_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1341 | self.waitUntilSettled() |
| 1342 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1343 | self.assertEqual(len(self.builds), 6) |
Paul Belanger | 58bf691 | 2016-11-11 19:36:01 -0500 | [diff] [blame] | 1344 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1345 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1346 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1347 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1348 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1349 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1350 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1351 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1352 | self.waitUntilSettled() |
| 1353 | |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1354 | self.assertEqual(len(self.builds), 2) # test2, merge for B |
| 1355 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1356 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1357 | self.executor_server.hold_jobs_in_build = False |
| 1358 | self.executor_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1359 | self.waitUntilSettled() |
| 1360 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1361 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1362 | self.assertEqual(len(self.history), 15) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1363 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1364 | self.assertEqual(A.data['status'], 'NEW') |
| 1365 | self.assertEqual(B.data['status'], 'MERGED') |
| 1366 | self.assertEqual(C.data['status'], 'MERGED') |
| 1367 | self.assertEqual(A.reported, 2) |
| 1368 | self.assertEqual(B.reported, 2) |
| 1369 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1370 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 1371 | @simple_layout('layouts/nonvoting-job.yaml') |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1372 | def test_nonvoting_job(self): |
| 1373 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1374 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1375 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1376 | 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1377 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1378 | self.executor_server.failJob('nonvoting-project-test2', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1379 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1380 | |
| 1381 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1382 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1383 | self.assertEqual(A.data['status'], 'MERGED') |
| 1384 | self.assertEqual(A.reported, 2) |
| 1385 | self.assertEqual( |
| 1386 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1387 | 'SUCCESS') |
| 1388 | self.assertEqual( |
| 1389 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1390 | 'SUCCESS') |
| 1391 | self.assertEqual( |
| 1392 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1393 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1394 | |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 1395 | self.assertTrue(self.getJobFromHistory('nonvoting-project-merge'). |
| 1396 | parameters['zuul']['voting']) |
| 1397 | self.assertTrue(self.getJobFromHistory('nonvoting-project-test1'). |
| 1398 | parameters['zuul']['voting']) |
| 1399 | self.assertFalse(self.getJobFromHistory('nonvoting-project-test2'). |
| 1400 | parameters['zuul']['voting']) |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1401 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1402 | def test_check_queue_success(self): |
| 1403 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1404 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1405 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1406 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1407 | |
| 1408 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1409 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1410 | self.assertEqual(A.data['status'], 'NEW') |
| 1411 | self.assertEqual(A.reported, 1) |
| 1412 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1413 | 'SUCCESS') |
| 1414 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1415 | 'SUCCESS') |
| 1416 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1417 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1418 | |
| 1419 | def test_check_queue_failure(self): |
| 1420 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1421 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1422 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1423 | self.executor_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1424 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1425 | |
| 1426 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1427 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1428 | self.assertEqual(A.data['status'], 'NEW') |
| 1429 | self.assertEqual(A.reported, 1) |
| 1430 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1431 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1432 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1433 | 'SUCCESS') |
| 1434 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1435 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1436 | |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1437 | @simple_layout('layouts/autohold.yaml') |
| 1438 | def test_autohold(self): |
| 1439 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1440 | |
| 1441 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 1442 | self.gearman_server.port) |
| 1443 | self.addCleanup(client.shutdown) |
David Shrewsbury | 36b2adf | 2017-07-31 15:40:13 -0400 | [diff] [blame] | 1444 | r = client.autohold('tenant-one', 'org/project', 'project-test2', |
| 1445 | "reason text", 1) |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1446 | self.assertTrue(r) |
| 1447 | |
| 1448 | self.executor_server.failJob('project-test2', A) |
| 1449 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1450 | |
| 1451 | self.waitUntilSettled() |
| 1452 | |
| 1453 | self.assertEqual(A.data['status'], 'NEW') |
| 1454 | self.assertEqual(A.reported, 1) |
| 1455 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1456 | 'FAILURE') |
| 1457 | |
| 1458 | # Check nodepool for a held node |
| 1459 | held_node = None |
| 1460 | for node in self.fake_nodepool.getNodes(): |
| 1461 | if node['state'] == zuul.model.STATE_HOLD: |
| 1462 | held_node = node |
| 1463 | break |
| 1464 | self.assertIsNotNone(held_node) |
| 1465 | |
| 1466 | # Validate node has recorded the failed job |
| 1467 | self.assertEqual( |
| 1468 | held_node['hold_job'], |
| 1469 | " ".join(['tenant-one', |
| 1470 | 'review.example.com/org/project', |
| 1471 | 'project-test2']) |
| 1472 | ) |
David Shrewsbury | f9af9df | 2017-08-01 15:19:26 -0400 | [diff] [blame] | 1473 | self.assertEqual(held_node['comment'], "reason text") |
David Shrewsbury | ffab07a | 2017-07-24 12:45:07 -0400 | [diff] [blame] | 1474 | |
| 1475 | # Another failed change should not hold any more nodes |
| 1476 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1477 | self.executor_server.failJob('project-test2', B) |
| 1478 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1479 | self.waitUntilSettled() |
| 1480 | self.assertEqual(B.data['status'], 'NEW') |
| 1481 | self.assertEqual(B.reported, 1) |
| 1482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1483 | 'FAILURE') |
| 1484 | |
| 1485 | held_nodes = 0 |
| 1486 | for node in self.fake_nodepool.getNodes(): |
| 1487 | if node['state'] == zuul.model.STATE_HOLD: |
| 1488 | held_nodes += 1 |
| 1489 | self.assertEqual(held_nodes, 1) |
| 1490 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 1491 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1492 | def test_dependent_behind_dequeue(self): |
Clint Byrum | a962657 | 2017-02-22 14:04:00 -0500 | [diff] [blame] | 1493 | # This particular test does a large amount of merges and needs a little |
| 1494 | # more time to complete |
James E. Blair | 267e516 | 2017-04-07 10:08:20 -0700 | [diff] [blame] | 1495 | self.wait_timeout = 120 |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1496 | "test that dependent changes behind dequeued changes work" |
| 1497 | # This complicated test is a reproduction of a real life bug |
| 1498 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1499 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1500 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1501 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1502 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1503 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1504 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1505 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1506 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1507 | D.setDependsOn(C, 1) |
| 1508 | E.setDependsOn(D, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1509 | A.addApproval('Code-Review', 2) |
| 1510 | B.addApproval('Code-Review', 2) |
| 1511 | C.addApproval('Code-Review', 2) |
| 1512 | D.addApproval('Code-Review', 2) |
| 1513 | E.addApproval('Code-Review', 2) |
| 1514 | F.addApproval('Code-Review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1515 | |
| 1516 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1517 | |
| 1518 | # Change object re-use in the gerrit trigger is hidden if |
| 1519 | # changes are added in quick succession; waiting makes it more |
| 1520 | # like real life. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1521 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1522 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1523 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1524 | self.waitUntilSettled() |
| 1525 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1526 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1527 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1528 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1529 | self.waitUntilSettled() |
| 1530 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1531 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1532 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1533 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1534 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1535 | self.fake_gerrit.addEvent(E.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1536 | self.waitUntilSettled() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1537 | self.fake_gerrit.addEvent(F.addApproval('Approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1538 | self.waitUntilSettled() |
| 1539 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1540 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1541 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1542 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1543 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1544 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1545 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1546 | self.executor_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1547 | self.waitUntilSettled() |
| 1548 | |
| 1549 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1550 | |
| 1551 | # Grab pointers to the jobs we want to release before |
| 1552 | # releasing any, because list indexes may change as |
| 1553 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1554 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1555 | a.release() |
| 1556 | b.release() |
| 1557 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1558 | self.waitUntilSettled() |
| 1559 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1560 | self.executor_server.hold_jobs_in_build = False |
| 1561 | self.executor_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1562 | self.waitUntilSettled() |
| 1563 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1564 | self.assertEqual(A.data['status'], 'NEW') |
| 1565 | self.assertEqual(B.data['status'], 'MERGED') |
| 1566 | self.assertEqual(C.data['status'], 'MERGED') |
| 1567 | self.assertEqual(D.data['status'], 'MERGED') |
| 1568 | self.assertEqual(E.data['status'], 'MERGED') |
| 1569 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1570 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1571 | self.assertEqual(A.reported, 2) |
| 1572 | self.assertEqual(B.reported, 2) |
| 1573 | self.assertEqual(C.reported, 2) |
| 1574 | self.assertEqual(D.reported, 2) |
| 1575 | self.assertEqual(E.reported, 2) |
| 1576 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1577 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1578 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1579 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1580 | |
| 1581 | def test_merger_repack(self): |
| 1582 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1583 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1584 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1585 | A.addApproval('Code-Review', 2) |
| 1586 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1587 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1588 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1589 | 'SUCCESS') |
| 1590 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1591 | 'SUCCESS') |
| 1592 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1593 | 'SUCCESS') |
| 1594 | self.assertEqual(A.data['status'], 'MERGED') |
| 1595 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1596 | self.assertEmptyQueues() |
Paul Belanger | 5bfe9e7 | 2016-11-04 19:20:04 -0400 | [diff] [blame] | 1597 | self.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1598 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1599 | path = os.path.join(self.merger_src_root, "review.example.com", |
| 1600 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1601 | if os.path.exists(path): |
| 1602 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1603 | path = os.path.join(self.executor_src_root, "review.example.com", |
| 1604 | "org/project") |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1605 | if os.path.exists(path): |
| 1606 | repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1607 | |
| 1608 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1609 | A.addApproval('Code-Review', 2) |
| 1610 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1611 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1612 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1613 | 'SUCCESS') |
| 1614 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1615 | 'SUCCESS') |
| 1616 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1617 | 'SUCCESS') |
| 1618 | self.assertEqual(A.data['status'], 'MERGED') |
| 1619 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1620 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1621 | def test_merger_repack_large_change(self): |
| 1622 | "Test that the merger works with large changes after a repack" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1623 | # https://bugs.executepad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1624 | # This test assumes the repo is already cloned; make sure it is |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1625 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1626 | trusted, project = tenant.getProject('org/project') |
James E. Blair | 0ffa010 | 2017-03-30 13:11:33 -0700 | [diff] [blame] | 1627 | url = self.fake_gerrit.getGitUrl(project) |
James E. Blair | 8d144dc | 2017-05-05 10:13:45 -0700 | [diff] [blame] | 1628 | self.executor_server.merger._addProject('review.example.com', |
James E. Blair | 197e820 | 2017-06-09 12:54:28 -0700 | [diff] [blame] | 1629 | 'org/project', url, None) |
James E. Blair | 6df6713 | 2017-04-19 13:53:20 -0700 | [diff] [blame] | 1630 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1631 | A.addPatchset(large=True) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1632 | # TODOv3(jeblair): add hostname to upstream root |
| 1633 | path = os.path.join(self.upstream_root, 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1634 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1635 | path = os.path.join(self.merger_src_root, 'review.example.com', |
| 1636 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1637 | if os.path.exists(path): |
| 1638 | repack_repo(path) |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 1639 | path = os.path.join(self.executor_src_root, 'review.example.com', |
| 1640 | 'org/project') |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 1641 | if os.path.exists(path): |
| 1642 | repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1643 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1644 | A.addApproval('Code-Review', 2) |
| 1645 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1646 | self.waitUntilSettled() |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1647 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1648 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1649 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1650 | 'SUCCESS') |
Paul Belanger | 503bded | 2016-11-11 19:43:38 -0500 | [diff] [blame] | 1651 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1652 | 'SUCCESS') |
| 1653 | self.assertEqual(A.data['status'], 'MERGED') |
| 1654 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1655 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1656 | def test_new_patchset_dequeues_old(self): |
| 1657 | "Test that a new patchset causes the old to be dequeued" |
| 1658 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1659 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1660 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1661 | M.setMerged() |
| 1662 | |
| 1663 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1664 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1665 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1666 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1667 | A.addApproval('Code-Review', 2) |
| 1668 | B.addApproval('Code-Review', 2) |
| 1669 | C.addApproval('Code-Review', 2) |
| 1670 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1671 | |
| 1672 | C.setDependsOn(B, 1) |
| 1673 | B.setDependsOn(A, 1) |
| 1674 | A.setDependsOn(M, 1) |
| 1675 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1676 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1677 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1678 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1679 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1680 | self.waitUntilSettled() |
| 1681 | |
| 1682 | B.addPatchset() |
| 1683 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1684 | self.waitUntilSettled() |
| 1685 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1686 | self.executor_server.hold_jobs_in_build = False |
| 1687 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1688 | self.waitUntilSettled() |
| 1689 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1690 | self.assertEqual(A.data['status'], 'MERGED') |
| 1691 | self.assertEqual(A.reported, 2) |
| 1692 | self.assertEqual(B.data['status'], 'NEW') |
| 1693 | self.assertEqual(B.reported, 2) |
| 1694 | self.assertEqual(C.data['status'], 'NEW') |
| 1695 | self.assertEqual(C.reported, 2) |
| 1696 | self.assertEqual(D.data['status'], 'MERGED') |
| 1697 | self.assertEqual(D.reported, 2) |
| 1698 | 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] | 1699 | |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1700 | def test_new_patchset_check(self): |
| 1701 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1702 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1703 | self.executor_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1704 | |
| 1705 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1706 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1707 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1708 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1709 | |
| 1710 | # Add two git-dependent changes |
| 1711 | B.setDependsOn(A, 1) |
| 1712 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1713 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1714 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1715 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1716 | |
| 1717 | # A live item, and a non-live/live pair |
| 1718 | items = check_pipeline.getAllItems() |
| 1719 | self.assertEqual(len(items), 3) |
| 1720 | |
| 1721 | self.assertEqual(items[0].change.number, '1') |
| 1722 | self.assertEqual(items[0].change.patchset, '1') |
| 1723 | self.assertFalse(items[0].live) |
| 1724 | |
| 1725 | self.assertEqual(items[1].change.number, '2') |
| 1726 | self.assertEqual(items[1].change.patchset, '1') |
| 1727 | self.assertTrue(items[1].live) |
| 1728 | |
| 1729 | self.assertEqual(items[2].change.number, '1') |
| 1730 | self.assertEqual(items[2].change.patchset, '1') |
| 1731 | self.assertTrue(items[2].live) |
| 1732 | |
| 1733 | # Add a new patchset to A |
| 1734 | A.addPatchset() |
| 1735 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1736 | self.waitUntilSettled() |
| 1737 | |
| 1738 | # The live copy of A,1 should be gone, but the non-live and B |
| 1739 | # should continue, and we should have a new A,2 |
| 1740 | items = check_pipeline.getAllItems() |
| 1741 | self.assertEqual(len(items), 3) |
| 1742 | |
| 1743 | self.assertEqual(items[0].change.number, '1') |
| 1744 | self.assertEqual(items[0].change.patchset, '1') |
| 1745 | self.assertFalse(items[0].live) |
| 1746 | |
| 1747 | self.assertEqual(items[1].change.number, '2') |
| 1748 | self.assertEqual(items[1].change.patchset, '1') |
| 1749 | self.assertTrue(items[1].live) |
| 1750 | |
| 1751 | self.assertEqual(items[2].change.number, '1') |
| 1752 | self.assertEqual(items[2].change.patchset, '2') |
| 1753 | self.assertTrue(items[2].live) |
| 1754 | |
| 1755 | # Add a new patchset to B |
| 1756 | B.addPatchset() |
| 1757 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1758 | self.waitUntilSettled() |
| 1759 | |
| 1760 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1761 | # but we should have a new B,2 (still based on A,1) |
| 1762 | items = check_pipeline.getAllItems() |
| 1763 | self.assertEqual(len(items), 3) |
| 1764 | |
| 1765 | self.assertEqual(items[0].change.number, '1') |
| 1766 | self.assertEqual(items[0].change.patchset, '2') |
| 1767 | self.assertTrue(items[0].live) |
| 1768 | |
| 1769 | self.assertEqual(items[1].change.number, '1') |
| 1770 | self.assertEqual(items[1].change.patchset, '1') |
| 1771 | self.assertFalse(items[1].live) |
| 1772 | |
| 1773 | self.assertEqual(items[2].change.number, '2') |
| 1774 | self.assertEqual(items[2].change.patchset, '2') |
| 1775 | self.assertTrue(items[2].live) |
| 1776 | |
| 1777 | self.builds[0].release() |
| 1778 | self.waitUntilSettled() |
| 1779 | self.builds[0].release() |
| 1780 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1781 | self.executor_server.hold_jobs_in_build = False |
| 1782 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1783 | self.waitUntilSettled() |
| 1784 | |
| 1785 | self.assertEqual(A.reported, 1) |
| 1786 | self.assertEqual(B.reported, 1) |
| 1787 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1788 | self.assertEqual(self.history[0].changes, '1,1') |
| 1789 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1790 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1791 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1792 | self.assertEqual(self.history[2].changes, '1,2') |
| 1793 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1794 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1795 | |
| 1796 | def test_abandoned_gate(self): |
| 1797 | "Test that an abandoned change is dequeued from gate" |
| 1798 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1799 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1800 | |
| 1801 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1802 | A.addApproval('Code-Review', 2) |
| 1803 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1804 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1805 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1806 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1807 | |
| 1808 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1809 | self.waitUntilSettled() |
| 1810 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1811 | self.executor_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1812 | self.waitUntilSettled() |
| 1813 | |
Arie | 5b4048c | 2016-10-05 16:12:06 +0300 | [diff] [blame] | 1814 | self.assertBuilds([]) |
| 1815 | self.assertHistory([ |
| 1816 | dict(name='project-merge', result='ABORTED', changes='1,1')], |
| 1817 | ordered=False) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1818 | self.assertEqual(A.reported, 1, |
| 1819 | "Abandoned gate change should report only start") |
| 1820 | |
| 1821 | def test_abandoned_check(self): |
| 1822 | "Test that an abandoned change is dequeued from check" |
| 1823 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1824 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1825 | |
| 1826 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1827 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 18e5f63 | 2016-11-03 15:24:16 -0400 | [diff] [blame] | 1828 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 1829 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1830 | |
| 1831 | # Add two git-dependent changes |
| 1832 | B.setDependsOn(A, 1) |
| 1833 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1834 | self.waitUntilSettled() |
| 1835 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1836 | self.waitUntilSettled() |
| 1837 | # A live item, and a non-live/live pair |
| 1838 | items = check_pipeline.getAllItems() |
| 1839 | self.assertEqual(len(items), 3) |
| 1840 | |
| 1841 | self.assertEqual(items[0].change.number, '1') |
| 1842 | self.assertFalse(items[0].live) |
| 1843 | |
| 1844 | self.assertEqual(items[1].change.number, '2') |
| 1845 | self.assertTrue(items[1].live) |
| 1846 | |
| 1847 | self.assertEqual(items[2].change.number, '1') |
| 1848 | self.assertTrue(items[2].live) |
| 1849 | |
| 1850 | # Abandon A |
| 1851 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1852 | self.waitUntilSettled() |
| 1853 | |
| 1854 | # The live copy of A should be gone, but the non-live and B |
| 1855 | # should continue |
| 1856 | items = check_pipeline.getAllItems() |
| 1857 | self.assertEqual(len(items), 2) |
| 1858 | |
| 1859 | self.assertEqual(items[0].change.number, '1') |
| 1860 | self.assertFalse(items[0].live) |
| 1861 | |
| 1862 | self.assertEqual(items[1].change.number, '2') |
| 1863 | self.assertTrue(items[1].live) |
| 1864 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1865 | self.executor_server.hold_jobs_in_build = False |
| 1866 | self.executor_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1867 | self.waitUntilSettled() |
| 1868 | |
| 1869 | self.assertEqual(len(self.history), 4) |
| 1870 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1871 | 'Build should have been aborted') |
| 1872 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1873 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1874 | |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1875 | def test_abandoned_not_timer(self): |
| 1876 | "Test that an abandoned change does not cancel timer jobs" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1877 | # This test can not use simple_layout because it must start |
| 1878 | # with a configuration which does not include a |
| 1879 | # timer-triggered job so that we have an opportunity to set |
| 1880 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1881 | self.executor_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1882 | # Start timer trigger - also org/project |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1883 | self.commitConfigUpdate('common-config', 'layouts/idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1884 | self.sched.reconfigure(self.config) |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1885 | # The pipeline triggers every second, so we should have seen |
| 1886 | # several by now. |
| 1887 | time.sleep(5) |
| 1888 | self.waitUntilSettled() |
| 1889 | # Stop queuing timer triggered jobs so that the assertions |
| 1890 | # below don't race against more jobs being queued. |
Clint Byrum | ead6c56 | 2017-02-01 16:34:04 -0800 | [diff] [blame] | 1891 | # Must be in same repo, so overwrite config with another one |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1892 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1893 | self.sched.reconfigure(self.config) |
James E. Blair | 0b137b4 | 2017-07-27 08:51:25 -0700 | [diff] [blame] | 1894 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 1895 | # If APScheduler is in mid-event when we remove the job, we |
| 1896 | # can end up with one more event firing, so give it an extra |
| 1897 | # second to settle. |
| 1898 | time.sleep(1) |
| 1899 | self.waitUntilSettled() |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 1900 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1901 | self.assertEqual(len(self.builds), 1, "One timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1902 | |
| 1903 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1904 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1905 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1906 | self.assertEqual(len(self.builds), 2, "One change plus one timer job") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1907 | |
| 1908 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1909 | self.waitUntilSettled() |
| 1910 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 1911 | self.assertEqual(len(self.builds), 1, "One timer job remains") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1912 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1913 | self.executor_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1914 | self.waitUntilSettled() |
| 1915 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1916 | def test_new_patchset_dequeues_old_on_head(self): |
| 1917 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 1918 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1919 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1920 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1921 | M.setMerged() |
| 1922 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1923 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1924 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1925 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1926 | A.addApproval('Code-Review', 2) |
| 1927 | B.addApproval('Code-Review', 2) |
| 1928 | C.addApproval('Code-Review', 2) |
| 1929 | D.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1930 | |
| 1931 | C.setDependsOn(B, 1) |
| 1932 | B.setDependsOn(A, 1) |
| 1933 | A.setDependsOn(M, 1) |
| 1934 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1935 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 1936 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1937 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1938 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1939 | self.waitUntilSettled() |
| 1940 | |
| 1941 | A.addPatchset() |
| 1942 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1943 | self.waitUntilSettled() |
| 1944 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1945 | self.executor_server.hold_jobs_in_build = False |
| 1946 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1947 | self.waitUntilSettled() |
| 1948 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1949 | self.assertEqual(A.data['status'], 'NEW') |
| 1950 | self.assertEqual(A.reported, 2) |
| 1951 | self.assertEqual(B.data['status'], 'NEW') |
| 1952 | self.assertEqual(B.reported, 2) |
| 1953 | self.assertEqual(C.data['status'], 'NEW') |
| 1954 | self.assertEqual(C.reported, 2) |
| 1955 | self.assertEqual(D.data['status'], 'MERGED') |
| 1956 | self.assertEqual(D.reported, 2) |
| 1957 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1958 | |
| 1959 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 1960 | "Test that a new patchset causes only the old to be dequeued" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1961 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1962 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1963 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1964 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1965 | A.addApproval('Code-Review', 2) |
| 1966 | B.addApproval('Code-Review', 2) |
| 1967 | C.addApproval('Code-Review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1968 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 1969 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 1970 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 1971 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1972 | self.waitUntilSettled() |
| 1973 | |
| 1974 | B.addPatchset() |
| 1975 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1976 | self.waitUntilSettled() |
| 1977 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1978 | self.executor_server.hold_jobs_in_build = False |
| 1979 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1980 | self.waitUntilSettled() |
| 1981 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1982 | self.assertEqual(A.data['status'], 'MERGED') |
| 1983 | self.assertEqual(A.reported, 2) |
| 1984 | self.assertEqual(B.data['status'], 'NEW') |
| 1985 | self.assertEqual(B.reported, 2) |
| 1986 | self.assertEqual(C.data['status'], 'MERGED') |
| 1987 | self.assertEqual(C.reported, 2) |
| 1988 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1989 | |
| 1990 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 1991 | "Test that a new patchset causes the old to be dequeued (independent)" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 1992 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1993 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1994 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1995 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1996 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1997 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1998 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 1999 | self.waitUntilSettled() |
| 2000 | |
| 2001 | B.addPatchset() |
| 2002 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2003 | self.waitUntilSettled() |
| 2004 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2005 | self.executor_server.hold_jobs_in_build = False |
| 2006 | self.executor_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2007 | self.waitUntilSettled() |
| 2008 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2009 | self.assertEqual(A.data['status'], 'NEW') |
| 2010 | self.assertEqual(A.reported, 1) |
| 2011 | self.assertEqual(B.data['status'], 'NEW') |
| 2012 | self.assertEqual(B.reported, 1) |
| 2013 | self.assertEqual(C.data['status'], 'NEW') |
| 2014 | self.assertEqual(C.reported, 1) |
| 2015 | self.assertEqual(len(self.history), 10) |
| 2016 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2017 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 2018 | @simple_layout('layouts/noop-job.yaml') |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2019 | def test_noop_job(self): |
| 2020 | "Test that the internal noop job works" |
| 2021 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2022 | A.addApproval('Code-Review', 2) |
| 2023 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2024 | self.waitUntilSettled() |
| 2025 | |
| 2026 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2027 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2028 | self.assertEqual(len(self.history), 0) |
| 2029 | self.assertEqual(A.data['status'], 'MERGED') |
| 2030 | self.assertEqual(A.reported, 2) |
| 2031 | |
James E. Blair | 06cc392 | 2017-04-19 10:08:10 -0700 | [diff] [blame] | 2032 | @simple_layout('layouts/no-jobs-project.yaml') |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2033 | def test_no_job_project(self): |
| 2034 | "Test that reports with no jobs don't get sent" |
| 2035 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2036 | 'master', 'A') |
| 2037 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2038 | self.waitUntilSettled() |
| 2039 | |
| 2040 | # Change wasn't reported to |
| 2041 | self.assertEqual(A.reported, False) |
| 2042 | |
| 2043 | # Check queue is empty afterwards |
Clint Byrum | 883c30e | 2016-12-13 11:54:33 -0800 | [diff] [blame] | 2044 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2045 | check_pipeline = tenant.layout.pipelines['check'] |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2046 | items = check_pipeline.getAllItems() |
| 2047 | self.assertEqual(len(items), 0) |
| 2048 | |
| 2049 | self.assertEqual(len(self.history), 0) |
| 2050 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2051 | def test_zuul_refs(self): |
| 2052 | "Test that zuul refs exist and have the right changes" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2053 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2054 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2055 | M1.setMerged() |
| 2056 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2057 | M2.setMerged() |
| 2058 | |
| 2059 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2060 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2061 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2062 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2063 | A.addApproval('Code-Review', 2) |
| 2064 | B.addApproval('Code-Review', 2) |
| 2065 | C.addApproval('Code-Review', 2) |
| 2066 | D.addApproval('Code-Review', 2) |
| 2067 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2068 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 2069 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
| 2070 | self.fake_gerrit.addEvent(D.addApproval('Approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2071 | |
| 2072 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2073 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2074 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2075 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2076 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2077 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2078 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2079 | self.executor_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2080 | self.waitUntilSettled() |
| 2081 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2082 | a_build = b_build = c_build = d_build = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2083 | for x in self.builds: |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2084 | if x.parameters['zuul']['change'] == '3': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2085 | a_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2086 | elif x.parameters['zuul']['change'] == '4': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2087 | b_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2088 | elif x.parameters['zuul']['change'] == '5': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2089 | c_build = x |
James E. Blair | e3db295 | 2017-07-21 15:03:36 -0700 | [diff] [blame] | 2090 | elif x.parameters['zuul']['change'] == '6': |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2091 | d_build = x |
| 2092 | if a_build and b_build and c_build and d_build: |
| 2093 | break |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2094 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2095 | # should have a, not b, and should not be in project2 |
| 2096 | self.assertTrue(a_build.hasChanges(A)) |
| 2097 | self.assertFalse(a_build.hasChanges(B, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2098 | |
Clint Byrum | 3343e3e | 2016-11-15 16:05:03 -0800 | [diff] [blame] | 2099 | # should have a and b, and should not be in project2 |
| 2100 | self.assertTrue(b_build.hasChanges(A, B)) |
| 2101 | self.assertFalse(b_build.hasChanges(M2)) |
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 and b in 1, c in 2 |
| 2104 | self.assertTrue(c_build.hasChanges(A, B, C)) |
| 2105 | self.assertFalse(c_build.hasChanges(D)) |
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 in 1, c and d in 2 |
| 2108 | self.assertTrue(d_build.hasChanges(A, B, C, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2109 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2110 | self.executor_server.hold_jobs_in_build = False |
| 2111 | self.executor_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2112 | self.waitUntilSettled() |
| 2113 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2114 | self.assertEqual(A.data['status'], 'MERGED') |
| 2115 | self.assertEqual(A.reported, 2) |
| 2116 | self.assertEqual(B.data['status'], 'MERGED') |
| 2117 | self.assertEqual(B.reported, 2) |
| 2118 | self.assertEqual(C.data['status'], 'MERGED') |
| 2119 | self.assertEqual(C.reported, 2) |
| 2120 | self.assertEqual(D.data['status'], 'MERGED') |
| 2121 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2122 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2123 | def test_rerun_on_error(self): |
| 2124 | "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] | 2125 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2126 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2127 | A.addApproval('Code-Review', 2) |
| 2128 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2129 | self.waitUntilSettled() |
| 2130 | |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2131 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2132 | self.executor_server.hold_jobs_in_build = False |
| 2133 | self.executor_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2134 | self.waitUntilSettled() |
James E. Blair | 412fba8 | 2017-01-26 15:00:50 -0800 | [diff] [blame] | 2135 | self.assertEqual(self.countJobResults(self.history, None), 1) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2136 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2137 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2138 | def test_statsd(self): |
| 2139 | "Test each of the statsd methods used in the scheduler" |
| 2140 | import extras |
| 2141 | statsd = extras.try_import('statsd.statsd') |
| 2142 | statsd.incr('test-incr') |
| 2143 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2144 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2145 | self.assertReportedStat('test-incr', '1|c') |
| 2146 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2147 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2148 | |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2149 | def test_stuck_job_cleanup(self): |
| 2150 | "Test that pending jobs are cleaned up if removed from layout" |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2151 | |
| 2152 | # 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] | 2153 | self.gearman_server.hold_jobs_in_queue = True |
| 2154 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2155 | A.addApproval('Code-Review', 2) |
| 2156 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2157 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2158 | # 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] | 2159 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2160 | |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2161 | self.commitConfigUpdate('common-config', 'layouts/no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2162 | self.sched.reconfigure(self.config) |
| 2163 | self.waitUntilSettled() |
| 2164 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2165 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2166 | self.waitUntilSettled() |
Clint Byrum | 678e2c3 | 2017-03-16 16:27:21 -0700 | [diff] [blame] | 2167 | # asserting that project-merge is removed from queue |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2168 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2169 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2170 | |
| 2171 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2172 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2173 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2174 | |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2175 | def test_file_head(self): |
| 2176 | # This is a regression test for an observed bug. A change |
| 2177 | # with a file named "HEAD" in the root directory of the repo |
| 2178 | # was processed by a merger. It then was unable to reset the |
| 2179 | # repo because of: |
| 2180 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2181 | # with exit code 128 |
| 2182 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2183 | # and filename |
| 2184 | # Use '--' to separate filenames from revisions' |
| 2185 | |
| 2186 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | a91095f | 2016-11-04 19:28:48 -0400 | [diff] [blame] | 2187 | A.addPatchset({'HEAD': ''}) |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2188 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2189 | |
| 2190 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2191 | self.waitUntilSettled() |
| 2192 | |
| 2193 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2194 | self.waitUntilSettled() |
| 2195 | |
| 2196 | self.assertIn('Build succeeded', A.messages[0]) |
| 2197 | self.assertIn('Build succeeded', B.messages[0]) |
| 2198 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2199 | def test_file_jobs(self): |
| 2200 | "Test that file jobs run only when appropriate" |
| 2201 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Adam Gandelman | 5661bda | 2017-02-03 15:58:03 -0800 | [diff] [blame] | 2202 | A.addPatchset({'pip-requires': 'foo'}) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2203 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2204 | A.addApproval('Code-Review', 2) |
| 2205 | B.addApproval('Code-Review', 2) |
| 2206 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2207 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2208 | self.waitUntilSettled() |
| 2209 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2210 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2211 | if x.name == 'project-testfile'] |
| 2212 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2213 | self.assertEqual(len(testfile_jobs), 1) |
| 2214 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2215 | self.assertEqual(A.data['status'], 'MERGED') |
| 2216 | self.assertEqual(A.reported, 2) |
| 2217 | self.assertEqual(B.data['status'], 'MERGED') |
| 2218 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2219 | |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2220 | def _test_irrelevant_files_jobs(self, should_skip): |
| 2221 | "Test that jobs with irrelevant-files filter run only when appropriate" |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2222 | if should_skip: |
| 2223 | files = {'ignoreme': 'ignored\n'} |
| 2224 | else: |
| 2225 | files = {'respectme': 'please!\n'} |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2226 | |
| 2227 | change = self.fake_gerrit.addFakeChange('org/project', |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2228 | 'master', |
| 2229 | 'test irrelevant-files', |
| 2230 | files=files) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2231 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2232 | self.waitUntilSettled() |
| 2233 | |
| 2234 | tested_change_ids = [x.changes[0] for x in self.history |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2235 | if x.name == 'project-test-irrelevant-files'] |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2236 | |
| 2237 | if should_skip: |
| 2238 | self.assertEqual([], tested_change_ids) |
| 2239 | else: |
| 2240 | self.assertIn(change.data['number'], tested_change_ids) |
| 2241 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2242 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2243 | def test_irrelevant_files_match_skips_job(self): |
| 2244 | self._test_irrelevant_files_jobs(should_skip=True) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2245 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2246 | @simple_layout('layouts/irrelevant-files.yaml') |
Clint Byrum | 3ee39f3 | 2016-11-17 23:45:07 -0800 | [diff] [blame] | 2247 | def test_irrelevant_files_no_match_runs_job(self): |
| 2248 | self._test_irrelevant_files_jobs(should_skip=False) |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2249 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2250 | @simple_layout('layouts/inheritance.yaml') |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2251 | def test_inherited_jobs_keep_matchers(self): |
Clint Byrum | 8549360 | 2016-11-18 11:59:47 -0800 | [diff] [blame] | 2252 | files = {'ignoreme': 'ignored\n'} |
| 2253 | |
| 2254 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2255 | 'master', |
| 2256 | 'test irrelevant-files', |
| 2257 | files=files) |
| 2258 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2259 | self.waitUntilSettled() |
| 2260 | |
| 2261 | run_jobs = set([build.name for build in self.history]) |
| 2262 | |
| 2263 | self.assertEqual(set(['project-test-nomatch-starts-empty', |
| 2264 | 'project-test-nomatch-starts-full']), run_jobs) |
| 2265 | |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2266 | def test_queue_names(self): |
| 2267 | "Test shared change queue names" |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2268 | tenant = self.sched.abide.tenants.get('tenant-one') |
James E. Blair | 6053de4 | 2017-04-05 11:27:11 -0700 | [diff] [blame] | 2269 | (trusted, project1) = tenant.getProject('org/project1') |
| 2270 | (trusted, project2) = tenant.getProject('org/project2') |
Paul Belanger | 8e68fc2 | 2017-02-06 16:24:49 -0500 | [diff] [blame] | 2271 | q1 = tenant.layout.pipelines['gate'].getQueue(project1) |
| 2272 | q2 = tenant.layout.pipelines['gate'].getQueue(project2) |
| 2273 | self.assertEqual(q1.name, 'integrated') |
| 2274 | self.assertEqual(q2.name, 'integrated') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2275 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2276 | def test_queue_precedence(self): |
| 2277 | "Test that queue precedence works" |
| 2278 | |
| 2279 | self.gearman_server.hold_jobs_in_queue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2280 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2281 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2282 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2283 | A.addApproval('Code-Review', 2) |
| 2284 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2285 | |
| 2286 | self.waitUntilSettled() |
| 2287 | self.gearman_server.hold_jobs_in_queue = False |
| 2288 | self.gearman_server.release() |
| 2289 | self.waitUntilSettled() |
| 2290 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2291 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2292 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2293 | self.executor_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2294 | self.waitUntilSettled() |
| 2295 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2296 | self.log.debug(self.history) |
| 2297 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2298 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2299 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2300 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2301 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2302 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2303 | |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2304 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2305 | "Test that we can retrieve JSON status info" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2306 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2307 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2308 | A.addApproval('Code-Review', 2) |
| 2309 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2310 | self.waitUntilSettled() |
| 2311 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2312 | self.executor_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2313 | self.waitUntilSettled() |
| 2314 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2315 | port = self.webapp.server.socket.getsockname()[1] |
| 2316 | |
Adam Gandelman | 77a12c7 | 2017-02-03 17:43:43 -0800 | [diff] [blame] | 2317 | req = urllib.request.Request( |
| 2318 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2319 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2320 | headers = f.info() |
| 2321 | self.assertIn('Content-Length', headers) |
| 2322 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2323 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2324 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2325 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2326 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2327 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2328 | self.assertIn('Expires', headers) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2329 | data = f.read().decode('utf8') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2330 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2331 | self.executor_server.hold_jobs_in_build = False |
| 2332 | self.executor_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2333 | self.waitUntilSettled() |
| 2334 | |
| 2335 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2336 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2337 | for p in data['pipelines']: |
| 2338 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2339 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2340 | self.assertEqual(q['window'], 20) |
| 2341 | else: |
| 2342 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2343 | for head in q['heads']: |
| 2344 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2345 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2346 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2347 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2348 | status_jobs.append(job) |
| 2349 | self.assertEqual('project-merge', status_jobs[0]['name']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2350 | # TODO(mordred) pull uuids from self.builds |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2351 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2352 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2353 | uuid=status_jobs[0]['uuid']), |
| 2354 | status_jobs[0]['url']) |
| 2355 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2356 | 'finger://{hostname}/{uuid}'.format( |
| 2357 | hostname=self.executor_server.hostname, |
| 2358 | uuid=status_jobs[0]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2359 | status_jobs[0]['finger_url']) |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 2360 | # TOOD(mordred) configure a success-url on the base job |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2361 | self.assertEqual( |
| 2362 | 'finger://{hostname}/{uuid}'.format( |
| 2363 | hostname=self.executor_server.hostname, |
| 2364 | uuid=status_jobs[0]['uuid']), |
| 2365 | status_jobs[0]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2366 | self.assertEqual('project-test1', status_jobs[1]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2367 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2368 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2369 | uuid=status_jobs[1]['uuid']), |
| 2370 | status_jobs[1]['url']) |
| 2371 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2372 | 'finger://{hostname}/{uuid}'.format( |
| 2373 | hostname=self.executor_server.hostname, |
| 2374 | uuid=status_jobs[1]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2375 | status_jobs[1]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2376 | self.assertEqual( |
| 2377 | 'finger://{hostname}/{uuid}'.format( |
| 2378 | hostname=self.executor_server.hostname, |
| 2379 | uuid=status_jobs[1]['uuid']), |
| 2380 | status_jobs[1]['report_url']) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2381 | |
| 2382 | self.assertEqual('project-test2', status_jobs[2]['name']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2383 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2384 | 'static/stream.html?uuid={uuid}&logfile=console.log'.format( |
| 2385 | uuid=status_jobs[2]['uuid']), |
| 2386 | status_jobs[2]['url']) |
| 2387 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2388 | 'finger://{hostname}/{uuid}'.format( |
| 2389 | hostname=self.executor_server.hostname, |
| 2390 | uuid=status_jobs[2]['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 2391 | status_jobs[2]['finger_url']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 2392 | self.assertEqual( |
| 2393 | 'finger://{hostname}/{uuid}'.format( |
| 2394 | hostname=self.executor_server.hostname, |
| 2395 | uuid=status_jobs[2]['uuid']), |
| 2396 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2397 | |
Tobias Henkel | 65639f8 | 2017-07-10 10:25:42 +0200 | [diff] [blame] | 2398 | # check job dependencies |
| 2399 | self.assertIsNotNone(status_jobs[0]['dependencies']) |
| 2400 | self.assertIsNotNone(status_jobs[1]['dependencies']) |
| 2401 | self.assertIsNotNone(status_jobs[2]['dependencies']) |
| 2402 | self.assertEqual(len(status_jobs[0]['dependencies']), 0) |
| 2403 | self.assertEqual(len(status_jobs[1]['dependencies']), 1) |
| 2404 | self.assertEqual(len(status_jobs[2]['dependencies']), 1) |
| 2405 | self.assertIn('project-merge', status_jobs[1]['dependencies']) |
| 2406 | self.assertIn('project-merge', status_jobs[2]['dependencies']) |
| 2407 | |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2408 | def test_live_reconfiguration(self): |
| 2409 | "Test that live reconfiguration works" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2410 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2411 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2412 | A.addApproval('Code-Review', 2) |
| 2413 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2414 | self.waitUntilSettled() |
| 2415 | |
| 2416 | self.sched.reconfigure(self.config) |
James E. Blair | bd96363 | 2017-02-01 09:58:14 -0800 | [diff] [blame] | 2417 | self.waitUntilSettled() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2418 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2419 | self.executor_server.hold_jobs_in_build = False |
| 2420 | self.executor_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2421 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2422 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2423 | 'SUCCESS') |
| 2424 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2425 | 'SUCCESS') |
| 2426 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2427 | 'SUCCESS') |
| 2428 | self.assertEqual(A.data['status'], 'MERGED') |
| 2429 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2430 | |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2431 | def test_live_reconfiguration_merge_conflict(self): |
| 2432 | # A real-world bug: a change in a gate queue has a merge |
| 2433 | # conflict and a job is added to its project while it's |
| 2434 | # sitting in the queue. The job gets added to the change and |
| 2435 | # enqueued and the change gets stuck. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2436 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2437 | |
| 2438 | # This change is fine. It's here to stop the queue long |
| 2439 | # enough for the next change to be subject to the |
| 2440 | # reconfiguration, as well as to provide a conflict for the |
| 2441 | # next change. This change will succeed and merge. |
| 2442 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2443 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2444 | A.addApproval('Code-Review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2445 | |
| 2446 | # This change will be in merge conflict. During the |
| 2447 | # reconfiguration, we will add a job. We want to make sure |
| 2448 | # that doesn't cause it to get stuck. |
| 2449 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2450 | B.addPatchset({'conflict': 'B'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2451 | B.addApproval('Code-Review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2452 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2453 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 2454 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2455 | |
| 2456 | self.waitUntilSettled() |
| 2457 | |
| 2458 | # No jobs have run yet |
| 2459 | self.assertEqual(A.data['status'], 'NEW') |
| 2460 | self.assertEqual(A.reported, 1) |
| 2461 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2462 | self.assertEqual(len(self.history), 0) |
| 2463 | |
| 2464 | # Add the "project-test3" job. |
Clint Byrum | 073c00b | 2017-05-01 13:41:23 -0700 | [diff] [blame] | 2465 | self.commitConfigUpdate('common-config', |
| 2466 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2467 | self.sched.reconfigure(self.config) |
| 2468 | self.waitUntilSettled() |
| 2469 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2470 | self.executor_server.hold_jobs_in_build = False |
| 2471 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2472 | self.waitUntilSettled() |
| 2473 | |
| 2474 | self.assertEqual(A.data['status'], 'MERGED') |
| 2475 | self.assertEqual(A.reported, 2) |
| 2476 | self.assertEqual(B.data['status'], 'NEW') |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 2477 | self.assertIn('Merge Failed', B.messages[-1]) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2478 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2479 | 'SUCCESS') |
| 2480 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2481 | 'SUCCESS') |
| 2482 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2483 | 'SUCCESS') |
| 2484 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2485 | 'SUCCESS') |
| 2486 | self.assertEqual(len(self.history), 4) |
| 2487 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2488 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2489 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2490 | # that tests a job added to a job tree with a failed root does |
| 2491 | # not run. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2492 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2493 | |
| 2494 | # This change is fine. It's here to stop the queue long |
| 2495 | # enough for the next change to be subject to the |
| 2496 | # reconfiguration. This change will succeed and merge. |
| 2497 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2498 | A.addPatchset({'conflict': 'A'}) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2499 | A.addApproval('Code-Review', 2) |
| 2500 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2501 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2502 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2503 | self.waitUntilSettled() |
| 2504 | |
| 2505 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2506 | self.executor_server.failJob('project-merge', B) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2507 | B.addApproval('Code-Review', 2) |
| 2508 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2509 | self.waitUntilSettled() |
| 2510 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2511 | self.executor_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2512 | self.waitUntilSettled() |
| 2513 | |
| 2514 | # Both -merge jobs have run, but no others. |
| 2515 | self.assertEqual(A.data['status'], 'NEW') |
| 2516 | self.assertEqual(A.reported, 1) |
| 2517 | self.assertEqual(B.data['status'], 'NEW') |
| 2518 | self.assertEqual(B.reported, 1) |
| 2519 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2520 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2521 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2522 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2523 | self.assertEqual(len(self.history), 2) |
| 2524 | |
| 2525 | # Add the "project-test3" job. |
Clint Byrum | 3147d65 | 2017-05-01 14:01:42 -0700 | [diff] [blame] | 2526 | self.commitConfigUpdate('common-config', |
| 2527 | 'layouts/live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2528 | self.sched.reconfigure(self.config) |
| 2529 | self.waitUntilSettled() |
| 2530 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2531 | self.executor_server.hold_jobs_in_build = False |
| 2532 | self.executor_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2533 | self.waitUntilSettled() |
| 2534 | |
| 2535 | self.assertEqual(A.data['status'], 'MERGED') |
| 2536 | self.assertEqual(A.reported, 2) |
| 2537 | self.assertEqual(B.data['status'], 'NEW') |
| 2538 | self.assertEqual(B.reported, 2) |
| 2539 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2540 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2541 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2542 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2543 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2544 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2545 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2546 | self.assertEqual(len(self.history), 5) |
| 2547 | |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2548 | def test_live_reconfiguration_failed_job(self): |
| 2549 | # Test that a change with a removed failing job does not |
| 2550 | # disrupt reconfiguration. If a change has a failed job and |
| 2551 | # that job is removed during a reconfiguration, we observed a |
| 2552 | # bug where the code to re-set build statuses would run on |
| 2553 | # that build and raise an exception because the job no longer |
| 2554 | # existed. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2555 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2556 | |
| 2557 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2558 | |
| 2559 | # This change will fail and later be removed by the reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2560 | self.executor_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2561 | |
| 2562 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2563 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2564 | self.executor_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2565 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2566 | self.executor_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2567 | self.waitUntilSettled() |
| 2568 | |
| 2569 | self.assertEqual(A.data['status'], 'NEW') |
| 2570 | self.assertEqual(A.reported, 0) |
| 2571 | |
| 2572 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2573 | 'SUCCESS') |
| 2574 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2575 | 'FAILURE') |
| 2576 | self.assertEqual(len(self.history), 2) |
| 2577 | |
| 2578 | # Remove the test1 job. |
Clint Byrum | 841a58c | 2017-05-01 14:17:21 -0700 | [diff] [blame] | 2579 | self.commitConfigUpdate('common-config', |
| 2580 | 'layouts/live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2581 | self.sched.reconfigure(self.config) |
| 2582 | self.waitUntilSettled() |
| 2583 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2584 | self.executor_server.hold_jobs_in_build = False |
| 2585 | self.executor_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2586 | self.waitUntilSettled() |
| 2587 | |
| 2588 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2589 | 'SUCCESS') |
| 2590 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2591 | 'SUCCESS') |
| 2592 | self.assertEqual(len(self.history), 4) |
| 2593 | |
| 2594 | self.assertEqual(A.data['status'], 'NEW') |
| 2595 | self.assertEqual(A.reported, 1) |
| 2596 | self.assertIn('Build succeeded', A.messages[0]) |
| 2597 | # Ensure the removed job was not included in the report. |
| 2598 | self.assertNotIn('project-test1', A.messages[0]) |
| 2599 | |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2600 | def test_live_reconfiguration_shared_queue(self): |
| 2601 | # Test that a change with a failing job which was removed from |
| 2602 | # this project but otherwise still exists in the system does |
| 2603 | # not disrupt reconfiguration. |
| 2604 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2605 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2606 | |
| 2607 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2608 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2609 | self.executor_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2610 | |
| 2611 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2612 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2613 | self.executor_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2614 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2615 | self.executor_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2616 | self.waitUntilSettled() |
| 2617 | |
| 2618 | self.assertEqual(A.data['status'], 'NEW') |
| 2619 | self.assertEqual(A.reported, 0) |
| 2620 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2621 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2622 | 'SUCCESS') |
| 2623 | self.assertEqual(self.getJobFromHistory( |
| 2624 | 'project1-project2-integration').result, 'FAILURE') |
| 2625 | self.assertEqual(len(self.history), 2) |
| 2626 | |
| 2627 | # Remove the integration job. |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2628 | self.commitConfigUpdate( |
| 2629 | 'common-config', |
| 2630 | 'layouts/live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2631 | self.sched.reconfigure(self.config) |
| 2632 | self.waitUntilSettled() |
| 2633 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2634 | self.executor_server.hold_jobs_in_build = False |
| 2635 | self.executor_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2636 | self.waitUntilSettled() |
| 2637 | |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2638 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2639 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2640 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2641 | 'SUCCESS') |
Clint Byrum | 69663d4 | 2017-05-01 14:51:04 -0700 | [diff] [blame] | 2642 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2643 | 'SUCCESS') |
| 2644 | self.assertEqual(self.getJobFromHistory( |
| 2645 | 'project1-project2-integration').result, 'FAILURE') |
| 2646 | self.assertEqual(len(self.history), 4) |
| 2647 | |
| 2648 | self.assertEqual(A.data['status'], 'NEW') |
| 2649 | self.assertEqual(A.reported, 1) |
| 2650 | self.assertIn('Build succeeded', A.messages[0]) |
| 2651 | # Ensure the removed job was not included in the report. |
| 2652 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2653 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2654 | def test_double_live_reconfiguration_shared_queue(self): |
| 2655 | # This was a real-world regression. A change is added to |
| 2656 | # gate; a reconfigure happens, a second change which depends |
| 2657 | # on the first is added, and a second reconfiguration happens. |
| 2658 | # Ensure that both changes merge. |
| 2659 | |
| 2660 | # A failure may indicate incorrect caching or cleaning up of |
| 2661 | # references during a reconfiguration. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2662 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2663 | |
| 2664 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2665 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2666 | B.setDependsOn(A, 1) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2667 | A.addApproval('Code-Review', 2) |
| 2668 | B.addApproval('Code-Review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2669 | |
| 2670 | # Add the parent change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2671 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2672 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2673 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2674 | self.waitUntilSettled() |
| 2675 | |
| 2676 | # Reconfigure (with only one change in the pipeline). |
| 2677 | self.sched.reconfigure(self.config) |
| 2678 | self.waitUntilSettled() |
| 2679 | |
| 2680 | # Add the child change. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2681 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2682 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2683 | self.executor_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2684 | self.waitUntilSettled() |
| 2685 | |
| 2686 | # Reconfigure (with both in the pipeline). |
| 2687 | self.sched.reconfigure(self.config) |
| 2688 | self.waitUntilSettled() |
| 2689 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2690 | self.executor_server.hold_jobs_in_build = False |
| 2691 | self.executor_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2692 | self.waitUntilSettled() |
| 2693 | |
| 2694 | self.assertEqual(len(self.history), 8) |
| 2695 | |
| 2696 | self.assertEqual(A.data['status'], 'MERGED') |
| 2697 | self.assertEqual(A.reported, 2) |
| 2698 | self.assertEqual(B.data['status'], 'MERGED') |
| 2699 | self.assertEqual(B.reported, 2) |
| 2700 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2701 | def test_live_reconfiguration_del_project(self): |
| 2702 | # Test project deletion from layout |
| 2703 | # while changes are enqueued |
| 2704 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2705 | self.executor_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2706 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2707 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2708 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2709 | |
| 2710 | # A Depends-On: B |
| 2711 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2712 | A.subject, B.data['id']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2713 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2714 | |
| 2715 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2716 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2717 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2718 | self.executor_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2719 | self.waitUntilSettled() |
| 2720 | self.assertEqual(len(self.builds), 5) |
| 2721 | |
| 2722 | # This layout defines only org/project, not org/project1 |
James E. Blair | 31cb3e8 | 2017-04-20 13:08:56 -0700 | [diff] [blame] | 2723 | self.commitConfigUpdate( |
| 2724 | 'common-config', |
| 2725 | 'layouts/live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2726 | self.sched.reconfigure(self.config) |
| 2727 | self.waitUntilSettled() |
| 2728 | |
| 2729 | # Builds for C aborted, builds for A succeed, |
| 2730 | # and have change B applied ahead |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2731 | job_c = self.getJobFromHistory('project-test1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2732 | self.assertEqual(job_c.changes, '3,1') |
| 2733 | self.assertEqual(job_c.result, 'ABORTED') |
| 2734 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2735 | self.executor_server.hold_jobs_in_build = False |
| 2736 | self.executor_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2737 | self.waitUntilSettled() |
| 2738 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2739 | self.assertEqual( |
| 2740 | self.getJobFromHistory('project-test1', 'org/project').changes, |
| 2741 | '2,1 1,1') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2742 | |
| 2743 | self.assertEqual(A.data['status'], 'NEW') |
| 2744 | self.assertEqual(B.data['status'], 'NEW') |
| 2745 | self.assertEqual(C.data['status'], 'NEW') |
| 2746 | self.assertEqual(A.reported, 1) |
| 2747 | self.assertEqual(B.reported, 0) |
| 2748 | self.assertEqual(C.reported, 0) |
| 2749 | |
Clint Byrum | 0149ada | 2017-04-04 12:22:01 -0700 | [diff] [blame] | 2750 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 2751 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2752 | self.assertIn('Build succeeded', A.messages[0]) |
| 2753 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2754 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2755 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2756 | self.updateConfigLayout( |
| 2757 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2758 | self.sched.reconfigure(self.config) |
| 2759 | |
| 2760 | self.init_repo("org/new-project") |
| 2761 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2762 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2763 | A.addApproval('Code-Review', 2) |
| 2764 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2765 | self.waitUntilSettled() |
| 2766 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2767 | 'SUCCESS') |
| 2768 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2769 | 'SUCCESS') |
| 2770 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2771 | 'SUCCESS') |
| 2772 | self.assertEqual(A.data['status'], 'MERGED') |
| 2773 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2774 | |
James E. Blair | 9ea7007 | 2017-04-19 16:05:30 -0700 | [diff] [blame] | 2775 | @simple_layout('layouts/repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2776 | def test_repo_deleted(self): |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2777 | self.init_repo("org/delete-project") |
| 2778 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2779 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2780 | A.addApproval('Code-Review', 2) |
| 2781 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2782 | self.waitUntilSettled() |
| 2783 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2784 | 'SUCCESS') |
| 2785 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2786 | 'SUCCESS') |
| 2787 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2788 | 'SUCCESS') |
| 2789 | self.assertEqual(A.data['status'], 'MERGED') |
| 2790 | self.assertEqual(A.reported, 2) |
| 2791 | |
| 2792 | # Delete org/new-project zuul repo. Should be recloned. |
James E. Blair | 8c1be53 | 2017-02-07 14:04:12 -0800 | [diff] [blame] | 2793 | p = 'org/delete-project' |
Monty Taylor | d642d85 | 2017-02-23 14:05:42 -0500 | [diff] [blame] | 2794 | if os.path.exists(os.path.join(self.merger_src_root, p)): |
| 2795 | shutil.rmtree(os.path.join(self.merger_src_root, p)) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2796 | if os.path.exists(os.path.join(self.executor_src_root, p)): |
| 2797 | shutil.rmtree(os.path.join(self.executor_src_root, p)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2798 | |
| 2799 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 2800 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 2801 | B.addApproval('Code-Review', 2) |
| 2802 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2803 | self.waitUntilSettled() |
| 2804 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2805 | 'SUCCESS') |
| 2806 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2807 | 'SUCCESS') |
| 2808 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2809 | 'SUCCESS') |
| 2810 | self.assertEqual(B.data['status'], 'MERGED') |
| 2811 | self.assertEqual(B.reported, 2) |
| 2812 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2813 | @simple_layout('layouts/tags.yaml') |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2814 | def test_tags(self): |
| 2815 | "Test job tags" |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2816 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2817 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 2818 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2819 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2820 | self.waitUntilSettled() |
| 2821 | |
James E. Blair | e68d43f | 2017-04-19 14:03:30 -0700 | [diff] [blame] | 2822 | self.assertEqual(len(self.history), 2) |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2823 | |
| 2824 | results = {self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2825 | project='org/project1').uuid: ['extratag', 'merge'], |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2826 | self.getJobFromHistory('merge', |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2827 | project='org/project2').uuid: ['merge']} |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2828 | |
| 2829 | for build in self.history: |
Cullen Taylor | 3aa6d47 | 2017-03-01 15:22:09 -0600 | [diff] [blame] | 2830 | self.assertEqual(results.get(build.uuid, ''), |
James E. Blair | 9d46f09 | 2017-07-20 16:06:20 -0700 | [diff] [blame] | 2831 | build.parameters['zuul'].get('jobtags')) |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 2832 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2833 | def test_timer(self): |
| 2834 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2835 | # This test can not use simple_layout because it must start |
| 2836 | # with a configuration which does not include a |
| 2837 | # timer-triggered job so that we have an opportunity to set |
| 2838 | # the hold flag before the first job. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2839 | self.create_branch('org/project', 'stable') |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2840 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2841 | self.commitConfigUpdate('common-config', 'layouts/timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2842 | self.sched.reconfigure(self.config) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2843 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2844 | # The pipeline triggers every second, so we should have seen |
| 2845 | # several by now. |
| 2846 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2847 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2848 | |
| 2849 | self.assertEqual(len(self.builds), 2) |
| 2850 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2851 | port = self.webapp.server.socket.getsockname()[1] |
| 2852 | |
Clint Byrum | 5e729e9 | 2017-02-08 06:34:57 -0800 | [diff] [blame] | 2853 | req = urllib.request.Request( |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2854 | "http://localhost:%s/tenant-one/status" % port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2855 | f = urllib.request.urlopen(req) |
Clint Byrum | f322fe2 | 2017-05-10 20:53:12 -0700 | [diff] [blame] | 2856 | data = f.read().decode('utf8') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2857 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2858 | self.executor_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2859 | # Stop queuing timer triggered jobs so that the assertions |
| 2860 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2861 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2862 | self.sched.reconfigure(self.config) |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2863 | self.waitUntilSettled() |
| 2864 | # If APScheduler is in mid-event when we remove the job, we |
| 2865 | # can end up with one more event firing, so give it an extra |
| 2866 | # second to settle. |
| 2867 | time.sleep(1) |
| 2868 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2869 | self.executor_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2870 | self.waitUntilSettled() |
| 2871 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2872 | self.assertHistory([ |
| 2873 | dict(name='project-bitrot', result='SUCCESS', |
| 2874 | ref='refs/heads/master'), |
| 2875 | dict(name='project-bitrot', result='SUCCESS', |
| 2876 | ref='refs/heads/stable'), |
| 2877 | ], ordered=False) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2878 | |
| 2879 | data = json.loads(data) |
| 2880 | status_jobs = set() |
| 2881 | for p in data['pipelines']: |
| 2882 | for q in p['change_queues']: |
| 2883 | for head in q['heads']: |
| 2884 | for change in head: |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2885 | for job in change['jobs']: |
| 2886 | status_jobs.add(job['name']) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2887 | self.assertIn('project-bitrot', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2888 | |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2889 | def test_idle(self): |
| 2890 | "Test that frequent periodic jobs work" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2891 | # This test can not use simple_layout because it must start |
| 2892 | # with a configuration which does not include a |
| 2893 | # timer-triggered job so that we have an opportunity to set |
| 2894 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2895 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2896 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2897 | for x in range(1, 3): |
| 2898 | # Test that timer triggers periodic jobs even across |
| 2899 | # layout config reloads. |
| 2900 | # Start timer trigger |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2901 | self.commitConfigUpdate('common-config', |
| 2902 | 'layouts/idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2903 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2904 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2905 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2906 | # The pipeline triggers every second, so we should have seen |
| 2907 | # several by now. |
| 2908 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2909 | |
| 2910 | # Stop queuing timer triggered jobs so that the assertions |
| 2911 | # below don't race against more jobs being queued. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2912 | self.commitConfigUpdate('common-config', |
| 2913 | 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2914 | self.sched.reconfigure(self.config) |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 2915 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2916 | # If APScheduler is in mid-event when we remove the job, |
| 2917 | # we can end up with one more event firing, so give it an |
| 2918 | # extra second to settle. |
| 2919 | time.sleep(1) |
| 2920 | self.waitUntilSettled() |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2921 | self.assertEqual(len(self.builds), 1, |
Clint Byrum | 58264dc | 2017-02-07 21:21:22 -0800 | [diff] [blame] | 2922 | 'Timer builds iteration #%d' % x) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2923 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2924 | self.waitUntilSettled() |
| 2925 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 2926 | self.assertEqual(len(self.history), x) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 2927 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 2928 | @simple_layout('layouts/smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2929 | def test_check_smtp_pool(self): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2930 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2931 | self.waitUntilSettled() |
| 2932 | |
| 2933 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2934 | self.waitUntilSettled() |
| 2935 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2936 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2937 | |
| 2938 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2939 | # work on the knowledge of what the first message should be as |
| 2940 | # it is only configured to go to SMTP. |
| 2941 | |
| 2942 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2943 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2944 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2945 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2946 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2947 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2948 | |
| 2949 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2950 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2951 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2952 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 2953 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2954 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 2955 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2956 | def test_timer_smtp(self): |
| 2957 | "Test that a periodic job is triggered" |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2958 | # This test can not use simple_layout because it must start |
| 2959 | # with a configuration which does not include a |
| 2960 | # timer-triggered job so that we have an opportunity to set |
| 2961 | # the hold flag before the first job. |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2962 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2963 | self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2964 | self.sched.reconfigure(self.config) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2965 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2966 | # The pipeline triggers every second, so we should have seen |
| 2967 | # several by now. |
| 2968 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2969 | self.waitUntilSettled() |
| 2970 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2971 | self.assertEqual(len(self.builds), 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 2972 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2973 | self.waitUntilSettled() |
| 2974 | self.assertEqual(len(self.history), 2) |
| 2975 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2976 | self.assertEqual(self.getJobFromHistory( |
| 2977 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 2978 | self.assertEqual(self.getJobFromHistory( |
| 2979 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 2980 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2981 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2982 | |
| 2983 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 2984 | # work on the knowledge of what the first message should be as |
| 2985 | # it is only configured to go to SMTP. |
| 2986 | |
| 2987 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2988 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2989 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2990 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2991 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 2992 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 2993 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2994 | # Stop queuing timer triggered jobs and let any that may have |
| 2995 | # queued through so that end of test assertions pass. |
James E. Blair | dfdfcfc | 2017-04-20 10:19:20 -0700 | [diff] [blame] | 2996 | self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 2997 | self.sched.reconfigure(self.config) |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 2998 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 2999 | # If APScheduler is in mid-event when we remove the job, we |
| 3000 | # can end up with one more event firing, so give it an extra |
| 3001 | # second to settle. |
| 3002 | time.sleep(1) |
| 3003 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3004 | self.executor_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3005 | self.waitUntilSettled() |
| 3006 | |
Joshua Hesketh | 25695cb | 2017-03-06 12:50:04 +1100 | [diff] [blame] | 3007 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3008 | def test_timer_sshkey(self): |
| 3009 | "Test that a periodic job can setup SSH key authentication" |
| 3010 | self.worker.hold_jobs_in_build = True |
| 3011 | self.config.set('zuul', 'layout_config', |
| 3012 | 'tests/fixtures/layout-timer.yaml') |
| 3013 | self.sched.reconfigure(self.config) |
| 3014 | self.registerJobs() |
| 3015 | |
| 3016 | # The pipeline triggers every second, so we should have seen |
| 3017 | # several by now. |
| 3018 | time.sleep(5) |
| 3019 | self.waitUntilSettled() |
| 3020 | |
| 3021 | self.assertEqual(len(self.builds), 2) |
| 3022 | |
| 3023 | ssh_wrapper = os.path.join(self.git_root, ".ssh_wrapper_gerrit") |
| 3024 | self.assertTrue(os.path.isfile(ssh_wrapper)) |
| 3025 | with open(ssh_wrapper) as f: |
| 3026 | ssh_wrapper_content = f.read() |
| 3027 | self.assertIn("fake_id_rsa", ssh_wrapper_content) |
| 3028 | # In the unit tests Merger runs in the same process, |
| 3029 | # so we see its' environment variables |
| 3030 | self.assertEqual(os.environ['GIT_SSH'], ssh_wrapper) |
| 3031 | |
| 3032 | self.worker.release('.*') |
| 3033 | self.waitUntilSettled() |
| 3034 | self.assertEqual(len(self.history), 2) |
| 3035 | |
| 3036 | self.assertEqual(self.getJobFromHistory( |
| 3037 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3038 | self.assertEqual(self.getJobFromHistory( |
| 3039 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3040 | |
| 3041 | # Stop queuing timer triggered jobs and let any that may have |
| 3042 | # queued through so that end of test assertions pass. |
| 3043 | self.config.set('zuul', 'layout_config', |
| 3044 | 'tests/fixtures/layout-no-timer.yaml') |
| 3045 | self.sched.reconfigure(self.config) |
| 3046 | self.registerJobs() |
| 3047 | self.waitUntilSettled() |
James E. Blair | 78ae478 | 2017-08-02 14:19:10 -0700 | [diff] [blame] | 3048 | # If APScheduler is in mid-event when we remove the job, we |
| 3049 | # can end up with one more event firing, so give it an extra |
| 3050 | # second to settle. |
| 3051 | time.sleep(1) |
| 3052 | self.waitUntilSettled() |
Evgeny Antyshev | da90a50 | 2017-02-08 08:42:59 +0000 | [diff] [blame] | 3053 | self.worker.release('.*') |
| 3054 | self.waitUntilSettled() |
| 3055 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3056 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3057 | "Test that the RPC client can enqueue a change" |
| 3058 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3059 | A.addApproval('Code-Review', 2) |
| 3060 | A.addApproval('Approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3061 | |
| 3062 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3063 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3064 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3065 | r = client.enqueue(tenant='tenant-one', |
| 3066 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3067 | project='org/project', |
| 3068 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3069 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3070 | self.waitUntilSettled() |
| 3071 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3072 | 'SUCCESS') |
| 3073 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3074 | 'SUCCESS') |
| 3075 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3076 | 'SUCCESS') |
| 3077 | self.assertEqual(A.data['status'], 'MERGED') |
| 3078 | self.assertEqual(A.reported, 2) |
| 3079 | self.assertEqual(r, True) |
| 3080 | |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3081 | def test_client_enqueue_ref(self): |
| 3082 | "Test that the RPC client can enqueue a ref" |
| 3083 | |
| 3084 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3085 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3086 | self.addCleanup(client.shutdown) |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3087 | r = client.enqueue_ref( |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3088 | tenant='tenant-one', |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3089 | pipeline='post', |
| 3090 | project='org/project', |
| 3091 | trigger='gerrit', |
| 3092 | ref='master', |
| 3093 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3094 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3095 | self.waitUntilSettled() |
| 3096 | job_names = [x.name for x in self.history] |
| 3097 | self.assertEqual(len(self.history), 1) |
| 3098 | self.assertIn('project-post', job_names) |
| 3099 | self.assertEqual(r, True) |
| 3100 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3101 | def test_client_enqueue_negative(self): |
| 3102 | "Test that the RPC client returns errors" |
| 3103 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3104 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3105 | self.addCleanup(client.shutdown) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3106 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3107 | "Invalid tenant"): |
| 3108 | r = client.enqueue(tenant='tenant-foo', |
| 3109 | pipeline='gate', |
| 3110 | project='org/project', |
| 3111 | trigger='gerrit', |
| 3112 | change='1,1') |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3113 | self.assertEqual(r, False) |
| 3114 | |
| 3115 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3116 | "Invalid project"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3117 | r = client.enqueue(tenant='tenant-one', |
| 3118 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3119 | project='project-does-not-exist', |
| 3120 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3121 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3122 | self.assertEqual(r, False) |
| 3123 | |
| 3124 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3125 | "Invalid pipeline"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3126 | r = client.enqueue(tenant='tenant-one', |
| 3127 | pipeline='pipeline-does-not-exist', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3128 | project='org/project', |
| 3129 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3130 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3131 | self.assertEqual(r, False) |
| 3132 | |
| 3133 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3134 | "Invalid trigger"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3135 | r = client.enqueue(tenant='tenant-one', |
| 3136 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3137 | project='org/project', |
| 3138 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3139 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3140 | self.assertEqual(r, False) |
| 3141 | |
| 3142 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3143 | "Invalid change"): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3144 | r = client.enqueue(tenant='tenant-one', |
| 3145 | pipeline='gate', |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3146 | project='org/project', |
| 3147 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3148 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3149 | self.assertEqual(r, False) |
| 3150 | |
| 3151 | self.waitUntilSettled() |
| 3152 | self.assertEqual(len(self.history), 0) |
| 3153 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3154 | |
| 3155 | def test_client_promote(self): |
| 3156 | "Test that the RPC client can promote a change" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3157 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3158 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3159 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3160 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3161 | A.addApproval('Code-Review', 2) |
| 3162 | B.addApproval('Code-Review', 2) |
| 3163 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3164 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3165 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3166 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3167 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3168 | |
| 3169 | self.waitUntilSettled() |
| 3170 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3171 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 3172 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3173 | enqueue_times = {} |
| 3174 | for item in items: |
| 3175 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3176 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3177 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3178 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3179 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3180 | r = client.promote(tenant='tenant-one', |
| 3181 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3182 | change_ids=['2,1', '3,1']) |
| 3183 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3184 | # ensure that enqueue times are durable |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3185 | items = tenant.layout.pipelines['gate'].getAllItems() |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3186 | for item in items: |
| 3187 | self.assertEqual( |
| 3188 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3189 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3190 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3191 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3192 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3193 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3194 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3195 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3196 | self.waitUntilSettled() |
| 3197 | |
| 3198 | self.assertEqual(len(self.builds), 6) |
| 3199 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3200 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3201 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3202 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3203 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3204 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3205 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3206 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3207 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3208 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3209 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3210 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3211 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3212 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3213 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3214 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3215 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3216 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3217 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3218 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3219 | self.waitUntilSettled() |
| 3220 | |
| 3221 | self.assertEqual(A.data['status'], 'MERGED') |
| 3222 | self.assertEqual(A.reported, 2) |
| 3223 | self.assertEqual(B.data['status'], 'MERGED') |
| 3224 | self.assertEqual(B.reported, 2) |
| 3225 | self.assertEqual(C.data['status'], 'MERGED') |
| 3226 | self.assertEqual(C.reported, 2) |
| 3227 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3228 | self.assertEqual(r, True) |
| 3229 | |
| 3230 | def test_client_promote_dependent(self): |
| 3231 | "Test that the RPC client can promote a dependent change" |
| 3232 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3233 | # A -> C (depends on B) -> B |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3234 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3235 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3236 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3237 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3238 | |
| 3239 | C.setDependsOn(B, 1) |
| 3240 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3241 | A.addApproval('Code-Review', 2) |
| 3242 | B.addApproval('Code-Review', 2) |
| 3243 | C.addApproval('Code-Review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3244 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3245 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3246 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3247 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3248 | |
| 3249 | self.waitUntilSettled() |
| 3250 | |
| 3251 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3252 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3253 | self.addCleanup(client.shutdown) |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3254 | r = client.promote(tenant='tenant-one', |
| 3255 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3256 | change_ids=['3,1']) |
| 3257 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3258 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3259 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3260 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3261 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3262 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3263 | self.executor_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3264 | self.waitUntilSettled() |
| 3265 | |
| 3266 | self.assertEqual(len(self.builds), 6) |
| 3267 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3268 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3269 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3270 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3271 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3272 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3273 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3274 | self.assertTrue(self.builds[0].hasChanges(B)) |
| 3275 | self.assertFalse(self.builds[0].hasChanges(A)) |
| 3276 | self.assertFalse(self.builds[0].hasChanges(C)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3277 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3278 | self.assertTrue(self.builds[2].hasChanges(B)) |
| 3279 | self.assertTrue(self.builds[2].hasChanges(C)) |
| 3280 | self.assertFalse(self.builds[2].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3281 | |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3282 | self.assertTrue(self.builds[4].hasChanges(B)) |
| 3283 | self.assertTrue(self.builds[4].hasChanges(C)) |
| 3284 | self.assertTrue(self.builds[4].hasChanges(A)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3285 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3286 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3287 | self.waitUntilSettled() |
| 3288 | |
| 3289 | self.assertEqual(A.data['status'], 'MERGED') |
| 3290 | self.assertEqual(A.reported, 2) |
| 3291 | self.assertEqual(B.data['status'], 'MERGED') |
| 3292 | self.assertEqual(B.reported, 2) |
| 3293 | self.assertEqual(C.data['status'], 'MERGED') |
| 3294 | self.assertEqual(C.reported, 2) |
| 3295 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3296 | self.assertEqual(r, True) |
| 3297 | |
| 3298 | def test_client_promote_negative(self): |
| 3299 | "Test that the RPC client returns errors for promotion" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3300 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3301 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3302 | A.addApproval('Code-Review', 2) |
| 3303 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3304 | self.waitUntilSettled() |
| 3305 | |
| 3306 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3307 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3308 | self.addCleanup(client.shutdown) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3309 | |
| 3310 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3311 | r = client.promote(tenant='tenant-one', |
| 3312 | pipeline='nonexistent', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3313 | change_ids=['2,1', '3,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3314 | self.assertEqual(r, False) |
| 3315 | |
| 3316 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
Paul Belanger | baca313 | 2016-11-04 12:49:54 -0400 | [diff] [blame] | 3317 | r = client.promote(tenant='tenant-one', |
| 3318 | pipeline='gate', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3319 | change_ids=['4,1']) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3320 | self.assertEqual(r, False) |
| 3321 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3322 | self.executor_server.hold_jobs_in_build = False |
| 3323 | self.executor_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3324 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3325 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3326 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3327 | def test_queue_rate_limiting(self): |
| 3328 | "Test that DependentPipelines are rate limited with dep across window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3329 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3330 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3331 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3332 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3333 | |
| 3334 | C.setDependsOn(B, 1) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3335 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3336 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3337 | A.addApproval('Code-Review', 2) |
| 3338 | B.addApproval('Code-Review', 2) |
| 3339 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3340 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3341 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3342 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3343 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3344 | self.waitUntilSettled() |
| 3345 | |
| 3346 | # Only A and B will have their merge jobs queued because |
| 3347 | # window is 2. |
| 3348 | self.assertEqual(len(self.builds), 2) |
| 3349 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3350 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3351 | |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3352 | # Release the merge jobs one at a time. |
| 3353 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3354 | self.waitUntilSettled() |
James E. Blair | 732ee86 | 2017-04-21 07:49:26 -0700 | [diff] [blame] | 3355 | self.builds[0].release() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3356 | self.waitUntilSettled() |
| 3357 | |
| 3358 | # Only A and B will have their test jobs queued because |
| 3359 | # window is 2. |
| 3360 | self.assertEqual(len(self.builds), 4) |
| 3361 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3362 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3363 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3364 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3365 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3366 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3367 | self.waitUntilSettled() |
| 3368 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3369 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | b01f1ca | 2017-04-02 10:19:52 -0700 | [diff] [blame] | 3370 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3371 | # A failed so window is reduced by 1 to 1. |
| 3372 | self.assertEqual(queue.window, 1) |
| 3373 | self.assertEqual(queue.window_floor, 1) |
| 3374 | self.assertEqual(A.data['status'], 'NEW') |
| 3375 | |
| 3376 | # Gate is reset and only B's merge job is queued because |
| 3377 | # window shrunk to 1. |
| 3378 | self.assertEqual(len(self.builds), 1) |
| 3379 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3380 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3381 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3382 | self.waitUntilSettled() |
| 3383 | |
| 3384 | # Only B's test jobs are queued because window is still 1. |
| 3385 | self.assertEqual(len(self.builds), 2) |
| 3386 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3387 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3388 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3389 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3390 | self.waitUntilSettled() |
| 3391 | |
| 3392 | # B was successfully merged so window is increased to 2. |
| 3393 | self.assertEqual(queue.window, 2) |
| 3394 | self.assertEqual(queue.window_floor, 1) |
| 3395 | self.assertEqual(B.data['status'], 'MERGED') |
| 3396 | |
| 3397 | # Only C is left and its merge job is queued. |
| 3398 | self.assertEqual(len(self.builds), 1) |
| 3399 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3400 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3401 | self.executor_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3402 | self.waitUntilSettled() |
| 3403 | |
| 3404 | # After successful merge job the test jobs for C are queued. |
| 3405 | self.assertEqual(len(self.builds), 2) |
| 3406 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3407 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3408 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3409 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3410 | self.waitUntilSettled() |
| 3411 | |
| 3412 | # C successfully merged so window is bumped to 3. |
| 3413 | self.assertEqual(queue.window, 3) |
| 3414 | self.assertEqual(queue.window_floor, 1) |
| 3415 | self.assertEqual(C.data['status'], 'MERGED') |
| 3416 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3417 | @simple_layout('layouts/rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3418 | def test_queue_rate_limiting_dependent(self): |
| 3419 | "Test that DependentPipelines are rate limited with dep in window" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3420 | self.executor_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3421 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3422 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3423 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3424 | |
| 3425 | B.setDependsOn(A, 1) |
| 3426 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3427 | self.executor_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3428 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3429 | A.addApproval('Code-Review', 2) |
| 3430 | B.addApproval('Code-Review', 2) |
| 3431 | C.addApproval('Code-Review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3432 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3433 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3434 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3435 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3436 | self.waitUntilSettled() |
| 3437 | |
| 3438 | # Only A and B will have their merge jobs queued because |
| 3439 | # window is 2. |
| 3440 | self.assertEqual(len(self.builds), 2) |
| 3441 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3442 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3443 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3444 | self.orderedRelease(2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3445 | |
| 3446 | # Only A and B will have their test jobs queued because |
| 3447 | # window is 2. |
| 3448 | self.assertEqual(len(self.builds), 4) |
| 3449 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3450 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3451 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3452 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3453 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3454 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3455 | self.waitUntilSettled() |
| 3456 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3457 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 14ab6ca | 2017-04-03 10:15:10 -0700 | [diff] [blame] | 3458 | queue = tenant.layout.pipelines['gate'].queues[0] |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3459 | # A failed so window is reduced by 1 to 1. |
| 3460 | self.assertEqual(queue.window, 1) |
| 3461 | self.assertEqual(queue.window_floor, 1) |
| 3462 | self.assertEqual(A.data['status'], 'NEW') |
| 3463 | self.assertEqual(B.data['status'], 'NEW') |
| 3464 | |
| 3465 | # Gate is reset and only C's merge job is queued because |
| 3466 | # window shrunk to 1 and A and B were dequeued. |
| 3467 | self.assertEqual(len(self.builds), 1) |
| 3468 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3469 | |
James E. Blair | f4a5f02 | 2017-04-18 14:01:10 -0700 | [diff] [blame] | 3470 | self.orderedRelease(1) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3471 | |
| 3472 | # Only C's test jobs are queued because window is still 1. |
| 3473 | self.assertEqual(len(self.builds), 2) |
James E. Blair | df25ddc | 2017-07-08 07:57:09 -0700 | [diff] [blame] | 3474 | builds = self.getSortedBuilds() |
| 3475 | self.assertEqual(builds[0].name, 'project-test1') |
| 3476 | self.assertEqual(builds[1].name, 'project-test2') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3477 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3478 | self.executor_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3479 | self.waitUntilSettled() |
| 3480 | |
| 3481 | # C was successfully merged so window is increased to 2. |
| 3482 | self.assertEqual(queue.window, 2) |
| 3483 | self.assertEqual(queue.window_floor, 1) |
| 3484 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3485 | |
| 3486 | def test_worker_update_metadata(self): |
| 3487 | "Test if a worker can send back metadata about itself" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3488 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3489 | |
| 3490 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3491 | A.addApproval('Code-Review', 2) |
| 3492 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3493 | self.waitUntilSettled() |
| 3494 | |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3495 | self.assertEqual(len(self.executor_client.builds), 1) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3496 | |
| 3497 | self.log.debug('Current builds:') |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3498 | self.log.debug(self.executor_client.builds) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3499 | |
| 3500 | start = time.time() |
| 3501 | while True: |
| 3502 | if time.time() - start > 10: |
| 3503 | raise Exception("Timeout waiting for gearman server to report " |
| 3504 | + "back to the client") |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3505 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3506 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3507 | break |
| 3508 | else: |
| 3509 | time.sleep(0) |
| 3510 | |
| 3511 | self.log.debug(build) |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3512 | self.assertEqual(self.executor_server.hostname, build.worker.name) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3513 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3514 | self.executor_server.hold_jobs_in_build = False |
| 3515 | self.executor_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3516 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3517 | |
James E. Blair | cc32419 | 2017-04-19 14:36:08 -0700 | [diff] [blame] | 3518 | @simple_layout('layouts/footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3519 | def test_footer_message(self): |
| 3520 | "Test a pipeline's footer message is correctly added to the report." |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3521 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3522 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3523 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3524 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3525 | self.waitUntilSettled() |
| 3526 | |
| 3527 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3528 | B.addApproval('Code-Review', 2) |
| 3529 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3530 | self.waitUntilSettled() |
| 3531 | |
| 3532 | self.assertEqual(2, len(self.smtp_messages)) |
| 3533 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3534 | failure_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3535 | Build failed. For information on how to proceed, see \ |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3536 | http://wiki.example.org/Test_Failures""" |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3537 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3538 | footer_msg = """\ |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3539 | For CI problems and help debugging, contact ci@example.org""" |
| 3540 | |
Adam Gandelman | 82258fd | 2017-02-07 16:51:58 -0800 | [diff] [blame] | 3541 | self.assertTrue(self.smtp_messages[0]['body'].startswith(failure_msg)) |
| 3542 | self.assertTrue(self.smtp_messages[0]['body'].endswith(footer_msg)) |
| 3543 | self.assertFalse(self.smtp_messages[1]['body'].startswith(failure_msg)) |
| 3544 | self.assertTrue(self.smtp_messages[1]['body'].endswith(footer_msg)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3545 | |
Tobias Henkel | 9842bd7 | 2017-05-16 13:40:03 +0200 | [diff] [blame] | 3546 | @simple_layout('layouts/unmanaged-project.yaml') |
| 3547 | def test_unmanaged_project_start_message(self): |
| 3548 | "Test start reporting is not done for unmanaged projects." |
| 3549 | self.init_repo("org/project", tag='init') |
| 3550 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3551 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3552 | self.waitUntilSettled() |
| 3553 | |
| 3554 | self.assertEqual(0, len(A.messages)) |
| 3555 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3556 | @simple_layout('layouts/merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3557 | def test_merge_failure_reporters(self): |
| 3558 | """Check that the config is set up correctly""" |
| 3559 | |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3560 | tenant = self.sched.abide.tenants.get('tenant-one') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3561 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3562 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3563 | "dependencies was unable to be automatically merged with the " |
| 3564 | "current state of its repository. Please rebase the change and " |
| 3565 | "upload a new patchset.", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3566 | tenant.layout.pipelines['check'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3567 | self.assertEqual( |
| 3568 | "The merge failed! For more information...", |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3569 | tenant.layout.pipelines['gate'].merge_failure_message) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3570 | |
| 3571 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3572 | len(tenant.layout.pipelines['check'].merge_failure_actions), 1) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3573 | self.assertEqual( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3574 | len(tenant.layout.pipelines['gate'].merge_failure_actions), 2) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3575 | |
| 3576 | self.assertTrue(isinstance( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3577 | tenant.layout.pipelines['check'].merge_failure_actions[0], |
| 3578 | gerritreporter.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3579 | |
| 3580 | self.assertTrue( |
| 3581 | ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3582 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3583 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3584 | zuul.driver.smtp.smtpreporter.SMTPReporter) and |
| 3585 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3586 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3587 | gerritreporter.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3588 | ) or ( |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3589 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3590 | merge_failure_actions[0], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3591 | gerritreporter.GerritReporter) and |
| 3592 | isinstance(tenant.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3593 | merge_failure_actions[1], |
Clint Byrum | b9de8be | 2017-05-27 13:49:19 -0700 | [diff] [blame] | 3594 | zuul.driver.smtp.smtpreporter.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3595 | ) |
| 3596 | ) |
| 3597 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3598 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3599 | def test_merge_failure_reports(self): |
| 3600 | """Check that when a change fails to merge the correct message is sent |
| 3601 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3602 | self.updateConfigLayout( |
| 3603 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3604 | self.sched.reconfigure(self.config) |
| 3605 | self.registerJobs() |
| 3606 | |
| 3607 | # Check a test failure isn't reported to SMTP |
| 3608 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3609 | A.addApproval('Code-Review', 2) |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3610 | self.executor_server.failJob('project-test1', A) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3611 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3612 | self.waitUntilSettled() |
| 3613 | |
| 3614 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3615 | self.assertEqual(0, len(self.smtp_messages)) |
| 3616 | |
| 3617 | # Check a merge failure is reported to SMTP |
| 3618 | # B should be merged, but C will conflict with B |
| 3619 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3620 | B.addPatchset(['conflict']) |
| 3621 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3622 | C.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3623 | B.addApproval('Code-Review', 2) |
| 3624 | C.addApproval('Code-Review', 2) |
| 3625 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 3626 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3627 | self.waitUntilSettled() |
| 3628 | |
| 3629 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3630 | self.assertEqual(1, len(self.smtp_messages)) |
| 3631 | self.assertEqual('The merge failed! For more information...', |
| 3632 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3633 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3634 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3635 | def test_default_merge_failure_reports(self): |
| 3636 | """Check that the default merge failure reports are correct.""" |
| 3637 | |
| 3638 | # A should report success, B should report merge failure. |
| 3639 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3640 | A.addPatchset(['conflict']) |
| 3641 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3642 | B.addPatchset(['conflict']) |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3643 | A.addApproval('Code-Review', 2) |
| 3644 | B.addApproval('Code-Review', 2) |
| 3645 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 3646 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3647 | self.waitUntilSettled() |
| 3648 | |
| 3649 | self.assertEqual(3, len(self.history)) # A jobs |
| 3650 | self.assertEqual(A.reported, 2) |
| 3651 | self.assertEqual(B.reported, 2) |
| 3652 | self.assertEqual(A.data['status'], 'MERGED') |
| 3653 | self.assertEqual(B.data['status'], 'NEW') |
| 3654 | self.assertIn('Build succeeded', A.messages[1]) |
| 3655 | self.assertIn('Merge Failed', B.messages[1]) |
| 3656 | self.assertIn('automatically merged', B.messages[1]) |
| 3657 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3658 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3659 | |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3660 | def test_client_get_running_jobs(self): |
| 3661 | "Test that the RPC client can get a list of running jobs" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3662 | self.executor_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3663 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3664 | A.addApproval('Code-Review', 2) |
| 3665 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3666 | self.waitUntilSettled() |
| 3667 | |
| 3668 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3669 | self.gearman_server.port) |
Clark Boylan | df4eba2 | 2017-04-24 17:37:58 -0700 | [diff] [blame] | 3670 | self.addCleanup(client.shutdown) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3671 | |
| 3672 | # Wait for gearman server to send the initial workData back to zuul |
| 3673 | start = time.time() |
| 3674 | while True: |
| 3675 | if time.time() - start > 10: |
| 3676 | raise Exception("Timeout waiting for gearman server to report " |
| 3677 | + "back to the client") |
Clint Byrum | 1d0c7d1 | 2017-05-10 19:40:53 -0700 | [diff] [blame] | 3678 | build = list(self.executor_client.builds.values())[0] |
Monty Taylor | eea6bb9 | 2017-06-14 11:56:54 -0500 | [diff] [blame] | 3679 | if build.worker.name == self.executor_server.hostname: |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3680 | break |
| 3681 | else: |
| 3682 | time.sleep(0) |
| 3683 | |
| 3684 | running_items = client.get_running_jobs() |
| 3685 | |
| 3686 | self.assertEqual(1, len(running_items)) |
| 3687 | running_item = running_items[0] |
| 3688 | self.assertEqual([], running_item['failing_reasons']) |
| 3689 | self.assertEqual([], running_item['items_behind']) |
| 3690 | self.assertEqual('https://hostname/1', running_item['url']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3691 | self.assertIsNone(running_item['item_ahead']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3692 | self.assertEqual('org/project', running_item['project']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3693 | self.assertIsNone(running_item['remaining_time']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3694 | self.assertEqual(True, running_item['active']) |
| 3695 | self.assertEqual('1,1', running_item['id']) |
| 3696 | |
| 3697 | self.assertEqual(3, len(running_item['jobs'])) |
| 3698 | for job in running_item['jobs']: |
| 3699 | if job['name'] == 'project-merge': |
| 3700 | self.assertEqual('project-merge', job['name']) |
| 3701 | self.assertEqual('gate', job['pipeline']) |
| 3702 | self.assertEqual(False, job['retry']) |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3703 | self.assertEqual( |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3704 | 'static/stream.html?uuid={uuid}&logfile=console.log' |
| 3705 | .format(uuid=job['uuid']), job['url']) |
| 3706 | self.assertEqual( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 3707 | 'finger://{hostname}/{uuid}'.format( |
| 3708 | hostname=self.executor_server.hostname, |
| 3709 | uuid=job['uuid']), |
Tobias Henkel | b4407fc | 2017-07-07 13:52:56 +0200 | [diff] [blame] | 3710 | job['finger_url']) |
Clint Byrum | d4de79a | 2017-05-27 11:39:13 -0700 | [diff] [blame] | 3711 | self.assertEqual(2, len(job['worker'])) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3712 | self.assertEqual(False, job['canceled']) |
| 3713 | self.assertEqual(True, job['voting']) |
Monty Taylor | 38b553a | 2017-06-05 13:06:10 -0500 | [diff] [blame] | 3714 | self.assertIsNone(job['result']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3715 | self.assertEqual('gate', job['pipeline']) |
| 3716 | break |
| 3717 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3718 | self.executor_server.hold_jobs_in_build = False |
| 3719 | self.executor_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3720 | self.waitUntilSettled() |
| 3721 | |
| 3722 | running_items = client.get_running_jobs() |
| 3723 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3724 | |
James E. Blair | b70e55a | 2017-04-19 12:57:02 -0700 | [diff] [blame] | 3725 | @simple_layout('layouts/nonvoting-pipeline.yaml') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3726 | def test_nonvoting_pipeline(self): |
| 3727 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3728 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3729 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3730 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3731 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3732 | self.waitUntilSettled() |
Paul Belanger | 15e3e20 | 2016-10-14 16:27:34 -0400 | [diff] [blame] | 3733 | |
| 3734 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3735 | 'SUCCESS') |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3736 | self.assertEqual( |
| 3737 | self.getJobFromHistory('experimental-project-test').result, |
| 3738 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3739 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3740 | |
| 3741 | def test_crd_gate(self): |
| 3742 | "Test cross-repo dependencies" |
| 3743 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3744 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3745 | A.addApproval('Code-Review', 2) |
| 3746 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3747 | |
| 3748 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3749 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3750 | AM2.setMerged() |
| 3751 | AM1.setMerged() |
| 3752 | |
| 3753 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3754 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3755 | BM2.setMerged() |
| 3756 | BM1.setMerged() |
| 3757 | |
| 3758 | # A -> AM1 -> AM2 |
| 3759 | # B -> BM1 -> BM2 |
| 3760 | # A Depends-On: B |
| 3761 | # M2 is here to make sure it is never queried. If it is, it |
| 3762 | # means zuul is walking down the entire history of merged |
| 3763 | # changes. |
| 3764 | |
| 3765 | B.setDependsOn(BM1, 1) |
| 3766 | BM1.setDependsOn(BM2, 1) |
| 3767 | |
| 3768 | A.setDependsOn(AM1, 1) |
| 3769 | AM1.setDependsOn(AM2, 1) |
| 3770 | |
| 3771 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3772 | A.subject, B.data['id']) |
| 3773 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3774 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3775 | self.waitUntilSettled() |
| 3776 | |
| 3777 | self.assertEqual(A.data['status'], 'NEW') |
| 3778 | self.assertEqual(B.data['status'], 'NEW') |
| 3779 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3780 | for connection in self.connections.connections.values(): |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3781 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3782 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3783 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3784 | B.addApproval('Approved', 1) |
| 3785 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3786 | self.waitUntilSettled() |
| 3787 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3788 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3789 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3790 | self.executor_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3791 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3792 | self.executor_server.hold_jobs_in_build = False |
| 3793 | self.executor_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3794 | self.waitUntilSettled() |
| 3795 | |
| 3796 | self.assertEqual(AM2.queried, 0) |
| 3797 | self.assertEqual(BM2.queried, 0) |
| 3798 | self.assertEqual(A.data['status'], 'MERGED') |
| 3799 | self.assertEqual(B.data['status'], 'MERGED') |
| 3800 | self.assertEqual(A.reported, 2) |
| 3801 | self.assertEqual(B.reported, 2) |
| 3802 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3803 | changes = self.getJobFromHistory( |
| 3804 | 'project-merge', 'org/project1').changes |
| 3805 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3806 | |
| 3807 | def test_crd_branch(self): |
| 3808 | "Test cross-repo dependencies in multiple branches" |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3809 | |
| 3810 | self.create_branch('org/project2', 'mp') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3811 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3812 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3813 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 3814 | C.data['id'] = B.data['id'] |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3815 | A.addApproval('Code-Review', 2) |
| 3816 | B.addApproval('Code-Review', 2) |
| 3817 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3818 | |
| 3819 | # A Depends-On: B+C |
| 3820 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3821 | A.subject, B.data['id']) |
| 3822 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3823 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3824 | B.addApproval('Approved', 1) |
| 3825 | C.addApproval('Approved', 1) |
| 3826 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3827 | self.waitUntilSettled() |
| 3828 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3829 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3830 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3831 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3832 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3833 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3834 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3835 | self.executor_server.hold_jobs_in_build = False |
| 3836 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3837 | self.waitUntilSettled() |
| 3838 | |
| 3839 | self.assertEqual(A.data['status'], 'MERGED') |
| 3840 | self.assertEqual(B.data['status'], 'MERGED') |
| 3841 | self.assertEqual(C.data['status'], 'MERGED') |
| 3842 | self.assertEqual(A.reported, 2) |
| 3843 | self.assertEqual(B.reported, 2) |
| 3844 | self.assertEqual(C.reported, 2) |
| 3845 | |
Paul Belanger | 6379db1 | 2016-11-14 13:57:54 -0500 | [diff] [blame] | 3846 | changes = self.getJobFromHistory( |
| 3847 | 'project-merge', 'org/project1').changes |
| 3848 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3849 | |
| 3850 | def test_crd_multiline(self): |
| 3851 | "Test multiple depends-on lines in commit" |
| 3852 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3853 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3854 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3855 | A.addApproval('Code-Review', 2) |
| 3856 | B.addApproval('Code-Review', 2) |
| 3857 | C.addApproval('Code-Review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3858 | |
| 3859 | # A Depends-On: B+C |
| 3860 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 3861 | A.subject, B.data['id'], C.data['id']) |
| 3862 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3863 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3864 | B.addApproval('Approved', 1) |
| 3865 | C.addApproval('Approved', 1) |
| 3866 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3867 | self.waitUntilSettled() |
| 3868 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3869 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3870 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3871 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3872 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3873 | self.executor_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3874 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3875 | self.executor_server.hold_jobs_in_build = False |
| 3876 | self.executor_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3877 | self.waitUntilSettled() |
| 3878 | |
| 3879 | self.assertEqual(A.data['status'], 'MERGED') |
| 3880 | self.assertEqual(B.data['status'], 'MERGED') |
| 3881 | self.assertEqual(C.data['status'], 'MERGED') |
| 3882 | self.assertEqual(A.reported, 2) |
| 3883 | self.assertEqual(B.reported, 2) |
| 3884 | self.assertEqual(C.reported, 2) |
| 3885 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3886 | changes = self.getJobFromHistory( |
| 3887 | 'project-merge', 'org/project1').changes |
| 3888 | self.assertEqual(changes, '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3889 | |
| 3890 | def test_crd_unshared_gate(self): |
| 3891 | "Test cross-repo dependencies in unshared gate queues" |
| 3892 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3893 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3894 | A.addApproval('Code-Review', 2) |
| 3895 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3896 | |
| 3897 | # A Depends-On: B |
| 3898 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3899 | A.subject, B.data['id']) |
| 3900 | |
| 3901 | # A and B do not share a queue, make sure that A is unable to |
| 3902 | # enqueue B (and therefore, A is unable to be enqueued). |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3903 | B.addApproval('Approved', 1) |
| 3904 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3905 | self.waitUntilSettled() |
| 3906 | |
| 3907 | self.assertEqual(A.data['status'], 'NEW') |
| 3908 | self.assertEqual(B.data['status'], 'NEW') |
| 3909 | self.assertEqual(A.reported, 0) |
| 3910 | self.assertEqual(B.reported, 0) |
| 3911 | self.assertEqual(len(self.history), 0) |
| 3912 | |
| 3913 | # Enqueue and merge B alone. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3914 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3915 | self.waitUntilSettled() |
| 3916 | |
| 3917 | self.assertEqual(B.data['status'], 'MERGED') |
| 3918 | self.assertEqual(B.reported, 2) |
| 3919 | |
| 3920 | # Now that B is merged, A should be able to be enqueued and |
| 3921 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3922 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3923 | self.waitUntilSettled() |
| 3924 | |
| 3925 | self.assertEqual(A.data['status'], 'MERGED') |
| 3926 | self.assertEqual(A.reported, 2) |
| 3927 | |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3928 | def test_crd_gate_reverse(self): |
| 3929 | "Test reverse cross-repo dependencies" |
| 3930 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3931 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3932 | A.addApproval('Code-Review', 2) |
| 3933 | B.addApproval('Code-Review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3934 | |
| 3935 | # A Depends-On: B |
| 3936 | |
| 3937 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3938 | A.subject, B.data['id']) |
| 3939 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3940 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3941 | self.waitUntilSettled() |
| 3942 | |
| 3943 | self.assertEqual(A.data['status'], 'NEW') |
| 3944 | self.assertEqual(B.data['status'], 'NEW') |
| 3945 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3946 | self.executor_server.hold_jobs_in_build = True |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3947 | A.addApproval('Approved', 1) |
| 3948 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3949 | self.waitUntilSettled() |
| 3950 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3951 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3952 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3953 | self.executor_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3954 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 3955 | self.executor_server.hold_jobs_in_build = False |
| 3956 | self.executor_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3957 | self.waitUntilSettled() |
| 3958 | |
| 3959 | self.assertEqual(A.data['status'], 'MERGED') |
| 3960 | self.assertEqual(B.data['status'], 'MERGED') |
| 3961 | self.assertEqual(A.reported, 2) |
| 3962 | self.assertEqual(B.reported, 2) |
| 3963 | |
Paul Belanger | 5dccbe7 | 2016-11-14 11:17:37 -0500 | [diff] [blame] | 3964 | changes = self.getJobFromHistory( |
| 3965 | 'project-merge', 'org/project1').changes |
| 3966 | self.assertEqual(changes, '2,1 1,1') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 3967 | |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3968 | def test_crd_cycle(self): |
| 3969 | "Test cross-repo dependency cycles" |
| 3970 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3971 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3972 | A.addApproval('Code-Review', 2) |
| 3973 | B.addApproval('Code-Review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3974 | |
| 3975 | # A -> B -> A (via commit-depends) |
| 3976 | |
| 3977 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3978 | A.subject, B.data['id']) |
| 3979 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3980 | B.subject, A.data['id']) |
| 3981 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3982 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3983 | self.waitUntilSettled() |
| 3984 | |
| 3985 | self.assertEqual(A.reported, 0) |
| 3986 | self.assertEqual(B.reported, 0) |
| 3987 | self.assertEqual(A.data['status'], 'NEW') |
| 3988 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 3989 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3990 | def test_crd_gate_unknown(self): |
| 3991 | "Test unknown projects in dependent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 3992 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3993 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3994 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 3995 | A.addApproval('Code-Review', 2) |
| 3996 | B.addApproval('Code-Review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 3997 | |
| 3998 | # A Depends-On: B |
| 3999 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4000 | A.subject, B.data['id']) |
| 4001 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4002 | B.addApproval('Approved', 1) |
| 4003 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4004 | self.waitUntilSettled() |
| 4005 | |
| 4006 | # Unknown projects cannot share a queue with any other |
| 4007 | # since they don't have common jobs with any other (they have no jobs). |
| 4008 | # Changes which depend on unknown project changes |
| 4009 | # should not be processed in dependent pipeline |
| 4010 | self.assertEqual(A.data['status'], 'NEW') |
| 4011 | self.assertEqual(B.data['status'], 'NEW') |
| 4012 | self.assertEqual(A.reported, 0) |
| 4013 | self.assertEqual(B.reported, 0) |
| 4014 | self.assertEqual(len(self.history), 0) |
| 4015 | |
James E. Blair | 7720b40 | 2017-06-07 08:51:49 -0700 | [diff] [blame] | 4016 | # Simulate change B being gated outside this layout Set the |
| 4017 | # change merged before submitting the event so that when the |
| 4018 | # event triggers a gerrit query to update the change, we get |
| 4019 | # the information that it was merged. |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4020 | B.setMerged() |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4021 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4022 | self.waitUntilSettled() |
| 4023 | self.assertEqual(len(self.history), 0) |
| 4024 | |
| 4025 | # Now that B is merged, A should be able to be enqueued and |
| 4026 | # merged. |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4027 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4028 | self.waitUntilSettled() |
| 4029 | |
| 4030 | self.assertEqual(A.data['status'], 'MERGED') |
| 4031 | self.assertEqual(A.reported, 2) |
| 4032 | self.assertEqual(B.data['status'], 'MERGED') |
| 4033 | self.assertEqual(B.reported, 0) |
| 4034 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4035 | def test_crd_check(self): |
| 4036 | "Test cross-repo dependencies in independent pipelines" |
| 4037 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4038 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4039 | self.gearman_server.hold_jobs_in_queue = True |
| 4040 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4041 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4042 | |
| 4043 | # A Depends-On: B |
| 4044 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4045 | A.subject, B.data['id']) |
| 4046 | |
| 4047 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4048 | self.waitUntilSettled() |
| 4049 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4050 | self.gearman_server.hold_jobs_in_queue = False |
| 4051 | self.gearman_server.release() |
| 4052 | self.waitUntilSettled() |
| 4053 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4054 | self.executor_server.release('.*-merge') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4055 | self.waitUntilSettled() |
| 4056 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4057 | self.assertTrue(self.builds[0].hasChanges(A, B)) |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4058 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4059 | self.executor_server.hold_jobs_in_build = False |
| 4060 | self.executor_server.release() |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4061 | self.waitUntilSettled() |
| 4062 | |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4063 | self.assertEqual(A.data['status'], 'NEW') |
| 4064 | self.assertEqual(B.data['status'], 'NEW') |
| 4065 | self.assertEqual(A.reported, 1) |
| 4066 | self.assertEqual(B.reported, 0) |
| 4067 | |
| 4068 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | b30342b | 2016-11-14 12:30:43 -0500 | [diff] [blame] | 4069 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4070 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4071 | |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4072 | def test_crd_check_git_depends(self): |
| 4073 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4074 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4075 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4076 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4077 | |
| 4078 | # Add two git-dependent changes and make sure they both report |
| 4079 | # success. |
| 4080 | B.setDependsOn(A, 1) |
| 4081 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4082 | self.waitUntilSettled() |
| 4083 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4084 | self.waitUntilSettled() |
| 4085 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4086 | self.orderedRelease() |
| 4087 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4088 | self.waitUntilSettled() |
| 4089 | |
| 4090 | self.assertEqual(A.data['status'], 'NEW') |
| 4091 | self.assertEqual(B.data['status'], 'NEW') |
| 4092 | self.assertEqual(A.reported, 1) |
| 4093 | self.assertEqual(B.reported, 1) |
| 4094 | |
| 4095 | self.assertEqual(self.history[0].changes, '1,1') |
| 4096 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4097 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4098 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4099 | |
| 4100 | self.assertIn('Build succeeded', A.messages[0]) |
| 4101 | self.assertIn('Build succeeded', B.messages[0]) |
| 4102 | |
| 4103 | def test_crd_check_duplicate(self): |
| 4104 | "Test duplicate check in independent pipelines" |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4105 | self.executor_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4106 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4107 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4108 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4109 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4110 | |
| 4111 | # Add two git-dependent changes... |
| 4112 | B.setDependsOn(A, 1) |
| 4113 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4114 | self.waitUntilSettled() |
| 4115 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4116 | |
| 4117 | # ...make sure the live one is not duplicated... |
| 4118 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4119 | self.waitUntilSettled() |
| 4120 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4121 | |
| 4122 | # ...but the non-live one is able to be. |
| 4123 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4124 | self.waitUntilSettled() |
| 4125 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4126 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4127 | # Release jobs in order to avoid races with change A jobs |
| 4128 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4129 | self.orderedRelease() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4130 | self.executor_server.hold_jobs_in_build = False |
| 4131 | self.executor_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4132 | self.waitUntilSettled() |
| 4133 | |
| 4134 | self.assertEqual(A.data['status'], 'NEW') |
| 4135 | self.assertEqual(B.data['status'], 'NEW') |
| 4136 | self.assertEqual(A.reported, 1) |
| 4137 | self.assertEqual(B.reported, 1) |
| 4138 | |
| 4139 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4140 | self.assertEqual(self.history[1].changes, '1,1') |
Paul Belanger | 0813696 | 2016-11-03 17:57:38 -0400 | [diff] [blame] | 4141 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4142 | |
| 4143 | self.assertIn('Build succeeded', A.messages[0]) |
| 4144 | self.assertIn('Build succeeded', B.messages[0]) |
| 4145 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4146 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4147 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4148 | |
| 4149 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4150 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4151 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4152 | |
| 4153 | # A Depends-On: B |
| 4154 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4155 | A.subject, B.data['id']) |
| 4156 | |
| 4157 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4158 | self.waitUntilSettled() |
| 4159 | |
| 4160 | self.sched.reconfigure(self.config) |
| 4161 | |
| 4162 | # Make sure the items still share a change queue, and the |
| 4163 | # first one is not live. |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4164 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 4165 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 1) |
| 4166 | queue = tenant.layout.pipelines['check'].queues[0] |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4167 | first_item = queue.queue[0] |
| 4168 | for item in queue.queue: |
| 4169 | self.assertEqual(item.queue, first_item.queue) |
| 4170 | self.assertFalse(first_item.live) |
| 4171 | self.assertTrue(queue.queue[1].live) |
| 4172 | |
| 4173 | self.gearman_server.hold_jobs_in_queue = False |
| 4174 | self.gearman_server.release() |
| 4175 | self.waitUntilSettled() |
| 4176 | |
| 4177 | self.assertEqual(A.data['status'], 'NEW') |
| 4178 | self.assertEqual(B.data['status'], 'NEW') |
| 4179 | self.assertEqual(A.reported, 1) |
| 4180 | self.assertEqual(B.reported, 0) |
| 4181 | |
| 4182 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
Paul Belanger | ce4485f | 2016-11-11 17:01:56 -0500 | [diff] [blame] | 4183 | self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4184 | |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4185 | def test_crd_check_reconfiguration(self): |
| 4186 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4187 | |
| 4188 | def test_crd_undefined_project(self): |
| 4189 | """Test that undefined projects in dependencies are handled for |
| 4190 | independent pipelines""" |
| 4191 | # It's a hack for fake gerrit, |
| 4192 | # as it implies repo creation upon the creation of any change |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4193 | self.init_repo("org/unknown", tag='init') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4194 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4195 | |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4196 | @simple_layout('layouts/ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4197 | def test_crd_check_ignore_dependencies(self): |
| 4198 | "Test cross-repo dependencies can be ignored" |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4199 | |
| 4200 | self.gearman_server.hold_jobs_in_queue = True |
| 4201 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4202 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4203 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4204 | |
| 4205 | # A Depends-On: B |
| 4206 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4207 | A.subject, B.data['id']) |
| 4208 | # C git-depends on B |
| 4209 | C.setDependsOn(B, 1) |
| 4210 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4211 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4212 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4213 | self.waitUntilSettled() |
| 4214 | |
| 4215 | # Make sure none of the items share a change queue, and all |
| 4216 | # are live. |
Jesse Keating | ea68ab4 | 2017-04-19 15:03:30 -0700 | [diff] [blame] | 4217 | tenant = self.sched.abide.tenants.get('tenant-one') |
Clint Byrum | 12282ca | 2017-04-03 11:04:02 -0700 | [diff] [blame] | 4218 | check_pipeline = tenant.layout.pipelines['check'] |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4219 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4220 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4221 | for item in check_pipeline.getAllItems(): |
| 4222 | self.assertTrue(item.live) |
| 4223 | |
| 4224 | self.gearman_server.hold_jobs_in_queue = False |
| 4225 | self.gearman_server.release() |
| 4226 | self.waitUntilSettled() |
| 4227 | |
| 4228 | self.assertEqual(A.data['status'], 'NEW') |
| 4229 | self.assertEqual(B.data['status'], 'NEW') |
| 4230 | self.assertEqual(C.data['status'], 'NEW') |
| 4231 | self.assertEqual(A.reported, 1) |
| 4232 | self.assertEqual(B.reported, 1) |
| 4233 | self.assertEqual(C.reported, 1) |
| 4234 | |
| 4235 | # Each job should have tested exactly one change |
| 4236 | for job in self.history: |
| 4237 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4238 | |
James E. Blair | 7cb8454 | 2017-04-19 13:35:05 -0700 | [diff] [blame] | 4239 | @simple_layout('layouts/three-projects.yaml') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4240 | def test_crd_check_transitive(self): |
| 4241 | "Test transitive cross-repo dependencies" |
| 4242 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4243 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4244 | # and C,2 (not C,1 which would indicate stale data in the |
| 4245 | # cache for B). |
| 4246 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4247 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4248 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4249 | |
| 4250 | # A Depends-On: B |
| 4251 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4252 | A.subject, B.data['id']) |
| 4253 | |
| 4254 | # B Depends-On: C |
| 4255 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4256 | B.subject, C.data['id']) |
| 4257 | |
| 4258 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4259 | self.waitUntilSettled() |
| 4260 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4261 | |
| 4262 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4263 | self.waitUntilSettled() |
| 4264 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4265 | |
| 4266 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4267 | self.waitUntilSettled() |
| 4268 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4269 | |
| 4270 | C.addPatchset() |
| 4271 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4272 | self.waitUntilSettled() |
| 4273 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4274 | |
| 4275 | A.addPatchset() |
| 4276 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4277 | self.waitUntilSettled() |
| 4278 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4279 | |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4280 | def test_crd_check_unknown(self): |
| 4281 | "Test unknown projects in independent pipeline" |
James E. Blair | c4ba97a | 2017-04-19 16:26:24 -0700 | [diff] [blame] | 4282 | self.init_repo("org/unknown", tag='init') |
James E. Blair | a8b90b3 | 2016-08-24 15:18:50 -0700 | [diff] [blame] | 4283 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4284 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'D') |
| 4285 | # A Depends-On: B |
| 4286 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4287 | A.subject, B.data['id']) |
| 4288 | |
| 4289 | # Make sure zuul has seen an event on B. |
| 4290 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4291 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4292 | self.waitUntilSettled() |
| 4293 | |
| 4294 | self.assertEqual(A.data['status'], 'NEW') |
| 4295 | self.assertEqual(A.reported, 1) |
| 4296 | self.assertEqual(B.data['status'], 'NEW') |
| 4297 | self.assertEqual(B.reported, 0) |
| 4298 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4299 | def test_crd_cycle_join(self): |
| 4300 | "Test an updated change creates a cycle" |
| 4301 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4302 | |
| 4303 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4304 | self.waitUntilSettled() |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4305 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4306 | |
| 4307 | # Create B->A |
| 4308 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4309 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4310 | B.subject, A.data['id']) |
| 4311 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4312 | self.waitUntilSettled() |
| 4313 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4314 | # Dep is there so zuul should have reported on B |
| 4315 | self.assertEqual(B.reported, 1) |
| 4316 | |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4317 | # Update A to add A->B (a cycle). |
| 4318 | A.addPatchset() |
| 4319 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4320 | A.subject, B.data['id']) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4321 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4322 | self.waitUntilSettled() |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4323 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4324 | # Dependency cycle injected so zuul should not have reported again on A |
| 4325 | self.assertEqual(A.reported, 1) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4326 | |
| 4327 | # Now if we update B to remove the depends-on, everything |
| 4328 | # should be okay. B; A->B |
| 4329 | |
| 4330 | B.addPatchset() |
| 4331 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4332 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4333 | self.waitUntilSettled() |
Paul Belanger | 0e155e2 | 2016-11-14 14:12:23 -0500 | [diff] [blame] | 4334 | |
Tobias Henkel | 6b9390f | 2017-03-28 11:23:21 +0200 | [diff] [blame] | 4335 | # Cycle was removed so now zuul should have reported again on A |
| 4336 | self.assertEqual(A.reported, 2) |
| 4337 | |
| 4338 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 4339 | self.waitUntilSettled() |
| 4340 | self.assertEqual(B.reported, 2) |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4341 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4342 | @simple_layout('layouts/disable_at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4343 | def test_disable_at(self): |
| 4344 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4345 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4346 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4347 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4348 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4349 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4350 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4351 | |
| 4352 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4353 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4354 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4355 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4356 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4357 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4358 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4359 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4360 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4361 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4362 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4363 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4364 | self.executor_server.failJob('project-test1', A) |
| 4365 | self.executor_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4366 | # Let C pass, resetting the counter |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4367 | self.executor_server.failJob('project-test1', D) |
| 4368 | self.executor_server.failJob('project-test1', E) |
| 4369 | self.executor_server.failJob('project-test1', F) |
| 4370 | self.executor_server.failJob('project-test1', G) |
| 4371 | self.executor_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4372 | # I also passes but should only report to the disabled reporters |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4373 | self.executor_server.failJob('project-test1', J) |
| 4374 | self.executor_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4375 | |
| 4376 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4377 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4378 | self.waitUntilSettled() |
| 4379 | |
| 4380 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4381 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4382 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4383 | |
| 4384 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4385 | self.waitUntilSettled() |
| 4386 | |
| 4387 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4388 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4389 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4390 | |
| 4391 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4392 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4393 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4394 | self.waitUntilSettled() |
| 4395 | |
| 4396 | # We should be disabled now |
| 4397 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4398 | 3, tenant.layout.pipelines['check']._consecutive_failures) |
| 4399 | self.assertTrue(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4400 | |
| 4401 | # We need to wait between each of these patches to make sure the |
| 4402 | # smtp messages come back in an expected order |
| 4403 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4404 | self.waitUntilSettled() |
| 4405 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4406 | self.waitUntilSettled() |
| 4407 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4408 | self.waitUntilSettled() |
| 4409 | |
| 4410 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4411 | # leaving a message on each change |
| 4412 | self.assertEqual(1, len(A.messages)) |
| 4413 | self.assertIn('Build failed.', A.messages[0]) |
| 4414 | self.assertEqual(1, len(B.messages)) |
| 4415 | self.assertIn('Build failed.', B.messages[0]) |
| 4416 | self.assertEqual(1, len(C.messages)) |
| 4417 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4418 | self.assertEqual(1, len(D.messages)) |
| 4419 | self.assertIn('Build failed.', D.messages[0]) |
| 4420 | self.assertEqual(1, len(E.messages)) |
| 4421 | self.assertIn('Build failed.', E.messages[0]) |
| 4422 | self.assertEqual(1, len(F.messages)) |
| 4423 | self.assertIn('Build failed.', F.messages[0]) |
| 4424 | |
| 4425 | # The last 3 (GHI) would have only reported via smtp. |
| 4426 | self.assertEqual(3, len(self.smtp_messages)) |
| 4427 | self.assertEqual(0, len(G.messages)) |
| 4428 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4429 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4430 | 'project-test1 finger://', self.smtp_messages[0]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4431 | self.assertEqual(0, len(H.messages)) |
| 4432 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4433 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4434 | 'project-test1 finger://', self.smtp_messages[1]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4435 | self.assertEqual(0, len(I.messages)) |
| 4436 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4437 | self.assertIn( |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4438 | 'project-test1 finger://', self.smtp_messages[2]['body']) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4439 | |
| 4440 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4441 | # comes out of disabled |
| 4442 | self.sched.reconfigure(self.config) |
| 4443 | |
Jesse Keating | cc67b12 | 2017-04-19 14:54:57 -0700 | [diff] [blame] | 4444 | tenant = self.sched.abide.tenants.get('tenant-one') |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4445 | |
| 4446 | self.assertEqual(3, tenant.layout.pipelines['check'].disable_at) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4447 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4448 | 0, tenant.layout.pipelines['check']._consecutive_failures) |
| 4449 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4450 | |
| 4451 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4452 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4453 | self.waitUntilSettled() |
| 4454 | |
| 4455 | self.assertEqual( |
Paul Belanger | 7dc76e8 | 2016-11-11 16:51:08 -0500 | [diff] [blame] | 4456 | 2, tenant.layout.pipelines['check']._consecutive_failures) |
| 4457 | self.assertFalse(tenant.layout.pipelines['check']._disabled) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4458 | |
| 4459 | # J and K went back to gerrit |
| 4460 | self.assertEqual(1, len(J.messages)) |
| 4461 | self.assertIn('Build failed.', J.messages[0]) |
| 4462 | self.assertEqual(1, len(K.messages)) |
| 4463 | self.assertIn('Build failed.', K.messages[0]) |
| 4464 | # No more messages reported via smtp |
| 4465 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4466 | |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4467 | @simple_layout('layouts/one-job-project.yaml') |
| 4468 | def test_one_job_project(self): |
| 4469 | "Test that queueing works with one job" |
| 4470 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4471 | 'master', 'A') |
| 4472 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 4473 | 'master', 'B') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4474 | A.addApproval('Code-Review', 2) |
| 4475 | B.addApproval('Code-Review', 2) |
| 4476 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4477 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
James E. Blair | cc02053 | 2017-04-19 13:04:44 -0700 | [diff] [blame] | 4478 | self.waitUntilSettled() |
| 4479 | |
| 4480 | self.assertEqual(A.data['status'], 'MERGED') |
| 4481 | self.assertEqual(A.reported, 2) |
| 4482 | self.assertEqual(B.data['status'], 'MERGED') |
| 4483 | self.assertEqual(B.reported, 2) |
| 4484 | |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4485 | def test_rerun_on_abort(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4486 | "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] | 4487 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4488 | self.executor_server.hold_jobs_in_build = True |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4489 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4490 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4491 | self.waitUntilSettled() |
| 4492 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4493 | self.executor_server.release('.*-merge') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4494 | self.waitUntilSettled() |
| 4495 | |
| 4496 | self.assertEqual(len(self.builds), 2) |
| 4497 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4498 | self.executor_server.release('.*-test*') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4499 | self.waitUntilSettled() |
| 4500 | |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4501 | for x in range(3): |
Clint Byrum | df0a55b | 2016-12-05 06:39:11 -0800 | [diff] [blame] | 4502 | self.assertEqual(len(self.builds), 1, |
| 4503 | 'len of builds at x=%d is wrong' % x) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4504 | self.builds[0].requeue = True |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4505 | self.executor_server.release('.*-test1') |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4506 | self.waitUntilSettled() |
| 4507 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4508 | self.executor_server.hold_jobs_in_build = False |
| 4509 | self.executor_server.release() |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4510 | self.waitUntilSettled() |
Clint Byrum | 5bb5feb | 2016-12-08 12:39:05 -0800 | [diff] [blame] | 4511 | self.assertEqual(len(self.history), 6) |
Paul Belanger | 71d9817 | 2016-11-08 10:56:31 -0500 | [diff] [blame] | 4512 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2) |
| 4513 | self.assertEqual(A.reported, 1) |
| 4514 | self.assertIn('RETRY_LIMIT', A.messages[0]) |
Joshua Hesketh | 3f7def3 | 2016-11-21 17:36:44 +1100 | [diff] [blame] | 4515 | |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4516 | def test_zookeeper_disconnect(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4517 | "Test that jobs are executed after a zookeeper disconnect" |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4518 | |
| 4519 | self.fake_nodepool.paused = True |
| 4520 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4521 | A.addApproval('Code-Review', 2) |
| 4522 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 15be0e1 | 2017-01-03 13:45:20 -0800 | [diff] [blame] | 4523 | self.waitUntilSettled() |
| 4524 | |
| 4525 | self.zk.client.stop() |
| 4526 | self.zk.client.start() |
| 4527 | self.fake_nodepool.paused = False |
| 4528 | self.waitUntilSettled() |
| 4529 | |
| 4530 | self.assertEqual(A.data['status'], 'MERGED') |
| 4531 | self.assertEqual(A.reported, 2) |
| 4532 | |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4533 | def test_nodepool_failure(self): |
| 4534 | "Test that jobs are reported after a nodepool failure" |
| 4535 | |
| 4536 | self.fake_nodepool.paused = True |
| 4537 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4538 | A.addApproval('Code-Review', 2) |
| 4539 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | 6ab79e0 | 2017-01-06 10:10:17 -0800 | [diff] [blame] | 4540 | self.waitUntilSettled() |
| 4541 | |
| 4542 | req = self.fake_nodepool.getNodeRequests()[0] |
| 4543 | self.fake_nodepool.addFailRequest(req) |
| 4544 | |
| 4545 | self.fake_nodepool.paused = False |
| 4546 | self.waitUntilSettled() |
| 4547 | |
| 4548 | self.assertEqual(A.data['status'], 'NEW') |
| 4549 | self.assertEqual(A.reported, 2) |
| 4550 | self.assertIn('project-merge : NODE_FAILURE', A.messages[1]) |
| 4551 | self.assertIn('project-test1 : SKIPPED', A.messages[1]) |
| 4552 | self.assertIn('project-test2 : SKIPPED', A.messages[1]) |
| 4553 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4554 | |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4555 | class TestExecutor(ZuulTestCase): |
| 4556 | tenant_config_file = 'config/single-tenant/main.yaml' |
| 4557 | |
| 4558 | def assertFinalState(self): |
| 4559 | # In this test, we expect to shut down in a non-final state, |
| 4560 | # so skip these checks. |
| 4561 | pass |
| 4562 | |
| 4563 | def assertCleanShutdown(self): |
| 4564 | self.log.debug("Assert clean shutdown") |
| 4565 | |
| 4566 | # After shutdown, make sure no jobs are running |
| 4567 | self.assertEqual({}, self.executor_server.job_workers) |
| 4568 | |
| 4569 | # Make sure that git.Repo objects have been garbage collected. |
| 4570 | repos = [] |
| 4571 | gc.collect() |
| 4572 | for obj in gc.get_objects(): |
| 4573 | if isinstance(obj, git.Repo): |
| 4574 | self.log.debug("Leaked git repo object: %s" % repr(obj)) |
| 4575 | repos.append(obj) |
| 4576 | self.assertEqual(len(repos), 0) |
| 4577 | |
| 4578 | def test_executor_shutdown(self): |
| 4579 | "Test that the executor can shut down with jobs running" |
| 4580 | |
| 4581 | self.executor_server.hold_jobs_in_build = True |
| 4582 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4583 | A.addApproval('Code-Review', 2) |
| 4584 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
James E. Blair | a002b03 | 2017-04-18 10:35:48 -0700 | [diff] [blame] | 4585 | self.waitUntilSettled() |
| 4586 | |
| 4587 | |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4588 | class TestDependencyGraph(ZuulTestCase): |
| 4589 | tenant_config_file = 'config/dependency-graph/main.yaml' |
| 4590 | |
| 4591 | def test_dependeny_graph_dispatch_jobs_once(self): |
| 4592 | "Test a job in a dependency graph is queued only once" |
| 4593 | # Job dependencies, starting with A |
| 4594 | # A |
| 4595 | # / \ |
| 4596 | # B C |
| 4597 | # / \ / \ |
| 4598 | # D F E |
| 4599 | # | |
| 4600 | # G |
| 4601 | |
| 4602 | self.executor_server.hold_jobs_in_build = True |
| 4603 | change = self.fake_gerrit.addFakeChange( |
| 4604 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4605 | change.addApproval('Code-Review', 2) |
| 4606 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4607 | |
| 4608 | self.waitUntilSettled() |
| 4609 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4610 | |
| 4611 | self.executor_server.release('A') |
| 4612 | self.waitUntilSettled() |
| 4613 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4614 | |
| 4615 | self.executor_server.release('B') |
| 4616 | self.waitUntilSettled() |
| 4617 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4618 | |
| 4619 | self.executor_server.release('D') |
| 4620 | self.waitUntilSettled() |
| 4621 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4622 | |
| 4623 | self.executor_server.release('C') |
| 4624 | self.waitUntilSettled() |
| 4625 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'F']) |
| 4626 | |
| 4627 | self.executor_server.release('F') |
| 4628 | self.waitUntilSettled() |
| 4629 | self.assertEqual(sorted(b.name for b in self.builds), ['E', 'G']) |
| 4630 | |
| 4631 | self.executor_server.release('G') |
| 4632 | self.waitUntilSettled() |
| 4633 | self.assertEqual([b.name for b in self.builds], ['E']) |
| 4634 | |
| 4635 | self.executor_server.release('E') |
| 4636 | self.waitUntilSettled() |
| 4637 | self.assertEqual(len(self.builds), 0) |
| 4638 | |
| 4639 | self.executor_server.hold_jobs_in_build = False |
| 4640 | self.executor_server.release() |
| 4641 | self.waitUntilSettled() |
| 4642 | |
| 4643 | self.assertEqual(len(self.builds), 0) |
| 4644 | self.assertEqual(len(self.history), 7) |
| 4645 | |
| 4646 | self.assertEqual(change.data['status'], 'MERGED') |
| 4647 | self.assertEqual(change.reported, 2) |
| 4648 | |
| 4649 | def test_jobs_launched_only_if_all_dependencies_are_successful(self): |
| 4650 | "Test that a job waits till all dependencies are successful" |
| 4651 | # Job dependencies, starting with A |
| 4652 | # A |
| 4653 | # / \ |
| 4654 | # B C* |
| 4655 | # / \ / \ |
| 4656 | # D F E |
| 4657 | # | |
| 4658 | # G |
| 4659 | |
| 4660 | self.executor_server.hold_jobs_in_build = True |
| 4661 | change = self.fake_gerrit.addFakeChange( |
| 4662 | 'org/project', 'master', 'change') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4663 | change.addApproval('Code-Review', 2) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4664 | |
| 4665 | self.executor_server.failJob('C', change) |
| 4666 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4667 | self.fake_gerrit.addEvent(change.addApproval('Approved', 1)) |
Fredrik Medley | f8aec83 | 2015-09-28 13:40:20 +0200 | [diff] [blame] | 4668 | |
| 4669 | self.waitUntilSettled() |
| 4670 | self.assertEqual([b.name for b in self.builds], ['A']) |
| 4671 | |
| 4672 | self.executor_server.release('A') |
| 4673 | self.waitUntilSettled() |
| 4674 | self.assertEqual(sorted(b.name for b in self.builds), ['B', 'C']) |
| 4675 | |
| 4676 | self.executor_server.release('B') |
| 4677 | self.waitUntilSettled() |
| 4678 | self.assertEqual(sorted(b.name for b in self.builds), ['C', 'D']) |
| 4679 | |
| 4680 | self.executor_server.release('D') |
| 4681 | self.waitUntilSettled() |
| 4682 | self.assertEqual([b.name for b in self.builds], ['C']) |
| 4683 | |
| 4684 | self.executor_server.release('C') |
| 4685 | self.waitUntilSettled() |
| 4686 | self.assertEqual(len(self.builds), 0) |
| 4687 | |
| 4688 | self.executor_server.hold_jobs_in_build = False |
| 4689 | self.executor_server.release() |
| 4690 | self.waitUntilSettled() |
| 4691 | |
| 4692 | self.assertEqual(len(self.builds), 0) |
| 4693 | self.assertEqual(len(self.history), 4) |
| 4694 | |
| 4695 | self.assertEqual(change.data['status'], 'NEW') |
| 4696 | self.assertEqual(change.reported, 2) |
| 4697 | |
| 4698 | |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4699 | class TestDuplicatePipeline(ZuulTestCase): |
| 4700 | tenant_config_file = 'config/duplicate-pipeline/main.yaml' |
| 4701 | |
| 4702 | def test_duplicate_pipelines(self): |
| 4703 | "Test that a change matching multiple pipelines works" |
| 4704 | |
| 4705 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4706 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 4707 | self.waitUntilSettled() |
| 4708 | |
| 4709 | self.assertHistory([ |
| 4710 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4711 | pipeline='dup1'), |
| 4712 | dict(name='project-test1', result='SUCCESS', changes='1,1', |
| 4713 | pipeline='dup2'), |
Paul Belanger | 73a7d8e | 2016-11-09 11:12:42 -0500 | [diff] [blame] | 4714 | ], ordered=False) |
Arie | b6f068c | 2016-10-09 13:11:06 +0300 | [diff] [blame] | 4715 | |
| 4716 | self.assertEqual(len(A.messages), 2) |
| 4717 | |
Paul Belanger | a46a374 | 2016-11-09 14:23:03 -0500 | [diff] [blame] | 4718 | if 'dup1' in A.messages[0]: |
| 4719 | self.assertIn('dup1', A.messages[0]) |
| 4720 | self.assertNotIn('dup2', A.messages[0]) |
| 4721 | self.assertIn('project-test1', A.messages[0]) |
| 4722 | self.assertIn('dup2', A.messages[1]) |
| 4723 | self.assertNotIn('dup1', A.messages[1]) |
| 4724 | self.assertIn('project-test1', A.messages[1]) |
| 4725 | else: |
| 4726 | self.assertIn('dup1', A.messages[1]) |
| 4727 | self.assertNotIn('dup2', A.messages[1]) |
| 4728 | self.assertIn('project-test1', A.messages[1]) |
| 4729 | self.assertIn('dup2', A.messages[0]) |
| 4730 | self.assertNotIn('dup1', A.messages[0]) |
| 4731 | self.assertIn('project-test1', A.messages[0]) |
Paul Belanger | fac69ba | 2016-11-03 09:03:13 -0400 | [diff] [blame] | 4732 | |
| 4733 | |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4734 | class TestSchedulerTemplatedProject(ZuulTestCase): |
| 4735 | tenant_config_file = 'config/templated-project/main.yaml' |
| 4736 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4737 | def test_job_from_templates_executed(self): |
| 4738 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 86085b3 | 2016-11-03 12:48:57 -0400 | [diff] [blame] | 4739 | |
| 4740 | A = self.fake_gerrit.addFakeChange( |
| 4741 | 'org/templated-project', 'master', 'A') |
| 4742 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4743 | self.waitUntilSettled() |
| 4744 | |
| 4745 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4746 | 'SUCCESS') |
| 4747 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4748 | 'SUCCESS') |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4749 | |
| 4750 | def test_layered_templates(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4751 | "Test whether a job generated via a template can be executed" |
Paul Belanger | 3adf72f | 2016-11-03 14:57:31 -0400 | [diff] [blame] | 4752 | |
| 4753 | A = self.fake_gerrit.addFakeChange( |
| 4754 | 'org/layered-project', 'master', 'A') |
| 4755 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4756 | self.waitUntilSettled() |
| 4757 | |
| 4758 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 4759 | 'SUCCESS') |
| 4760 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 4761 | 'SUCCESS') |
| 4762 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 4763 | ).result, 'SUCCESS') |
| 4764 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 4765 | ).result, 'SUCCESS') |
| 4766 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 4767 | ).result, 'SUCCESS') |
| 4768 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 4769 | 'SUCCESS') |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4770 | |
| 4771 | |
| 4772 | class TestSchedulerSuccessURL(ZuulTestCase): |
| 4773 | tenant_config_file = 'config/success-url/main.yaml' |
| 4774 | |
| 4775 | def test_success_url(self): |
| 4776 | "Ensure bad build params are ignored" |
| 4777 | self.sched.reconfigure(self.config) |
| 4778 | self.init_repo('org/docs') |
| 4779 | |
| 4780 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4781 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4782 | self.waitUntilSettled() |
| 4783 | |
| 4784 | # Both builds ran: docs-draft-test + docs-draft-test2 |
| 4785 | self.assertEqual(len(self.history), 2) |
| 4786 | |
| 4787 | # Grab build id |
James E. Blair | e757680 | 2016-12-21 16:15:00 -0800 | [diff] [blame] | 4788 | for build in self.history: |
| 4789 | if build.name == 'docs-draft-test': |
| 4790 | uuid = build.uuid[:7] |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4791 | elif build.name == 'docs-draft-test2': |
| 4792 | uuid_test2 = build.uuid |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4793 | |
| 4794 | # Two msgs: 'Starting...' + results |
| 4795 | self.assertEqual(len(self.smtp_messages), 2) |
| 4796 | body = self.smtp_messages[1]['body'].splitlines() |
| 4797 | self.assertEqual('Build succeeded.', body[0]) |
| 4798 | |
| 4799 | self.assertIn( |
| 4800 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4801 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4802 | body[2]) |
| 4803 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4804 | # NOTE: This default URL is currently hard-coded in executor/server.py |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4805 | self.assertIn( |
Monty Taylor | 51139a0 | 2016-05-24 11:28:10 -0500 | [diff] [blame] | 4806 | '- docs-draft-test2 finger://{hostname}/{uuid}'.format( |
| 4807 | hostname=self.executor_server.hostname, |
Monty Taylor | de8242c | 2017-02-23 20:29:53 -0600 | [diff] [blame] | 4808 | uuid=uuid_test2), |
Adam Gandelman | 94a6006 | 2016-11-21 16:43:14 -0800 | [diff] [blame] | 4809 | body[3]) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4810 | |
| 4811 | |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4812 | class TestSchedulerMerges(ZuulTestCase): |
| 4813 | tenant_config_file = 'config/merges/main.yaml' |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4814 | |
| 4815 | def _test_project_merge_mode(self, mode): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4816 | self.executor_server.keep_jobdir = False |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4817 | project = 'org/project-%s' % mode |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4818 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4819 | A = self.fake_gerrit.addFakeChange(project, 'master', 'A') |
| 4820 | B = self.fake_gerrit.addFakeChange(project, 'master', 'B') |
| 4821 | C = self.fake_gerrit.addFakeChange(project, 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4822 | A.addApproval('Code-Review', 2) |
| 4823 | B.addApproval('Code-Review', 2) |
| 4824 | C.addApproval('Code-Review', 2) |
| 4825 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4826 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4827 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4828 | self.waitUntilSettled() |
| 4829 | |
| 4830 | build = self.builds[-1] |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4831 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4832 | project) |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4833 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4834 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4835 | repo_messages.reverse() |
| 4836 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4837 | self.executor_server.hold_jobs_in_build = False |
| 4838 | self.executor_server.release() |
Adam Gandelman | 8bd5710 | 2016-12-02 12:58:42 -0800 | [diff] [blame] | 4839 | self.waitUntilSettled() |
| 4840 | |
| 4841 | return repo_messages |
| 4842 | |
| 4843 | def _test_merge(self, mode): |
| 4844 | us_path = os.path.join( |
| 4845 | self.upstream_root, 'org/project-%s' % mode) |
| 4846 | expected_messages = [ |
| 4847 | 'initial commit', |
| 4848 | 'add content from fixture', |
| 4849 | # the intermediate commits order is nondeterministic |
| 4850 | "Merge commit 'refs/changes/1/2/1' of %s into HEAD" % us_path, |
| 4851 | "Merge commit 'refs/changes/1/3/1' of %s into HEAD" % us_path, |
| 4852 | ] |
| 4853 | result = self._test_project_merge_mode(mode) |
| 4854 | self.assertEqual(result[:2], expected_messages[:2]) |
| 4855 | self.assertEqual(result[-2:], expected_messages[-2:]) |
| 4856 | |
| 4857 | def test_project_merge_mode_merge(self): |
| 4858 | self._test_merge('merge') |
| 4859 | |
| 4860 | def test_project_merge_mode_merge_resolve(self): |
| 4861 | self._test_merge('merge-resolve') |
| 4862 | |
| 4863 | def test_project_merge_mode_cherrypick(self): |
| 4864 | expected_messages = [ |
| 4865 | 'initial commit', |
| 4866 | 'add content from fixture', |
| 4867 | 'A-1', |
| 4868 | 'B-1', |
| 4869 | 'C-1'] |
| 4870 | result = self._test_project_merge_mode('cherry-pick') |
| 4871 | self.assertEqual(result, expected_messages) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4872 | |
| 4873 | def test_merge_branch(self): |
| 4874 | "Test that the right commits are on alternate branches" |
| 4875 | self.create_branch('org/project-merge-branches', 'mp') |
| 4876 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4877 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4878 | A = self.fake_gerrit.addFakeChange( |
| 4879 | 'org/project-merge-branches', 'mp', 'A') |
| 4880 | B = self.fake_gerrit.addFakeChange( |
| 4881 | 'org/project-merge-branches', 'mp', 'B') |
| 4882 | C = self.fake_gerrit.addFakeChange( |
| 4883 | 'org/project-merge-branches', 'mp', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4884 | A.addApproval('Code-Review', 2) |
| 4885 | B.addApproval('Code-Review', 2) |
| 4886 | C.addApproval('Code-Review', 2) |
| 4887 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4888 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4889 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4890 | self.waitUntilSettled() |
| 4891 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4892 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4893 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4894 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4895 | self.waitUntilSettled() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4896 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4897 | self.waitUntilSettled() |
| 4898 | |
| 4899 | build = self.builds[-1] |
James E. Blair | 3b22249 | 2017-07-21 15:17:37 -0700 | [diff] [blame] | 4900 | self.assertEqual(build.parameters['zuul']['branch'], 'mp') |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4901 | path = os.path.join(build.jobdir.src_root, 'review.example.com', |
| 4902 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4903 | repo = git.Repo(path) |
| 4904 | |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4905 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4906 | repo_messages.reverse() |
| 4907 | correct_messages = [ |
| 4908 | 'initial commit', |
| 4909 | 'add content from fixture', |
| 4910 | 'mp commit', |
| 4911 | 'A-1', 'B-1', 'C-1'] |
| 4912 | self.assertEqual(repo_messages, correct_messages) |
| 4913 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4914 | self.executor_server.hold_jobs_in_build = False |
| 4915 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4916 | self.waitUntilSettled() |
| 4917 | |
| 4918 | def test_merge_multi_branch(self): |
| 4919 | "Test that dependent changes on multiple branches are merged" |
| 4920 | self.create_branch('org/project-merge-branches', 'mp') |
| 4921 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4922 | self.executor_server.hold_jobs_in_build = True |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4923 | A = self.fake_gerrit.addFakeChange( |
| 4924 | 'org/project-merge-branches', 'master', 'A') |
| 4925 | B = self.fake_gerrit.addFakeChange( |
| 4926 | 'org/project-merge-branches', 'mp', 'B') |
| 4927 | C = self.fake_gerrit.addFakeChange( |
| 4928 | 'org/project-merge-branches', 'master', 'C') |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 4929 | A.addApproval('Code-Review', 2) |
| 4930 | B.addApproval('Code-Review', 2) |
| 4931 | C.addApproval('Code-Review', 2) |
| 4932 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 4933 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 4934 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4935 | self.waitUntilSettled() |
| 4936 | |
| 4937 | job_A = None |
| 4938 | for job in self.builds: |
| 4939 | if 'project-merge' in job.name: |
| 4940 | job_A = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4941 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4942 | path = os.path.join(job_A.jobdir.src_root, 'review.example.com', |
| 4943 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4944 | repo = git.Repo(path) |
| 4945 | repo_messages = [c.message.strip() |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4946 | for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4947 | repo_messages.reverse() |
| 4948 | correct_messages = [ |
| 4949 | 'initial commit', 'add content from fixture', 'A-1'] |
| 4950 | self.assertEqual(repo_messages, correct_messages) |
| 4951 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4952 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4953 | self.waitUntilSettled() |
| 4954 | |
| 4955 | job_B = None |
| 4956 | for job in self.builds: |
| 4957 | if 'project-merge' in job.name: |
| 4958 | job_B = job |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4959 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4960 | path = os.path.join(job_B.jobdir.src_root, 'review.example.com', |
| 4961 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4962 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4963 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4964 | repo_messages.reverse() |
| 4965 | correct_messages = [ |
| 4966 | 'initial commit', 'add content from fixture', 'mp commit', 'B-1'] |
| 4967 | self.assertEqual(repo_messages, correct_messages) |
| 4968 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4969 | self.executor_server.release('.*-merge') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4970 | self.waitUntilSettled() |
| 4971 | |
| 4972 | job_C = None |
| 4973 | for job in self.builds: |
| 4974 | if 'project-merge' in job.name: |
| 4975 | job_C = job |
James E. Blair | b134583 | 2017-07-21 14:51:35 -0700 | [diff] [blame] | 4976 | |
James E. Blair | 2a53567 | 2017-04-27 12:03:15 -0700 | [diff] [blame] | 4977 | path = os.path.join(job_C.jobdir.src_root, 'review.example.com', |
| 4978 | 'org/project-merge-branches') |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4979 | repo = git.Repo(path) |
James E. Blair | 247cab7 | 2017-07-20 16:52:36 -0700 | [diff] [blame] | 4980 | repo_messages = [c.message.strip() for c in repo.iter_commits()] |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4981 | |
| 4982 | repo_messages.reverse() |
| 4983 | correct_messages = [ |
| 4984 | 'initial commit', 'add content from fixture', |
| 4985 | 'A-1', 'C-1'] |
| 4986 | # Ensure the right commits are in the history for this ref |
| 4987 | self.assertEqual(repo_messages, correct_messages) |
| 4988 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 4989 | self.executor_server.hold_jobs_in_build = False |
| 4990 | self.executor_server.release() |
Adam Gandelman | 4da00f6 | 2016-12-09 15:47:33 -0800 | [diff] [blame] | 4991 | self.waitUntilSettled() |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 4992 | |
| 4993 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 4994 | class TestSemaphore(ZuulTestCase): |
| 4995 | tenant_config_file = 'config/semaphore/main.yaml' |
| 4996 | |
| 4997 | def test_semaphore_one(self): |
| 4998 | "Test semaphores with max=1 (mutex)" |
| 4999 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5000 | |
| 5001 | self.executor_server.hold_jobs_in_build = True |
| 5002 | |
| 5003 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5004 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5005 | self.assertFalse('test-semaphore' in |
| 5006 | tenant.semaphore_handler.semaphores) |
| 5007 | |
| 5008 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5009 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5010 | self.waitUntilSettled() |
| 5011 | |
| 5012 | self.assertEqual(len(self.builds), 3) |
| 5013 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5014 | self.assertEqual(self.builds[1].name, 'semaphore-one-test1') |
| 5015 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5016 | |
| 5017 | self.executor_server.release('semaphore-one-test1') |
| 5018 | self.waitUntilSettled() |
| 5019 | |
| 5020 | self.assertEqual(len(self.builds), 3) |
| 5021 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5022 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5023 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5024 | self.assertTrue('test-semaphore' in |
| 5025 | tenant.semaphore_handler.semaphores) |
| 5026 | |
| 5027 | self.executor_server.release('semaphore-one-test2') |
| 5028 | self.waitUntilSettled() |
| 5029 | |
| 5030 | self.assertEqual(len(self.builds), 3) |
| 5031 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5032 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5033 | self.assertEqual(self.builds[2].name, 'semaphore-one-test1') |
| 5034 | self.assertTrue('test-semaphore' in |
| 5035 | tenant.semaphore_handler.semaphores) |
| 5036 | |
| 5037 | self.executor_server.release('semaphore-one-test1') |
| 5038 | self.waitUntilSettled() |
| 5039 | |
| 5040 | self.assertEqual(len(self.builds), 3) |
| 5041 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5042 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5043 | self.assertEqual(self.builds[2].name, 'semaphore-one-test2') |
| 5044 | self.assertTrue('test-semaphore' in |
| 5045 | tenant.semaphore_handler.semaphores) |
| 5046 | |
| 5047 | self.executor_server.release('semaphore-one-test2') |
| 5048 | self.waitUntilSettled() |
| 5049 | |
| 5050 | self.assertEqual(len(self.builds), 2) |
| 5051 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5052 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5053 | self.assertFalse('test-semaphore' in |
| 5054 | tenant.semaphore_handler.semaphores) |
| 5055 | |
| 5056 | self.executor_server.hold_jobs_in_build = False |
| 5057 | self.executor_server.release() |
| 5058 | |
| 5059 | self.waitUntilSettled() |
| 5060 | self.assertEqual(len(self.builds), 0) |
| 5061 | |
| 5062 | self.assertEqual(A.reported, 1) |
| 5063 | self.assertEqual(B.reported, 1) |
| 5064 | self.assertFalse('test-semaphore' in |
| 5065 | tenant.semaphore_handler.semaphores) |
| 5066 | |
| 5067 | def test_semaphore_two(self): |
| 5068 | "Test semaphores with max>1" |
| 5069 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5070 | |
| 5071 | self.executor_server.hold_jobs_in_build = True |
| 5072 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5073 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5074 | self.assertFalse('test-semaphore-two' in |
| 5075 | tenant.semaphore_handler.semaphores) |
| 5076 | |
| 5077 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5078 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5079 | self.waitUntilSettled() |
| 5080 | |
| 5081 | self.assertEqual(len(self.builds), 4) |
| 5082 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5083 | self.assertEqual(self.builds[1].name, 'semaphore-two-test1') |
| 5084 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5085 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 5086 | self.assertTrue('test-semaphore-two' in |
| 5087 | tenant.semaphore_handler.semaphores) |
| 5088 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5089 | 'test-semaphore-two', [])), 2) |
| 5090 | |
| 5091 | self.executor_server.release('semaphore-two-test1') |
| 5092 | self.waitUntilSettled() |
| 5093 | |
| 5094 | self.assertEqual(len(self.builds), 4) |
| 5095 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5096 | self.assertEqual(self.builds[1].name, 'semaphore-two-test2') |
| 5097 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 5098 | self.assertEqual(self.builds[3].name, 'semaphore-two-test1') |
| 5099 | self.assertTrue('test-semaphore-two' in |
| 5100 | tenant.semaphore_handler.semaphores) |
| 5101 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5102 | 'test-semaphore-two', [])), 2) |
| 5103 | |
| 5104 | self.executor_server.release('semaphore-two-test2') |
| 5105 | self.waitUntilSettled() |
| 5106 | |
| 5107 | self.assertEqual(len(self.builds), 4) |
| 5108 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5109 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5110 | self.assertEqual(self.builds[2].name, 'semaphore-two-test1') |
| 5111 | self.assertEqual(self.builds[3].name, 'semaphore-two-test2') |
| 5112 | self.assertTrue('test-semaphore-two' in |
| 5113 | tenant.semaphore_handler.semaphores) |
| 5114 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5115 | 'test-semaphore-two', [])), 2) |
| 5116 | |
| 5117 | self.executor_server.release('semaphore-two-test1') |
| 5118 | self.waitUntilSettled() |
| 5119 | |
| 5120 | self.assertEqual(len(self.builds), 3) |
| 5121 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5122 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5123 | self.assertEqual(self.builds[2].name, 'semaphore-two-test2') |
| 5124 | self.assertTrue('test-semaphore-two' in |
| 5125 | tenant.semaphore_handler.semaphores) |
| 5126 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5127 | 'test-semaphore-two', [])), 1) |
| 5128 | |
| 5129 | self.executor_server.release('semaphore-two-test2') |
| 5130 | self.waitUntilSettled() |
| 5131 | |
| 5132 | self.assertEqual(len(self.builds), 2) |
| 5133 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 5134 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 5135 | self.assertFalse('test-semaphore-two' in |
| 5136 | tenant.semaphore_handler.semaphores) |
| 5137 | |
| 5138 | self.executor_server.hold_jobs_in_build = False |
| 5139 | self.executor_server.release() |
| 5140 | |
| 5141 | self.waitUntilSettled() |
| 5142 | self.assertEqual(len(self.builds), 0) |
| 5143 | |
| 5144 | self.assertEqual(A.reported, 1) |
| 5145 | self.assertEqual(B.reported, 1) |
| 5146 | |
| 5147 | def test_semaphore_abandon(self): |
| 5148 | "Test abandon with job semaphores" |
| 5149 | self.executor_server.hold_jobs_in_build = True |
| 5150 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5151 | check_pipeline = tenant.layout.pipelines['check'] |
| 5152 | |
| 5153 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5154 | self.assertFalse('test-semaphore' in |
| 5155 | tenant.semaphore_handler.semaphores) |
| 5156 | |
| 5157 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5158 | self.waitUntilSettled() |
| 5159 | |
| 5160 | self.assertTrue('test-semaphore' in |
| 5161 | tenant.semaphore_handler.semaphores) |
| 5162 | |
| 5163 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 5164 | self.waitUntilSettled() |
| 5165 | |
| 5166 | # The check pipeline should be empty |
| 5167 | items = check_pipeline.getAllItems() |
| 5168 | self.assertEqual(len(items), 0) |
| 5169 | |
| 5170 | # The semaphore should be released |
| 5171 | self.assertFalse('test-semaphore' in |
| 5172 | tenant.semaphore_handler.semaphores) |
| 5173 | |
| 5174 | self.executor_server.hold_jobs_in_build = False |
| 5175 | self.executor_server.release() |
| 5176 | self.waitUntilSettled() |
| 5177 | |
Tobias Henkel | 0f71400 | 2017-06-30 23:30:52 +0200 | [diff] [blame] | 5178 | def test_semaphore_new_patchset(self): |
| 5179 | "Test new patchset with job semaphores" |
| 5180 | self.executor_server.hold_jobs_in_build = True |
| 5181 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5182 | check_pipeline = tenant.layout.pipelines['check'] |
| 5183 | |
| 5184 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5185 | self.assertFalse('test-semaphore' in |
| 5186 | tenant.semaphore_handler.semaphores) |
| 5187 | |
| 5188 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5189 | self.waitUntilSettled() |
| 5190 | |
| 5191 | self.assertTrue('test-semaphore' in |
| 5192 | tenant.semaphore_handler.semaphores) |
| 5193 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5194 | self.assertEqual(len(semaphore), 1) |
| 5195 | |
| 5196 | A.addPatchset() |
| 5197 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 5198 | self.waitUntilSettled() |
| 5199 | |
| 5200 | self.assertTrue('test-semaphore' in |
| 5201 | tenant.semaphore_handler.semaphores) |
| 5202 | semaphore = tenant.semaphore_handler.semaphores['test-semaphore'] |
| 5203 | self.assertEqual(len(semaphore), 1) |
| 5204 | |
| 5205 | items = check_pipeline.getAllItems() |
| 5206 | self.assertEqual(items[0].change.number, '1') |
| 5207 | self.assertEqual(items[0].change.patchset, '2') |
| 5208 | self.assertTrue(items[0].live) |
| 5209 | |
| 5210 | self.executor_server.hold_jobs_in_build = False |
| 5211 | self.executor_server.release() |
| 5212 | self.waitUntilSettled() |
| 5213 | |
| 5214 | # The semaphore should be released |
| 5215 | self.assertFalse('test-semaphore' in |
| 5216 | tenant.semaphore_handler.semaphores) |
| 5217 | |
James E. Blair | 9ea0d0b | 2017-04-20 09:27:15 -0700 | [diff] [blame] | 5218 | def test_semaphore_reconfigure(self): |
| 5219 | "Test reconfigure with job semaphores" |
| 5220 | self.executor_server.hold_jobs_in_build = True |
| 5221 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5222 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 5223 | self.assertFalse('test-semaphore' in |
| 5224 | tenant.semaphore_handler.semaphores) |
| 5225 | |
| 5226 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5227 | self.waitUntilSettled() |
| 5228 | |
| 5229 | self.assertTrue('test-semaphore' in |
| 5230 | tenant.semaphore_handler.semaphores) |
| 5231 | |
| 5232 | # reconfigure without layout change |
| 5233 | self.sched.reconfigure(self.config) |
| 5234 | self.waitUntilSettled() |
| 5235 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5236 | |
| 5237 | # semaphore still must be held |
| 5238 | self.assertTrue('test-semaphore' in |
| 5239 | tenant.semaphore_handler.semaphores) |
| 5240 | |
| 5241 | self.commitConfigUpdate( |
| 5242 | 'common-config', |
| 5243 | 'config/semaphore/zuul-reconfiguration.yaml') |
| 5244 | self.sched.reconfigure(self.config) |
| 5245 | self.waitUntilSettled() |
| 5246 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5247 | |
| 5248 | self.executor_server.release('project-test1') |
| 5249 | self.waitUntilSettled() |
| 5250 | |
| 5251 | # There should be no builds anymore |
| 5252 | self.assertEqual(len(self.builds), 0) |
| 5253 | |
| 5254 | # The semaphore should be released |
| 5255 | self.assertFalse('test-semaphore' in |
| 5256 | tenant.semaphore_handler.semaphores) |
| 5257 | |
| 5258 | |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5259 | class TestSemaphoreMultiTenant(ZuulTestCase): |
| 5260 | tenant_config_file = 'config/multi-tenant-semaphore/main.yaml' |
| 5261 | |
| 5262 | def test_semaphore_tenant_isolation(self): |
| 5263 | "Test semaphores in multiple tenants" |
| 5264 | |
| 5265 | self.waitUntilSettled() |
| 5266 | tenant_one = self.sched.abide.tenants.get('tenant-one') |
| 5267 | tenant_two = self.sched.abide.tenants.get('tenant-two') |
| 5268 | |
| 5269 | self.executor_server.hold_jobs_in_build = True |
| 5270 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 5271 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 5272 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 5273 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 5274 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 5275 | self.assertFalse('test-semaphore' in |
| 5276 | tenant_one.semaphore_handler.semaphores) |
| 5277 | self.assertFalse('test-semaphore' in |
| 5278 | tenant_two.semaphore_handler.semaphores) |
| 5279 | |
| 5280 | # add patches to project1 of tenant-one |
| 5281 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 5282 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 5283 | self.waitUntilSettled() |
| 5284 | |
| 5285 | # one build of project1-test1 must run |
| 5286 | # semaphore of tenant-one must be acquired once |
| 5287 | # semaphore of tenant-two must not be acquired |
| 5288 | self.assertEqual(len(self.builds), 1) |
| 5289 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5290 | self.assertTrue('test-semaphore' in |
| 5291 | tenant_one.semaphore_handler.semaphores) |
| 5292 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5293 | 'test-semaphore', [])), 1) |
| 5294 | self.assertFalse('test-semaphore' in |
| 5295 | tenant_two.semaphore_handler.semaphores) |
| 5296 | |
| 5297 | # add patches to project2 of tenant-two |
| 5298 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 5299 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 5300 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 5301 | self.waitUntilSettled() |
| 5302 | |
| 5303 | # one build of project1-test1 must run |
| 5304 | # two builds of project2-test1 must run |
| 5305 | # semaphore of tenant-one must be acquired once |
| 5306 | # semaphore of tenant-two must be acquired twice |
| 5307 | self.assertEqual(len(self.builds), 3) |
| 5308 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 5309 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5310 | self.assertEqual(self.builds[2].name, 'project2-test1') |
| 5311 | self.assertTrue('test-semaphore' in |
| 5312 | tenant_one.semaphore_handler.semaphores) |
| 5313 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5314 | 'test-semaphore', [])), 1) |
| 5315 | self.assertTrue('test-semaphore' in |
| 5316 | tenant_two.semaphore_handler.semaphores) |
| 5317 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5318 | 'test-semaphore', [])), 2) |
| 5319 | |
| 5320 | self.executor_server.release('project1-test1') |
| 5321 | self.waitUntilSettled() |
| 5322 | |
| 5323 | # one build of project1-test1 must run |
| 5324 | # two builds of project2-test1 must run |
| 5325 | # semaphore of tenant-one must be acquired once |
| 5326 | # semaphore of tenant-two must be acquired twice |
| 5327 | self.assertEqual(len(self.builds), 3) |
| 5328 | self.assertEqual(self.builds[0].name, 'project2-test1') |
| 5329 | self.assertEqual(self.builds[1].name, 'project2-test1') |
| 5330 | self.assertEqual(self.builds[2].name, 'project1-test1') |
| 5331 | self.assertTrue('test-semaphore' in |
| 5332 | tenant_one.semaphore_handler.semaphores) |
| 5333 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5334 | 'test-semaphore', [])), 1) |
| 5335 | self.assertTrue('test-semaphore' in |
| 5336 | tenant_two.semaphore_handler.semaphores) |
| 5337 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5338 | 'test-semaphore', [])), 2) |
| 5339 | |
| 5340 | self.executor_server.release('project2-test1') |
| 5341 | self.waitUntilSettled() |
| 5342 | |
| 5343 | # one build of project1-test1 must run |
| 5344 | # one build of project2-test1 must run |
| 5345 | # semaphore of tenant-one must be acquired once |
| 5346 | # semaphore of tenant-two must be acquired once |
| 5347 | self.assertEqual(len(self.builds), 2) |
| 5348 | self.assertTrue('test-semaphore' in |
| 5349 | tenant_one.semaphore_handler.semaphores) |
| 5350 | self.assertEqual(len(tenant_one.semaphore_handler.semaphores.get( |
| 5351 | 'test-semaphore', [])), 1) |
| 5352 | self.assertTrue('test-semaphore' in |
| 5353 | tenant_two.semaphore_handler.semaphores) |
| 5354 | self.assertEqual(len(tenant_two.semaphore_handler.semaphores.get( |
| 5355 | 'test-semaphore', [])), 1) |
| 5356 | |
| 5357 | self.executor_server.hold_jobs_in_build = False |
| 5358 | self.executor_server.release() |
| 5359 | |
| 5360 | self.waitUntilSettled() |
| 5361 | |
| 5362 | # no build must run |
| 5363 | # semaphore of tenant-one must not be acquired |
| 5364 | # semaphore of tenant-two must not be acquired |
| 5365 | self.assertEqual(len(self.builds), 0) |
| 5366 | self.assertFalse('test-semaphore' in |
| 5367 | tenant_one.semaphore_handler.semaphores) |
| 5368 | self.assertFalse('test-semaphore' in |
| 5369 | tenant_two.semaphore_handler.semaphores) |
| 5370 | |
| 5371 | self.assertEqual(A.reported, 1) |
| 5372 | self.assertEqual(B.reported, 1) |
| 5373 | |
| 5374 | |
| 5375 | class TestSemaphoreInRepo(ZuulTestCase): |
Tobias Henkel | abf973e | 2017-07-28 10:07:34 +0200 | [diff] [blame] | 5376 | config_file = 'zuul-connections-gerrit-and-github.conf' |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5377 | tenant_config_file = 'config/in-repo/main.yaml' |
| 5378 | |
| 5379 | def test_semaphore_in_repo(self): |
| 5380 | "Test semaphores in repo config" |
| 5381 | |
| 5382 | # This tests dynamic semaphore handling in project repos. The semaphore |
| 5383 | # max value should not be evaluated dynamically but must be updated |
| 5384 | # after the change lands. |
| 5385 | |
| 5386 | self.waitUntilSettled() |
| 5387 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5388 | |
| 5389 | in_repo_conf = textwrap.dedent( |
| 5390 | """ |
| 5391 | - job: |
Tobias Henkel | f02cf51 | 2017-07-21 22:55:34 +0200 | [diff] [blame] | 5392 | name: project-test1 |
| 5393 | |
| 5394 | - job: |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5395 | name: project-test2 |
| 5396 | semaphore: test-semaphore |
| 5397 | |
| 5398 | - project: |
| 5399 | name: org/project |
| 5400 | tenant-one-gate: |
| 5401 | jobs: |
| 5402 | - project-test2 |
| 5403 | |
| 5404 | # the max value in dynamic layout must be ignored |
| 5405 | - semaphore: |
| 5406 | name: test-semaphore |
| 5407 | max: 2 |
| 5408 | """) |
| 5409 | |
| 5410 | in_repo_playbook = textwrap.dedent( |
| 5411 | """ |
| 5412 | - hosts: all |
| 5413 | tasks: [] |
| 5414 | """) |
| 5415 | |
| 5416 | file_dict = {'.zuul.yaml': in_repo_conf, |
| 5417 | 'playbooks/project-test2.yaml': in_repo_playbook} |
| 5418 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', |
| 5419 | files=file_dict) |
| 5420 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 5421 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 5422 | B.setDependsOn(A, 1) |
| 5423 | C.setDependsOn(A, 1) |
| 5424 | |
| 5425 | self.executor_server.hold_jobs_in_build = True |
| 5426 | |
Tobias Henkel | bf24fd1 | 2017-07-27 06:13:07 +0200 | [diff] [blame] | 5427 | A.addApproval('Code-Review', 2) |
| 5428 | B.addApproval('Code-Review', 2) |
| 5429 | C.addApproval('Code-Review', 2) |
| 5430 | self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) |
| 5431 | self.fake_gerrit.addEvent(B.addApproval('Approved', 1)) |
| 5432 | self.fake_gerrit.addEvent(C.addApproval('Approved', 1)) |
Tobias Henkel | 9a0e194 | 2017-03-20 16:16:02 +0100 | [diff] [blame] | 5433 | self.waitUntilSettled() |
| 5434 | |
| 5435 | # check that the layout in a queue item still has max value of 1 |
| 5436 | # for test-semaphore |
| 5437 | pipeline = tenant.layout.pipelines.get('tenant-one-gate') |
| 5438 | queue = None |
| 5439 | for queue_candidate in pipeline.queues: |
| 5440 | if queue_candidate.name == 'org/project': |
| 5441 | queue = queue_candidate |
| 5442 | break |
| 5443 | queue_item = queue.queue[0] |
| 5444 | item_dynamic_layout = queue_item.current_build_set.layout |
| 5445 | dynamic_test_semaphore = \ |
| 5446 | item_dynamic_layout.semaphores.get('test-semaphore') |
| 5447 | self.assertEqual(dynamic_test_semaphore.max, 1) |
| 5448 | |
| 5449 | # one build must be in queue, one semaphores acquired |
| 5450 | self.assertEqual(len(self.builds), 1) |
| 5451 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5452 | self.assertTrue('test-semaphore' in |
| 5453 | tenant.semaphore_handler.semaphores) |
| 5454 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5455 | 'test-semaphore', [])), 1) |
| 5456 | |
| 5457 | self.executor_server.release('project-test2') |
| 5458 | self.waitUntilSettled() |
| 5459 | |
| 5460 | # change A must be merged |
| 5461 | self.assertEqual(A.data['status'], 'MERGED') |
| 5462 | self.assertEqual(A.reported, 2) |
| 5463 | |
| 5464 | # send change-merged event as the gerrit mock doesn't send it |
| 5465 | self.fake_gerrit.addEvent(A.getChangeMergedEvent()) |
| 5466 | self.waitUntilSettled() |
| 5467 | |
| 5468 | # now that change A was merged, the new semaphore max must be effective |
| 5469 | tenant = self.sched.abide.tenants.get('tenant-one') |
| 5470 | self.assertEqual(tenant.layout.semaphores.get('test-semaphore').max, 2) |
| 5471 | |
| 5472 | # two builds must be in queue, two semaphores acquired |
| 5473 | self.assertEqual(len(self.builds), 2) |
| 5474 | self.assertEqual(self.builds[0].name, 'project-test2') |
| 5475 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 5476 | self.assertTrue('test-semaphore' in |
| 5477 | tenant.semaphore_handler.semaphores) |
| 5478 | self.assertEqual(len(tenant.semaphore_handler.semaphores.get( |
| 5479 | 'test-semaphore', [])), 2) |
| 5480 | |
| 5481 | self.executor_server.release('project-test2') |
| 5482 | self.waitUntilSettled() |
| 5483 | |
| 5484 | self.assertEqual(len(self.builds), 0) |
| 5485 | self.assertFalse('test-semaphore' in |
| 5486 | tenant.semaphore_handler.semaphores) |
| 5487 | |
| 5488 | self.executor_server.hold_jobs_in_build = False |
| 5489 | self.executor_server.release() |
| 5490 | |
| 5491 | self.waitUntilSettled() |
| 5492 | self.assertEqual(len(self.builds), 0) |
| 5493 | |
| 5494 | self.assertEqual(A.reported, 2) |
| 5495 | self.assertEqual(B.reported, 2) |
| 5496 | self.assertEqual(C.reported, 2) |