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 | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 17 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | import logging |
| 19 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 20 | import re |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 21 | import shutil |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 22 | import time |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 23 | import yaml |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 24 | from unittest import skip |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 26 | import git |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 27 | from six.moves import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 28 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 29 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 30 | import zuul.change_matcher |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 31 | import zuul.scheduler |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 32 | import zuul.rpcclient |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 33 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 34 | import zuul.reporter.smtp |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 35 | |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 36 | from tests.base import ( |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 37 | ZuulTestCase, |
| 38 | repack_repo, |
| 39 | ) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 40 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 41 | logging.basicConfig(level=logging.DEBUG, |
| 42 | format='%(asctime)s %(name)-32s ' |
| 43 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
| 45 | |
Clark Boylan | b640e05 | 2014-04-03 16:41:46 -0700 | [diff] [blame] | 46 | class TestScheduler(ZuulTestCase): |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 47 | tenant_config_file = 'config/single-tenant/main.yaml' |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 48 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 49 | def test_jobs_launched(self): |
| 50 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 51 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 52 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 53 | A.addApproval('code-review', 2) |
| 54 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 55 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 56 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 57 | 'SUCCESS') |
| 58 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 59 | 'SUCCESS') |
| 60 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 61 | 'SUCCESS') |
| 62 | self.assertEqual(A.data['status'], 'MERGED') |
| 63 | self.assertEqual(A.reported, 2) |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 64 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 65 | 'image1') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 66 | |
James E. Blair | 552b54f | 2016-07-22 13:55:32 -0700 | [diff] [blame] | 67 | # TODOv3(jeblair): we may want to report stats by tenant (also?). |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 68 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 69 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 70 | value='1|g') |
| 71 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 72 | kind='ms') |
| 73 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 74 | value='1|c') |
| 75 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 76 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 77 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 78 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 79 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 80 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 81 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 82 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 83 | for build in self.builds: |
| 84 | self.assertEqual(build.parameters['ZUUL_VOTING'], '1') |
| 85 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 86 | def test_initial_pipeline_gauges(self): |
| 87 | "Test that each pipeline reported its length on start" |
James E. Blair | 7da51b7 | 2016-07-25 15:29:43 -0700 | [diff] [blame] | 88 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 89 | value='0|g') |
| 90 | self.assertReportedStat('zuul.pipeline.check.current_changes', |
| 91 | value='0|g') |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 92 | |
James E. Blair | 34776ee | 2016-08-25 13:53:54 -0700 | [diff] [blame] | 93 | def test_job_branch(self): |
| 94 | "Test the correct variant of a job runs on a branch" |
| 95 | self.create_branch('org/project', 'stable') |
| 96 | A = self.fake_gerrit.addFakeChange('org/project', 'stable', 'A') |
| 97 | A.addApproval('code-review', 2) |
| 98 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 99 | self.waitUntilSettled() |
| 100 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 101 | 'SUCCESS') |
| 102 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 103 | 'SUCCESS') |
| 104 | self.assertEqual(A.data['status'], 'MERGED') |
| 105 | self.assertEqual(A.reported, 2, |
| 106 | "A should report start and success") |
| 107 | self.assertIn('gate', A.messages[1], |
| 108 | "A should transit gate") |
| 109 | self.assertEqual(self.getJobFromHistory('project-test1').node, |
| 110 | 'image2') |
| 111 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 112 | @skip("Disabled for early v3 development") |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 113 | def test_duplicate_pipelines(self): |
| 114 | "Test that a change matching multiple pipelines works" |
James E. Blair | 1b4d972 | 2013-05-21 10:32:04 -0700 | [diff] [blame] | 115 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 116 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 117 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 118 | self.waitUntilSettled() |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 119 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 120 | self.assertEqual(len(self.history), 2) |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 121 | self.history[0].name == 'project-test1' |
| 122 | self.history[1].name == 'project-test1' |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 123 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 124 | self.assertEqual(len(A.messages), 2) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 125 | if 'dup1/project-test1' in A.messages[0]: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 126 | self.assertIn('dup1/project-test1', A.messages[0]) |
| 127 | self.assertNotIn('dup2/project-test1', A.messages[0]) |
| 128 | self.assertNotIn('dup1/project-test1', A.messages[1]) |
| 129 | self.assertIn('dup2/project-test1', A.messages[1]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 130 | else: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 131 | self.assertIn('dup1/project-test1', A.messages[1]) |
| 132 | self.assertNotIn('dup2/project-test1', A.messages[1]) |
| 133 | self.assertNotIn('dup1/project-test1', A.messages[0]) |
| 134 | self.assertIn('dup2/project-test1', A.messages[0]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 135 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 136 | def test_parallel_changes(self): |
| 137 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 138 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 139 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 140 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 141 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 142 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 143 | A.addApproval('code-review', 2) |
| 144 | B.addApproval('code-review', 2) |
| 145 | C.addApproval('code-review', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 146 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 147 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 148 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 149 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 150 | |
| 151 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 152 | self.assertEqual(len(self.builds), 1) |
| 153 | self.assertEqual(self.builds[0].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 154 | self.assertTrue(self.builds[0].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 155 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 156 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 157 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 158 | self.assertEqual(len(self.builds), 3) |
| 159 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 160 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 161 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 162 | self.assertTrue(self.builds[1].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 163 | self.assertEqual(self.builds[2].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 164 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 165 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 166 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 167 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 168 | self.assertEqual(len(self.builds), 5) |
| 169 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 170 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 171 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 172 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 173 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 174 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 175 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 176 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 177 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 178 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 179 | self.assertEqual(self.builds[4].name, 'project-merge') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 180 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 182 | self.launch_server.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 183 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 184 | self.assertEqual(len(self.builds), 6) |
| 185 | self.assertEqual(self.builds[0].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 186 | self.assertTrue(self.builds[0].hasChanges(A)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 187 | self.assertEqual(self.builds[1].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 188 | self.assertTrue(self.builds[1].hasChanges(A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 189 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 190 | self.assertEqual(self.builds[2].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 191 | self.assertTrue(self.builds[2].hasChanges(A, B)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 192 | self.assertEqual(self.builds[3].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 193 | self.assertTrue(self.builds[3].hasChanges(A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 194 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 195 | self.assertEqual(self.builds[4].name, 'project-test1') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 196 | self.assertTrue(self.builds[4].hasChanges(A, B, C)) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 197 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 198 | self.assertTrue(self.builds[5].hasChanges(A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 199 | |
James E. Blair | 791b539 | 2016-08-03 11:25:56 -0700 | [diff] [blame] | 200 | self.launch_server.hold_jobs_in_build = False |
| 201 | self.launch_server.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 202 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 203 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 204 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 205 | self.assertEqual(len(self.history), 9) |
| 206 | self.assertEqual(A.data['status'], 'MERGED') |
| 207 | self.assertEqual(B.data['status'], 'MERGED') |
| 208 | self.assertEqual(C.data['status'], 'MERGED') |
| 209 | self.assertEqual(A.reported, 2) |
| 210 | self.assertEqual(B.reported, 2) |
| 211 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 212 | |
| 213 | def test_failed_changes(self): |
| 214 | "Test that a change behind a failed change is retested" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 215 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 216 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 217 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 218 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 219 | A.addApproval('code-review', 2) |
| 220 | B.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 221 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 222 | self.launch_server.failJob('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 223 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 224 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 225 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 226 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 227 | self.assertBuilds([dict(name='project-merge', changes='1,1')]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 228 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 229 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 230 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 231 | # A/project-merge is complete |
| 232 | self.assertBuilds([ |
| 233 | dict(name='project-test1', changes='1,1'), |
| 234 | dict(name='project-test2', changes='1,1'), |
| 235 | dict(name='project-merge', changes='1,1 2,1'), |
| 236 | ]) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 237 | |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 238 | self.launch_server.release('.*-merge') |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 239 | self.waitUntilSettled() |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 240 | # A/project-merge is complete |
| 241 | # B/project-merge is complete |
| 242 | self.assertBuilds([ |
| 243 | dict(name='project-test1', changes='1,1'), |
| 244 | dict(name='project-test2', changes='1,1'), |
| 245 | dict(name='project-test1', changes='1,1 2,1'), |
| 246 | dict(name='project-test2', changes='1,1 2,1'), |
| 247 | ]) |
| 248 | |
| 249 | # Release project-test1 for A which will fail. This will |
| 250 | # abort both running B jobs and relaunch project-merge for B. |
| 251 | self.builds[0].release() |
| 252 | self.waitUntilSettled() |
| 253 | |
| 254 | self.orderedRelease() |
| 255 | self.assertHistory([ |
| 256 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 257 | dict(name='project-merge', result='SUCCESS', changes='1,1 2,1'), |
| 258 | dict(name='project-test1', result='FAILURE', changes='1,1'), |
| 259 | dict(name='project-test1', result='ABORTED', changes='1,1 2,1'), |
| 260 | dict(name='project-test2', result='ABORTED', changes='1,1 2,1'), |
| 261 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 262 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 263 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 264 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 265 | ], ordered=False) |
James E. Blair | 2b2a8ab | 2016-08-11 14:39:11 -0700 | [diff] [blame] | 266 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 267 | self.assertEqual(A.data['status'], 'NEW') |
| 268 | self.assertEqual(B.data['status'], 'MERGED') |
| 269 | self.assertEqual(A.reported, 2) |
| 270 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 271 | |
| 272 | def test_independent_queues(self): |
| 273 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 274 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 275 | self.launch_server.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 276 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 277 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 278 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 279 | A.addApproval('code-review', 2) |
| 280 | B.addApproval('code-review', 2) |
| 281 | C.addApproval('code-review', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 282 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 283 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 284 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 285 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 286 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 287 | self.waitUntilSettled() |
| 288 | |
| 289 | # 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] | 290 | self.assertBuilds([ |
| 291 | dict(name='project-merge', changes='1,1'), |
| 292 | dict(name='project-merge', changes='2,1'), |
| 293 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 294 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 295 | # Release the current merge builds |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 296 | self.builds[0].release() |
| 297 | self.waitUntilSettled() |
| 298 | self.builds[0].release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 299 | self.waitUntilSettled() |
| 300 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 301 | self.launch_server.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 302 | self.waitUntilSettled() |
| 303 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 304 | # All the test builds should be running: |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 305 | self.assertBuilds([ |
| 306 | dict(name='project-test1', changes='1,1'), |
| 307 | dict(name='project-test2', changes='1,1'), |
| 308 | dict(name='project-test1', changes='2,1'), |
| 309 | dict(name='project-test2', changes='2,1'), |
| 310 | dict(name='project-test1', changes='2,1 3,1'), |
| 311 | dict(name='project-test2', changes='2,1 3,1'), |
| 312 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 313 | |
James E. Blair | 5f0d49e | 2016-08-19 09:36:50 -0700 | [diff] [blame] | 314 | self.orderedRelease() |
| 315 | self.assertHistory([ |
| 316 | dict(name='project-merge', result='SUCCESS', changes='1,1'), |
| 317 | dict(name='project-merge', result='SUCCESS', changes='2,1'), |
| 318 | dict(name='project-merge', result='SUCCESS', changes='2,1 3,1'), |
| 319 | dict(name='project-test1', result='SUCCESS', changes='1,1'), |
| 320 | dict(name='project-test2', result='SUCCESS', changes='1,1'), |
| 321 | dict(name='project-test1', result='SUCCESS', changes='2,1'), |
| 322 | dict(name='project-test2', result='SUCCESS', changes='2,1'), |
| 323 | dict(name='project-test1', result='SUCCESS', changes='2,1 3,1'), |
| 324 | dict(name='project-test2', result='SUCCESS', changes='2,1 3,1'), |
| 325 | ]) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 326 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 327 | self.assertEqual(A.data['status'], 'MERGED') |
| 328 | self.assertEqual(B.data['status'], 'MERGED') |
| 329 | self.assertEqual(C.data['status'], 'MERGED') |
| 330 | self.assertEqual(A.reported, 2) |
| 331 | self.assertEqual(B.reported, 2) |
| 332 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 333 | |
| 334 | def test_failed_change_at_head(self): |
| 335 | "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] | 336 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 337 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 338 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 339 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 340 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 341 | A.addApproval('code-review', 2) |
| 342 | B.addApproval('code-review', 2) |
| 343 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 344 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 345 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 346 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 347 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 348 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 349 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 350 | |
| 351 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 352 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 353 | self.assertBuilds([ |
| 354 | dict(name='project-merge', changes='1,1'), |
| 355 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 356 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 357 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 358 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 359 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 360 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 361 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 362 | self.waitUntilSettled() |
| 363 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 364 | self.assertBuilds([ |
| 365 | dict(name='project-test1', changes='1,1'), |
| 366 | dict(name='project-test2', changes='1,1'), |
| 367 | dict(name='project-test1', changes='1,1 2,1'), |
| 368 | dict(name='project-test2', changes='1,1 2,1'), |
| 369 | dict(name='project-test1', changes='1,1 2,1 3,1'), |
| 370 | dict(name='project-test2', changes='1,1 2,1 3,1'), |
| 371 | ]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 372 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 373 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 374 | self.waitUntilSettled() |
| 375 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 376 | # project-test2, project-merge for B |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 377 | self.assertBuilds([ |
| 378 | dict(name='project-test2', changes='1,1'), |
| 379 | dict(name='project-merge', changes='2,1'), |
| 380 | ]) |
| 381 | # Unordered history comparison because the aborts can finish |
| 382 | # in any order. |
| 383 | self.assertHistory([ |
| 384 | dict(name='project-merge', result='SUCCESS', |
| 385 | changes='1,1'), |
| 386 | dict(name='project-merge', result='SUCCESS', |
| 387 | changes='1,1 2,1'), |
| 388 | dict(name='project-merge', result='SUCCESS', |
| 389 | changes='1,1 2,1 3,1'), |
| 390 | dict(name='project-test1', result='FAILURE', |
| 391 | changes='1,1'), |
| 392 | dict(name='project-test1', result='ABORTED', |
| 393 | changes='1,1 2,1'), |
| 394 | dict(name='project-test2', result='ABORTED', |
| 395 | changes='1,1 2,1'), |
| 396 | dict(name='project-test1', result='ABORTED', |
| 397 | changes='1,1 2,1 3,1'), |
| 398 | dict(name='project-test2', result='ABORTED', |
| 399 | changes='1,1 2,1 3,1'), |
| 400 | ], ordered=False) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 401 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 402 | self.launch_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 403 | self.waitUntilSettled() |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 404 | self.launch_server.release('.*-merge') |
| 405 | self.waitUntilSettled() |
| 406 | self.orderedRelease() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 407 | |
James E. Blair | b536ecc | 2016-08-31 10:11:42 -0700 | [diff] [blame^] | 408 | self.assertBuilds([]) |
| 409 | self.assertHistory([ |
| 410 | dict(name='project-merge', result='SUCCESS', |
| 411 | changes='1,1'), |
| 412 | dict(name='project-merge', result='SUCCESS', |
| 413 | changes='1,1 2,1'), |
| 414 | dict(name='project-merge', result='SUCCESS', |
| 415 | changes='1,1 2,1 3,1'), |
| 416 | dict(name='project-test1', result='FAILURE', |
| 417 | changes='1,1'), |
| 418 | dict(name='project-test1', result='ABORTED', |
| 419 | changes='1,1 2,1'), |
| 420 | dict(name='project-test2', result='ABORTED', |
| 421 | changes='1,1 2,1'), |
| 422 | dict(name='project-test1', result='ABORTED', |
| 423 | changes='1,1 2,1 3,1'), |
| 424 | dict(name='project-test2', result='ABORTED', |
| 425 | changes='1,1 2,1 3,1'), |
| 426 | dict(name='project-merge', result='SUCCESS', |
| 427 | changes='2,1'), |
| 428 | dict(name='project-merge', result='SUCCESS', |
| 429 | changes='2,1 3,1'), |
| 430 | dict(name='project-test2', result='SUCCESS', |
| 431 | changes='1,1'), |
| 432 | dict(name='project-test1', result='SUCCESS', |
| 433 | changes='2,1'), |
| 434 | dict(name='project-test2', result='SUCCESS', |
| 435 | changes='2,1'), |
| 436 | dict(name='project-test1', result='SUCCESS', |
| 437 | changes='2,1 3,1'), |
| 438 | dict(name='project-test2', result='SUCCESS', |
| 439 | changes='2,1 3,1'), |
| 440 | ], ordered=False) |
| 441 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 442 | self.assertEqual(A.data['status'], 'NEW') |
| 443 | self.assertEqual(B.data['status'], 'MERGED') |
| 444 | self.assertEqual(C.data['status'], 'MERGED') |
| 445 | self.assertEqual(A.reported, 2) |
| 446 | self.assertEqual(B.reported, 2) |
| 447 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 448 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 449 | @skip("Disabled for early v3 development") |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 450 | def test_failed_change_in_middle(self): |
| 451 | "Test a failed change in the middle of the queue" |
| 452 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 453 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 454 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 455 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 456 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 457 | A.addApproval('code-review', 2) |
| 458 | B.addApproval('code-review', 2) |
| 459 | C.addApproval('code-review', 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 460 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 461 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 462 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 463 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 464 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 465 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 466 | |
| 467 | self.waitUntilSettled() |
| 468 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 469 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 470 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 471 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 472 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 473 | self.launch_server.release('.*-merge') |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 474 | self.waitUntilSettled() |
| 475 | |
| 476 | self.assertEqual(len(self.builds), 6) |
| 477 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 478 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 479 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 480 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 481 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 482 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 483 | |
| 484 | self.release(self.builds[2]) |
| 485 | self.waitUntilSettled() |
| 486 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 487 | # project-test1 and project-test2 for A |
| 488 | # project-test2 for B |
| 489 | # project-merge for C (without B) |
| 490 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 491 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 492 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 493 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 494 | self.waitUntilSettled() |
| 495 | |
| 496 | # project-test1 and project-test2 for A |
| 497 | # project-test2 for B |
| 498 | # project-test1 and project-test2 for C |
| 499 | self.assertEqual(len(self.builds), 5) |
| 500 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 501 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 502 | builds = items[0].current_build_set.getBuilds() |
| 503 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 504 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 505 | builds = items[1].current_build_set.getBuilds() |
| 506 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 507 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 508 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 509 | builds = items[2].current_build_set.getBuilds() |
| 510 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 511 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 512 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 513 | self.launch_server.hold_jobs_in_build = False |
| 514 | self.launch_server.release() |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 515 | self.waitUntilSettled() |
| 516 | |
| 517 | self.assertEqual(len(self.builds), 0) |
| 518 | self.assertEqual(len(self.history), 12) |
| 519 | self.assertEqual(A.data['status'], 'MERGED') |
| 520 | self.assertEqual(B.data['status'], 'NEW') |
| 521 | self.assertEqual(C.data['status'], 'MERGED') |
| 522 | self.assertEqual(A.reported, 2) |
| 523 | self.assertEqual(B.reported, 2) |
| 524 | self.assertEqual(C.reported, 2) |
| 525 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 526 | @skip("Disabled for early v3 development") |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 527 | def test_failed_change_at_head_with_queue(self): |
| 528 | "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] | 529 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 530 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 531 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 532 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 533 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 534 | A.addApproval('code-review', 2) |
| 535 | B.addApproval('code-review', 2) |
| 536 | C.addApproval('code-review', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 537 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 538 | self.launch_server.failJob('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 539 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 540 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 541 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 542 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 543 | |
| 544 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 545 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 546 | self.assertEqual(len(self.builds), 0) |
| 547 | self.assertEqual(len(queue), 1) |
| 548 | self.assertEqual(queue[0].name, 'build:project-merge') |
| 549 | self.assertTrue(self.job_has_changes(queue[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 550 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 551 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 552 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 553 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 554 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 555 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 556 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 557 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 558 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 559 | self.assertEqual(len(self.builds), 0) |
| 560 | self.assertEqual(len(queue), 6) |
| 561 | self.assertEqual(queue[0].name, 'build:project-test1') |
| 562 | self.assertEqual(queue[1].name, 'build:project-test2') |
| 563 | self.assertEqual(queue[2].name, 'build:project-test1') |
| 564 | self.assertEqual(queue[3].name, 'build:project-test2') |
| 565 | self.assertEqual(queue[4].name, 'build:project-test1') |
| 566 | self.assertEqual(queue[5].name, 'build:project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 567 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 568 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 569 | self.waitUntilSettled() |
| 570 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 571 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 572 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 573 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 574 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 575 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 576 | self.gearman_server.hold_jobs_in_queue = False |
| 577 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 578 | self.waitUntilSettled() |
| 579 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 580 | self.assertEqual(len(self.builds), 0) |
| 581 | self.assertEqual(len(self.history), 11) |
| 582 | self.assertEqual(A.data['status'], 'NEW') |
| 583 | self.assertEqual(B.data['status'], 'MERGED') |
| 584 | self.assertEqual(C.data['status'], 'MERGED') |
| 585 | self.assertEqual(A.reported, 2) |
| 586 | self.assertEqual(B.reported, 2) |
| 587 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 588 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 589 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 590 | def _test_time_database(self, iteration): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 591 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 592 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 593 | A.addApproval('code-review', 2) |
| 594 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 595 | self.waitUntilSettled() |
| 596 | time.sleep(2) |
| 597 | |
| 598 | data = json.loads(self.sched.formatStatusJSON()) |
| 599 | found_job = None |
| 600 | for pipeline in data['pipelines']: |
| 601 | if pipeline['name'] != 'gate': |
| 602 | continue |
| 603 | for queue in pipeline['change_queues']: |
| 604 | for head in queue['heads']: |
| 605 | for item in head: |
| 606 | for job in item['jobs']: |
| 607 | if job['name'] == 'project-merge': |
| 608 | found_job = job |
| 609 | break |
| 610 | |
| 611 | self.assertIsNotNone(found_job) |
| 612 | if iteration == 1: |
| 613 | self.assertIsNotNone(found_job['estimated_time']) |
| 614 | self.assertIsNone(found_job['remaining_time']) |
| 615 | else: |
| 616 | self.assertIsNotNone(found_job['estimated_time']) |
| 617 | self.assertTrue(found_job['estimated_time'] >= 2) |
| 618 | self.assertIsNotNone(found_job['remaining_time']) |
| 619 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 620 | self.launch_server.hold_jobs_in_build = False |
| 621 | self.launch_server.release() |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 622 | self.waitUntilSettled() |
| 623 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 624 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 625 | def test_time_database(self): |
| 626 | "Test the time database" |
| 627 | |
| 628 | self._test_time_database(1) |
| 629 | self._test_time_database(2) |
| 630 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 631 | @skip("Disabled for early v3 development") |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 632 | def test_two_failed_changes_at_head(self): |
| 633 | "Test that changes are reparented correctly if 2 fail at head" |
| 634 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 635 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 636 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 637 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 638 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 639 | A.addApproval('code-review', 2) |
| 640 | B.addApproval('code-review', 2) |
| 641 | C.addApproval('code-review', 2) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 642 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 643 | self.launch_server.failJob('project-test1', A) |
| 644 | self.launch_server.failJob('project-test1', B) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 645 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 646 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 647 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 648 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 649 | self.waitUntilSettled() |
| 650 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 651 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 652 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 653 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 654 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 655 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 656 | self.waitUntilSettled() |
| 657 | |
| 658 | self.assertEqual(len(self.builds), 6) |
| 659 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 660 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 661 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 662 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 663 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 664 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 665 | |
| 666 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 667 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 668 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 669 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 670 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 671 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 672 | |
| 673 | # Fail change B first |
| 674 | self.release(self.builds[2]) |
| 675 | self.waitUntilSettled() |
| 676 | |
| 677 | # restart of C after B failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 678 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 679 | self.waitUntilSettled() |
| 680 | |
| 681 | self.assertEqual(len(self.builds), 5) |
| 682 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 683 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 684 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 685 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 686 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 687 | |
| 688 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 689 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 690 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 691 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 692 | self.assertFalse(self.job_has_changes(self.builds[4], B)) |
| 693 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 694 | |
| 695 | # Finish running all passing jobs for change A |
| 696 | self.release(self.builds[1]) |
| 697 | self.waitUntilSettled() |
| 698 | # Fail and report change A |
| 699 | self.release(self.builds[0]) |
| 700 | self.waitUntilSettled() |
| 701 | |
| 702 | # restart of B,C after A failure |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 703 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 704 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 705 | self.launch_server.release('.*-merge') |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 706 | self.waitUntilSettled() |
| 707 | |
| 708 | self.assertEqual(len(self.builds), 4) |
| 709 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 710 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 711 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 712 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 713 | |
| 714 | self.assertFalse(self.job_has_changes(self.builds[1], A)) |
| 715 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
| 716 | self.assertFalse(self.job_has_changes(self.builds[1], C)) |
| 717 | |
| 718 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 719 | # After A failed and B and C restarted, B should be back in |
| 720 | # C's tests because it has not failed yet. |
| 721 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 722 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 723 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 724 | self.launch_server.hold_jobs_in_build = False |
| 725 | self.launch_server.release() |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 726 | self.waitUntilSettled() |
| 727 | |
| 728 | self.assertEqual(len(self.builds), 0) |
| 729 | self.assertEqual(len(self.history), 21) |
| 730 | self.assertEqual(A.data['status'], 'NEW') |
| 731 | self.assertEqual(B.data['status'], 'NEW') |
| 732 | self.assertEqual(C.data['status'], 'MERGED') |
| 733 | self.assertEqual(A.reported, 2) |
| 734 | self.assertEqual(B.reported, 2) |
| 735 | self.assertEqual(C.reported, 2) |
| 736 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 737 | @skip("Disabled for early v3 development") |
James E. Blair | ce8a213 | 2016-05-19 15:21:52 -0700 | [diff] [blame] | 738 | def test_parse_skip_if(self): |
| 739 | job_yaml = """ |
| 740 | jobs: |
| 741 | - name: job_name |
| 742 | skip-if: |
| 743 | - project: ^project_name$ |
| 744 | branch: ^stable/icehouse$ |
| 745 | all-files-match-any: |
| 746 | - ^filename$ |
| 747 | - project: ^project2_name$ |
| 748 | all-files-match-any: |
| 749 | - ^filename2$ |
| 750 | """.strip() |
| 751 | data = yaml.load(job_yaml) |
| 752 | config_job = data.get('jobs')[0] |
| 753 | cm = zuul.change_matcher |
| 754 | expected = cm.MatchAny([ |
| 755 | cm.MatchAll([ |
| 756 | cm.ProjectMatcher('^project_name$'), |
| 757 | cm.BranchMatcher('^stable/icehouse$'), |
| 758 | cm.MatchAllFiles([cm.FileMatcher('^filename$')]), |
| 759 | ]), |
| 760 | cm.MatchAll([ |
| 761 | cm.ProjectMatcher('^project2_name$'), |
| 762 | cm.MatchAllFiles([cm.FileMatcher('^filename2$')]), |
| 763 | ]), |
| 764 | ]) |
| 765 | matcher = self.sched._parseSkipIf(config_job) |
| 766 | self.assertEqual(expected, matcher) |
| 767 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 768 | @skip("Disabled for early v3 development") |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 769 | def test_patch_order(self): |
| 770 | "Test that dependent patches are tested in the right order" |
| 771 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 772 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 773 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 774 | A.addApproval('code-review', 2) |
| 775 | B.addApproval('code-review', 2) |
| 776 | C.addApproval('code-review', 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 777 | |
| 778 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 779 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 780 | M2.setMerged() |
| 781 | M1.setMerged() |
| 782 | |
| 783 | # C -> B -> A -> M1 -> M2 |
| 784 | # M2 is here to make sure it is never queried. If it is, it |
| 785 | # means zuul is walking down the entire history of merged |
| 786 | # changes. |
| 787 | |
| 788 | C.setDependsOn(B, 1) |
| 789 | B.setDependsOn(A, 1) |
| 790 | A.setDependsOn(M1, 1) |
| 791 | M1.setDependsOn(M2, 1) |
| 792 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 793 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 794 | |
| 795 | self.waitUntilSettled() |
| 796 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 797 | self.assertEqual(A.data['status'], 'NEW') |
| 798 | self.assertEqual(B.data['status'], 'NEW') |
| 799 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 800 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 801 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 802 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 803 | |
| 804 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 805 | self.assertEqual(M2.queried, 0) |
| 806 | self.assertEqual(A.data['status'], 'MERGED') |
| 807 | self.assertEqual(B.data['status'], 'MERGED') |
| 808 | self.assertEqual(C.data['status'], 'MERGED') |
| 809 | self.assertEqual(A.reported, 2) |
| 810 | self.assertEqual(B.reported, 2) |
| 811 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 812 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 813 | @skip("Disabled for early v3 development") |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 814 | def test_needed_changes_enqueue(self): |
| 815 | "Test that a needed change is enqueued ahead" |
| 816 | # A Given a git tree like this, if we enqueue |
| 817 | # / \ change C, we should walk up and down the tree |
| 818 | # B G and enqueue changes in the order ABCDEFG. |
| 819 | # /|\ This is also the order that you would get if |
| 820 | # *C E F you enqueued changes in the order ABCDEFG, so |
| 821 | # / the ordering is stable across re-enqueue events. |
| 822 | # D |
| 823 | |
| 824 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 825 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 826 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 827 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 828 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 829 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 830 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 831 | B.setDependsOn(A, 1) |
| 832 | C.setDependsOn(B, 1) |
| 833 | D.setDependsOn(C, 1) |
| 834 | E.setDependsOn(B, 1) |
| 835 | F.setDependsOn(B, 1) |
| 836 | G.setDependsOn(A, 1) |
| 837 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 838 | A.addApproval('code-review', 2) |
| 839 | B.addApproval('code-review', 2) |
| 840 | C.addApproval('code-review', 2) |
| 841 | D.addApproval('code-review', 2) |
| 842 | E.addApproval('code-review', 2) |
| 843 | F.addApproval('code-review', 2) |
| 844 | G.addApproval('code-review', 2) |
| 845 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 846 | |
| 847 | self.waitUntilSettled() |
| 848 | |
| 849 | self.assertEqual(A.data['status'], 'NEW') |
| 850 | self.assertEqual(B.data['status'], 'NEW') |
| 851 | self.assertEqual(C.data['status'], 'NEW') |
| 852 | self.assertEqual(D.data['status'], 'NEW') |
| 853 | self.assertEqual(E.data['status'], 'NEW') |
| 854 | self.assertEqual(F.data['status'], 'NEW') |
| 855 | self.assertEqual(G.data['status'], 'NEW') |
| 856 | |
| 857 | # We're about to add approvals to changes without adding the |
| 858 | # triggering events to Zuul, so that we can be sure that it is |
| 859 | # enqueing the changes based on dependencies, not because of |
| 860 | # triggering events. Since it will have the changes cached |
| 861 | # already (without approvals), we need to clear the cache |
| 862 | # first. |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 863 | for connection in self.connections.values(): |
| 864 | connection.maintainCache([]) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 865 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 866 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 867 | A.addApproval('approved', 1) |
| 868 | B.addApproval('approved', 1) |
| 869 | D.addApproval('approved', 1) |
| 870 | E.addApproval('approved', 1) |
| 871 | F.addApproval('approved', 1) |
| 872 | G.addApproval('approved', 1) |
| 873 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 874 | |
| 875 | for x in range(8): |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 876 | self.launch_server.release('.*-merge') |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 877 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 878 | self.launch_server.hold_jobs_in_build = False |
| 879 | self.launch_server.release() |
James E. Blair | 063672f | 2015-01-29 13:09:12 -0800 | [diff] [blame] | 880 | self.waitUntilSettled() |
| 881 | |
| 882 | self.assertEqual(A.data['status'], 'MERGED') |
| 883 | self.assertEqual(B.data['status'], 'MERGED') |
| 884 | self.assertEqual(C.data['status'], 'MERGED') |
| 885 | self.assertEqual(D.data['status'], 'MERGED') |
| 886 | self.assertEqual(E.data['status'], 'MERGED') |
| 887 | self.assertEqual(F.data['status'], 'MERGED') |
| 888 | self.assertEqual(G.data['status'], 'MERGED') |
| 889 | self.assertEqual(A.reported, 2) |
| 890 | self.assertEqual(B.reported, 2) |
| 891 | self.assertEqual(C.reported, 2) |
| 892 | self.assertEqual(D.reported, 2) |
| 893 | self.assertEqual(E.reported, 2) |
| 894 | self.assertEqual(F.reported, 2) |
| 895 | self.assertEqual(G.reported, 2) |
| 896 | self.assertEqual(self.history[6].changes, |
| 897 | '1,1 2,1 3,1 4,1 5,1 6,1 7,1') |
| 898 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 899 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 850ccb6 | 2014-11-27 11:31:02 +1100 | [diff] [blame] | 900 | def test_source_cache(self): |
| 901 | "Test that the source cache operates correctly" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 902 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 903 | |
| 904 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 905 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 906 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 907 | A.addApproval('code-review', 2) |
| 908 | B.addApproval('code-review', 2) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 909 | |
| 910 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 911 | M1.setMerged() |
| 912 | |
| 913 | B.setDependsOn(A, 1) |
| 914 | A.setDependsOn(M1, 1) |
| 915 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 916 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 917 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 918 | |
| 919 | self.waitUntilSettled() |
| 920 | |
| 921 | for build in self.builds: |
| 922 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 923 | build.release() |
| 924 | self.waitUntilSettled() |
| 925 | for build in self.builds: |
| 926 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 927 | build.release() |
| 928 | self.waitUntilSettled() |
| 929 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 930 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 931 | self.waitUntilSettled() |
| 932 | |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 933 | self.log.debug("len %s" % self.fake_gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 934 | # there should still be changes in the cache |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 935 | self.assertNotEqual(len(self.fake_gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 936 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 937 | self.launch_server.hold_jobs_in_build = False |
| 938 | self.launch_server.release() |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 939 | self.waitUntilSettled() |
| 940 | |
| 941 | self.assertEqual(A.data['status'], 'MERGED') |
| 942 | self.assertEqual(B.data['status'], 'MERGED') |
| 943 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 944 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 945 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 946 | @skip("Disabled for early v3 development") |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 947 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 948 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 949 | # TODO: move to test_gerrit (this is a unit test!) |
| 950 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 951 | source = self.sched.layout.pipelines['gate'].source |
| 952 | a = source._getChange(1, 2) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 953 | mgr = self.sched.layout.pipelines['gate'].manager |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 954 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 955 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 956 | A.addApproval('code-review', 2) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 957 | a = source._getChange(1, 2, refresh=True) |
| 958 | self.assertFalse(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 959 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 960 | A.addApproval('approved', 1) |
James E. Blair | c0dedf8 | 2014-08-06 09:37:52 -0700 | [diff] [blame] | 961 | a = source._getChange(1, 2, refresh=True) |
| 962 | self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 963 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 964 | @skip("Disabled for early v3 development") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 965 | def test_build_configuration(self): |
| 966 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 967 | |
| 968 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 969 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 970 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 971 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 972 | A.addApproval('code-review', 2) |
| 973 | B.addApproval('code-review', 2) |
| 974 | C.addApproval('code-review', 2) |
| 975 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 976 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 977 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 978 | self.waitUntilSettled() |
| 979 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 980 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 981 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 982 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 983 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 984 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 985 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 986 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 987 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 988 | self.gearman_server.hold_jobs_in_queue = False |
| 989 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 990 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 991 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 992 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 993 | repo = git.Repo(path) |
| 994 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 995 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 996 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 997 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 998 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 999 | @skip("Disabled for early v3 development") |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1000 | def test_build_configuration_conflict(self): |
| 1001 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1002 | |
| 1003 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1004 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1005 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1006 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1007 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1008 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1009 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1010 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1011 | 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1012 | A.addApproval('code-review', 2) |
| 1013 | B.addApproval('code-review', 2) |
| 1014 | C.addApproval('code-review', 2) |
| 1015 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1016 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1017 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1018 | self.waitUntilSettled() |
| 1019 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1020 | self.assertEqual(A.reported, 1) |
| 1021 | self.assertEqual(B.reported, 1) |
| 1022 | self.assertEqual(C.reported, 1) |
| 1023 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1024 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1025 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1026 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1027 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1028 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1029 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1030 | |
| 1031 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 1032 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1033 | self.gearman_server.hold_jobs_in_queue = False |
| 1034 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1035 | self.waitUntilSettled() |
| 1036 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1037 | self.assertEqual(A.data['status'], 'MERGED') |
| 1038 | self.assertEqual(B.data['status'], 'NEW') |
| 1039 | self.assertEqual(C.data['status'], 'MERGED') |
| 1040 | self.assertEqual(A.reported, 2) |
| 1041 | self.assertEqual(B.reported, 2) |
| 1042 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1043 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1044 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1045 | @skip("Disabled for early v3 development") |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1046 | def test_post(self): |
| 1047 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1048 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1049 | e = { |
| 1050 | "type": "ref-updated", |
| 1051 | "submitter": { |
| 1052 | "name": "User Name", |
| 1053 | }, |
| 1054 | "refUpdate": { |
| 1055 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1056 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1057 | "refName": "master", |
| 1058 | "project": "org/project", |
| 1059 | } |
| 1060 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1061 | self.fake_gerrit.addEvent(e) |
| 1062 | self.waitUntilSettled() |
| 1063 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1064 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1065 | self.assertEqual(len(self.history), 1) |
| 1066 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1067 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1068 | @skip("Disabled for early v3 development") |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1069 | def test_post_ignore_deletes(self): |
| 1070 | "Test that deleting refs does not trigger post jobs" |
| 1071 | |
| 1072 | e = { |
| 1073 | "type": "ref-updated", |
| 1074 | "submitter": { |
| 1075 | "name": "User Name", |
| 1076 | }, |
| 1077 | "refUpdate": { |
| 1078 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1079 | "newRev": "0000000000000000000000000000000000000000", |
| 1080 | "refName": "master", |
| 1081 | "project": "org/project", |
| 1082 | } |
| 1083 | } |
| 1084 | self.fake_gerrit.addEvent(e) |
| 1085 | self.waitUntilSettled() |
| 1086 | |
| 1087 | job_names = [x.name for x in self.history] |
| 1088 | self.assertEqual(len(self.history), 0) |
| 1089 | self.assertNotIn('project-post', job_names) |
| 1090 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1091 | @skip("Disabled for early v3 development") |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1092 | def test_post_ignore_deletes_negative(self): |
| 1093 | "Test that deleting refs does trigger post jobs" |
| 1094 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1095 | self.updateConfigLayout( |
| 1096 | 'tests/fixtures/layout-dont-ignore-deletes.yaml') |
K Jonathan Harker | f95e723 | 2015-04-29 13:33:16 -0700 | [diff] [blame] | 1097 | self.sched.reconfigure(self.config) |
| 1098 | |
| 1099 | e = { |
| 1100 | "type": "ref-updated", |
| 1101 | "submitter": { |
| 1102 | "name": "User Name", |
| 1103 | }, |
| 1104 | "refUpdate": { |
| 1105 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1106 | "newRev": "0000000000000000000000000000000000000000", |
| 1107 | "refName": "master", |
| 1108 | "project": "org/project", |
| 1109 | } |
| 1110 | } |
| 1111 | self.fake_gerrit.addEvent(e) |
| 1112 | self.waitUntilSettled() |
| 1113 | |
| 1114 | job_names = [x.name for x in self.history] |
| 1115 | self.assertEqual(len(self.history), 1) |
| 1116 | self.assertIn('project-post', job_names) |
| 1117 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1118 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1119 | def test_build_configuration_branch(self): |
| 1120 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1121 | |
| 1122 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1123 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1124 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1125 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1126 | A.addApproval('code-review', 2) |
| 1127 | B.addApproval('code-review', 2) |
| 1128 | C.addApproval('code-review', 2) |
| 1129 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1130 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1131 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1132 | self.waitUntilSettled() |
| 1133 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1134 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1135 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1136 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1137 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1138 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1139 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1140 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1141 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1142 | self.gearman_server.hold_jobs_in_queue = False |
| 1143 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1144 | self.waitUntilSettled() |
| 1145 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1146 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1147 | repo = git.Repo(path) |
| 1148 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1149 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1150 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1151 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1152 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1153 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1154 | def test_build_configuration_branch_interaction(self): |
| 1155 | "Test that switching between branches works" |
| 1156 | self.test_build_configuration() |
| 1157 | self.test_build_configuration_branch() |
| 1158 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1159 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1160 | repo = git.Repo(path) |
| 1161 | repo.heads.master.commit = repo.commit('init') |
| 1162 | self.test_build_configuration() |
| 1163 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1164 | @skip("Disabled for early v3 development") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1165 | def test_build_configuration_multi_branch(self): |
| 1166 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1167 | |
| 1168 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1169 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1170 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1171 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1172 | A.addApproval('code-review', 2) |
| 1173 | B.addApproval('code-review', 2) |
| 1174 | C.addApproval('code-review', 2) |
| 1175 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1176 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1177 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1178 | self.waitUntilSettled() |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1179 | queue = self.gearman_server.getQueue() |
| 1180 | job_A = None |
| 1181 | for job in queue: |
| 1182 | if 'project-merge' in job.name: |
| 1183 | job_A = job |
| 1184 | ref_A = self.getParameter(job_A, 'ZUUL_REF') |
| 1185 | commit_A = self.getParameter(job_A, 'ZUUL_COMMIT') |
| 1186 | self.log.debug("Got Zuul ref for change A: %s" % ref_A) |
| 1187 | self.log.debug("Got Zuul commit for change A: %s" % commit_A) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1188 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1189 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1190 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1191 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1192 | job_B = None |
| 1193 | for job in queue: |
| 1194 | if 'project-merge' in job.name: |
| 1195 | job_B = job |
| 1196 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1197 | commit_B = self.getParameter(job_B, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1198 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1199 | self.log.debug("Got Zuul commit for change B: %s" % commit_B) |
| 1200 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1201 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1202 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1203 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1204 | for job in queue: |
| 1205 | if 'project-merge' in job.name: |
| 1206 | job_C = job |
| 1207 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1208 | commit_C = self.getParameter(job_C, 'ZUUL_COMMIT') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1209 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1210 | self.log.debug("Got Zuul commit for change C: %s" % commit_C) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1211 | self.gearman_server.hold_jobs_in_queue = False |
| 1212 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1213 | self.waitUntilSettled() |
| 1214 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1215 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1216 | repo = git.Repo(path) |
| 1217 | |
| 1218 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1219 | for c in repo.iter_commits(ref_C)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1220 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_C)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1221 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1222 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1223 | # Ensure the right commits are in the history for this ref |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1224 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1225 | # Ensure ZUUL_REF -> ZUUL_COMMIT |
| 1226 | self.assertEqual(repo_shas[0], commit_C) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1227 | |
| 1228 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1229 | for c in repo.iter_commits(ref_B)] |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1230 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_B)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1231 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1232 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1233 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | bb1fe50 | 2014-03-04 10:15:06 -0800 | [diff] [blame] | 1234 | self.assertEqual(repo_shas[0], commit_B) |
| 1235 | |
| 1236 | repo_messages = [c.message.strip() |
| 1237 | for c in repo.iter_commits(ref_A)] |
| 1238 | repo_shas = [c.hexsha for c in repo.iter_commits(ref_A)] |
| 1239 | repo_messages.reverse() |
| 1240 | correct_messages = ['initial commit', 'A-1'] |
| 1241 | self.assertEqual(repo_messages, correct_messages) |
| 1242 | self.assertEqual(repo_shas[0], commit_A) |
| 1243 | |
| 1244 | self.assertNotEqual(ref_A, ref_B, ref_C) |
| 1245 | self.assertNotEqual(commit_A, commit_B, commit_C) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1246 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1247 | @skip("Disabled for early v3 development") |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1248 | def test_one_job_project(self): |
| 1249 | "Test that queueing works with one job" |
| 1250 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1251 | 'master', 'A') |
| 1252 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1253 | 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1254 | A.addApproval('code-review', 2) |
| 1255 | B.addApproval('code-review', 2) |
| 1256 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1257 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1258 | self.waitUntilSettled() |
| 1259 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1260 | self.assertEqual(A.data['status'], 'MERGED') |
| 1261 | self.assertEqual(A.reported, 2) |
| 1262 | self.assertEqual(B.data['status'], 'MERGED') |
| 1263 | self.assertEqual(B.reported, 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1264 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1265 | @skip("Disabled for early v3 development") |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1266 | def test_job_from_templates_launched(self): |
| 1267 | "Test whether a job generated via a template can be launched" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1268 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1269 | A = self.fake_gerrit.addFakeChange( |
| 1270 | 'org/templated-project', 'master', 'A') |
| 1271 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1272 | self.waitUntilSettled() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1273 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1274 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1275 | 'SUCCESS') |
| 1276 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1277 | 'SUCCESS') |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1278 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1279 | @skip("Disabled for early v3 development") |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1280 | def test_layered_templates(self): |
| 1281 | "Test whether a job generated via a template can be launched" |
| 1282 | |
| 1283 | A = self.fake_gerrit.addFakeChange( |
| 1284 | 'org/layered-project', 'master', 'A') |
| 1285 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1286 | self.waitUntilSettled() |
| 1287 | |
| 1288 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1289 | 'SUCCESS') |
| 1290 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1291 | 'SUCCESS') |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 1292 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 1293 | ).result, 'SUCCESS') |
| 1294 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 1295 | ).result, 'SUCCESS') |
James E. Blair | 12a92b1 | 2014-03-26 11:54:53 -0700 | [diff] [blame] | 1296 | self.assertEqual(self.getJobFromHistory('layered-project-foo-test5' |
| 1297 | ).result, 'SUCCESS') |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 1298 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 1299 | 'SUCCESS') |
| 1300 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1301 | @skip("Disabled for early v3 development") |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1302 | def test_dependent_changes_dequeue(self): |
| 1303 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1304 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1305 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1306 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1307 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1308 | A.addApproval('code-review', 2) |
| 1309 | B.addApproval('code-review', 2) |
| 1310 | C.addApproval('code-review', 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1311 | |
| 1312 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1313 | M1.setMerged() |
| 1314 | |
| 1315 | # C -> B -> A -> M1 |
| 1316 | |
| 1317 | C.setDependsOn(B, 1) |
| 1318 | B.setDependsOn(A, 1) |
| 1319 | A.setDependsOn(M1, 1) |
| 1320 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1321 | self.launch_server.failJob('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1322 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1323 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1324 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1325 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1326 | |
| 1327 | self.waitUntilSettled() |
| 1328 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1329 | self.assertEqual(A.data['status'], 'NEW') |
| 1330 | self.assertEqual(A.reported, 2) |
| 1331 | self.assertEqual(B.data['status'], 'NEW') |
| 1332 | self.assertEqual(B.reported, 2) |
| 1333 | self.assertEqual(C.data['status'], 'NEW') |
| 1334 | self.assertEqual(C.reported, 2) |
| 1335 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1336 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1337 | @skip("Disabled for early v3 development") |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1338 | def test_failing_dependent_changes(self): |
| 1339 | "Test that failing dependent patches are taken out of stream" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1340 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1341 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1342 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1343 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1344 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 1345 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1346 | A.addApproval('code-review', 2) |
| 1347 | B.addApproval('code-review', 2) |
| 1348 | C.addApproval('code-review', 2) |
| 1349 | D.addApproval('code-review', 2) |
| 1350 | E.addApproval('code-review', 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1351 | |
| 1352 | # E, D -> C -> B, A |
| 1353 | |
| 1354 | D.setDependsOn(C, 1) |
| 1355 | C.setDependsOn(B, 1) |
| 1356 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1357 | self.launch_server.failJob('project-test1', B) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1358 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1359 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1360 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
| 1361 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1362 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1363 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1364 | |
| 1365 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1366 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1367 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1368 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1369 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1370 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1371 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1372 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1373 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1374 | self.launch_server.release('.*-merge') |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1375 | self.waitUntilSettled() |
| 1376 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1377 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1378 | for build in self.builds: |
| 1379 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 1380 | build.release() |
| 1381 | self.waitUntilSettled() |
| 1382 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1383 | self.launch_server.release() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1384 | self.waitUntilSettled() |
| 1385 | |
| 1386 | self.assertEqual(A.data['status'], 'MERGED') |
| 1387 | self.assertEqual(A.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1388 | self.assertIn('Build succeeded', A.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1389 | self.assertEqual(B.data['status'], 'NEW') |
| 1390 | self.assertEqual(B.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1391 | self.assertIn('Build failed', B.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1392 | self.assertEqual(C.data['status'], 'NEW') |
| 1393 | self.assertEqual(C.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1394 | self.assertIn('depends on a change', C.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1395 | self.assertEqual(D.data['status'], 'NEW') |
| 1396 | self.assertEqual(D.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1397 | self.assertIn('depends on a change', D.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1398 | self.assertEqual(E.data['status'], 'MERGED') |
| 1399 | self.assertEqual(E.reported, 2) |
Jeremy Stanley | 1083713 | 2014-08-02 16:10:56 +0000 | [diff] [blame] | 1400 | self.assertIn('Build succeeded', E.messages[1]) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1401 | self.assertEqual(len(self.history), 18) |
| 1402 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1403 | @skip("Disabled for early v3 development") |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1404 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1405 | "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] | 1406 | # If it's dequeued more than once, we should see extra |
| 1407 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1408 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1409 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1410 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1411 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1412 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1413 | A.addApproval('code-review', 2) |
| 1414 | B.addApproval('code-review', 2) |
| 1415 | C.addApproval('code-review', 2) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1416 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1417 | self.launch_server.failJob('project1-test1', A) |
| 1418 | self.launch_server.failJob('project1-test2', A) |
| 1419 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1420 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1421 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1422 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1423 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1424 | |
| 1425 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1426 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1427 | self.assertEqual(len(self.builds), 1) |
| 1428 | self.assertEqual(self.builds[0].name, 'project1-merge') |
| 1429 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1430 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1431 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1432 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1433 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1434 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1435 | self.launch_server.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1436 | self.waitUntilSettled() |
| 1437 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1438 | self.assertEqual(len(self.builds), 9) |
| 1439 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 1440 | self.assertEqual(self.builds[1].name, 'project1-test2') |
| 1441 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
| 1442 | self.assertEqual(self.builds[3].name, 'project1-test1') |
| 1443 | self.assertEqual(self.builds[4].name, 'project1-test2') |
| 1444 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
| 1445 | self.assertEqual(self.builds[6].name, 'project1-test1') |
| 1446 | self.assertEqual(self.builds[7].name, 'project1-test2') |
| 1447 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1448 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1449 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1450 | self.waitUntilSettled() |
| 1451 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1452 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 1453 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1454 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1455 | self.launch_server.hold_jobs_in_build = False |
| 1456 | self.launch_server.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 1457 | self.waitUntilSettled() |
| 1458 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1459 | self.assertEqual(len(self.builds), 0) |
| 1460 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1461 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1462 | self.assertEqual(A.data['status'], 'NEW') |
| 1463 | self.assertEqual(B.data['status'], 'MERGED') |
| 1464 | self.assertEqual(C.data['status'], 'MERGED') |
| 1465 | self.assertEqual(A.reported, 2) |
| 1466 | self.assertEqual(B.reported, 2) |
| 1467 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1468 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1469 | @skip("Disabled for early v3 development") |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1470 | def test_nonvoting_job(self): |
| 1471 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1472 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1473 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 1474 | 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1475 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1476 | self.launch_server.failJob('nonvoting-project-test2', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1477 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1478 | |
| 1479 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 1480 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1481 | self.assertEqual(A.data['status'], 'MERGED') |
| 1482 | self.assertEqual(A.reported, 2) |
| 1483 | self.assertEqual( |
| 1484 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 1485 | 'SUCCESS') |
| 1486 | self.assertEqual( |
| 1487 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 1488 | 'SUCCESS') |
| 1489 | self.assertEqual( |
| 1490 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 1491 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1492 | |
James E. Blair | 5821bd9 | 2015-09-16 08:48:15 -0700 | [diff] [blame] | 1493 | for build in self.builds: |
| 1494 | self.assertEqual(build.parameters['ZUUL_VOTING'], '0') |
| 1495 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1496 | @skip("Disabled for early v3 development") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1497 | def test_check_queue_success(self): |
| 1498 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1499 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1500 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1501 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1502 | |
| 1503 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1504 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1505 | self.assertEqual(A.data['status'], 'NEW') |
| 1506 | self.assertEqual(A.reported, 1) |
| 1507 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1508 | 'SUCCESS') |
| 1509 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1510 | 'SUCCESS') |
| 1511 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1512 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1513 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1514 | @skip("Disabled for early v3 development") |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1515 | def test_check_queue_failure(self): |
| 1516 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1517 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1518 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1519 | self.launch_server.failJob('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1520 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1521 | |
| 1522 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1523 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1524 | self.assertEqual(A.data['status'], 'NEW') |
| 1525 | self.assertEqual(A.reported, 1) |
| 1526 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 1527 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1528 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1529 | 'SUCCESS') |
| 1530 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1531 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1532 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1533 | @skip("Disabled for early v3 development") |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1534 | def test_dependent_behind_dequeue(self): |
| 1535 | "test that dependent changes behind dequeued changes work" |
| 1536 | # This complicated test is a reproduction of a real life bug |
| 1537 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1538 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1539 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1540 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1541 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1542 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 1543 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 1544 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 1545 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 1546 | D.setDependsOn(C, 1) |
| 1547 | E.setDependsOn(D, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1548 | A.addApproval('code-review', 2) |
| 1549 | B.addApproval('code-review', 2) |
| 1550 | C.addApproval('code-review', 2) |
| 1551 | D.addApproval('code-review', 2) |
| 1552 | E.addApproval('code-review', 2) |
| 1553 | F.addApproval('code-review', 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1554 | |
| 1555 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1556 | |
| 1557 | # Change object re-use in the gerrit trigger is hidden if |
| 1558 | # changes are added in quick succession; waiting makes it more |
| 1559 | # like real life. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1560 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1561 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1562 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1563 | self.waitUntilSettled() |
| 1564 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1565 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1566 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1567 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1568 | self.waitUntilSettled() |
| 1569 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1570 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1571 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1572 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1573 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1574 | self.fake_gerrit.addEvent(E.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1575 | self.waitUntilSettled() |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1576 | self.fake_gerrit.addEvent(F.addApproval('approved', 1)) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1577 | self.waitUntilSettled() |
| 1578 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1579 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1580 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1581 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1582 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1583 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1584 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1585 | self.launch_server.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1586 | self.waitUntilSettled() |
| 1587 | |
| 1588 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1589 | |
| 1590 | # Grab pointers to the jobs we want to release before |
| 1591 | # releasing any, because list indexes may change as |
| 1592 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1593 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 1594 | a.release() |
| 1595 | b.release() |
| 1596 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1597 | self.waitUntilSettled() |
| 1598 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1599 | self.launch_server.hold_jobs_in_build = False |
| 1600 | self.launch_server.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1601 | self.waitUntilSettled() |
| 1602 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1603 | self.assertEqual(A.data['status'], 'NEW') |
| 1604 | self.assertEqual(B.data['status'], 'MERGED') |
| 1605 | self.assertEqual(C.data['status'], 'MERGED') |
| 1606 | self.assertEqual(D.data['status'], 'MERGED') |
| 1607 | self.assertEqual(E.data['status'], 'MERGED') |
| 1608 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1609 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1610 | self.assertEqual(A.reported, 2) |
| 1611 | self.assertEqual(B.reported, 2) |
| 1612 | self.assertEqual(C.reported, 2) |
| 1613 | self.assertEqual(D.reported, 2) |
| 1614 | self.assertEqual(E.reported, 2) |
| 1615 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 1616 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1617 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 1618 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1619 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1620 | @skip("Disabled for early v3 development") |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1621 | def test_merger_repack(self): |
| 1622 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1623 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1624 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1625 | A.addApproval('code-review', 2) |
| 1626 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1627 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1628 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1629 | 'SUCCESS') |
| 1630 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1631 | 'SUCCESS') |
| 1632 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1633 | 'SUCCESS') |
| 1634 | self.assertEqual(A.data['status'], 'MERGED') |
| 1635 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1636 | self.assertEmptyQueues() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 1637 | self.worker.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1638 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1639 | path = os.path.join(self.git_root, "org/project") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1640 | print(repack_repo(path)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1641 | |
| 1642 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1643 | A.addApproval('code-review', 2) |
| 1644 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 1645 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1646 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1647 | 'SUCCESS') |
| 1648 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1649 | 'SUCCESS') |
| 1650 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1651 | 'SUCCESS') |
| 1652 | self.assertEqual(A.data['status'], 'MERGED') |
| 1653 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1654 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1655 | @skip("Disabled for early v3 development") |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1656 | def test_merger_repack_large_change(self): |
| 1657 | "Test that the merger works with large changes after a repack" |
| 1658 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1659 | # This test assumes the repo is already cloned; make sure it is |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 1660 | url = self.fake_gerrit.getGitUrl( |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 1661 | self.sched.layout.projects['org/project1']) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 1662 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1663 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 1664 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1665 | path = os.path.join(self.upstream_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1666 | print(repack_repo(path)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1667 | path = os.path.join(self.git_root, "org/project1") |
Morgan Fainberg | 4c6a774 | 2016-05-27 08:42:17 -0700 | [diff] [blame] | 1668 | print(repack_repo(path)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1669 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1670 | A.addApproval('code-review', 2) |
| 1671 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1672 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1673 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 1674 | 'SUCCESS') |
| 1675 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 1676 | 'SUCCESS') |
| 1677 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 1678 | 'SUCCESS') |
| 1679 | self.assertEqual(A.data['status'], 'MERGED') |
| 1680 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 1681 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1682 | @skip("Disabled for early v3 development") |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1683 | def test_nonexistent_job(self): |
| 1684 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1685 | # Set to the state immediately after a restart |
| 1686 | self.resetGearmanServer() |
| 1687 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1688 | |
| 1689 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1690 | A.addApproval('code-review', 2) |
| 1691 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1692 | # There may be a thread about to report a lost change |
| 1693 | while A.reported < 2: |
| 1694 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1695 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1696 | self.assertFalse(job_names) |
| 1697 | self.assertEqual(A.data['status'], 'NEW') |
| 1698 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1699 | self.assertEmptyQueues() |
| 1700 | |
| 1701 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1702 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1703 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1704 | A.addApproval('code-review', 2) |
| 1705 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 1706 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1707 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1708 | 'SUCCESS') |
| 1709 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1710 | 'SUCCESS') |
| 1711 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1712 | 'SUCCESS') |
| 1713 | self.assertEqual(A.data['status'], 'MERGED') |
| 1714 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1715 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1716 | @skip("Disabled for early v3 development") |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1717 | def test_single_nonexistent_post_job(self): |
| 1718 | "Test launching a single post job that doesn't exist" |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1719 | e = { |
| 1720 | "type": "ref-updated", |
| 1721 | "submitter": { |
| 1722 | "name": "User Name", |
| 1723 | }, |
| 1724 | "refUpdate": { |
| 1725 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1726 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1727 | "refName": "master", |
| 1728 | "project": "org/project", |
| 1729 | } |
| 1730 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1731 | # Set to the state immediately after a restart |
| 1732 | self.resetGearmanServer() |
| 1733 | self.launcher.negative_function_cache_ttl = 0 |
| 1734 | |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1735 | self.fake_gerrit.addEvent(e) |
| 1736 | self.waitUntilSettled() |
| 1737 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1738 | self.assertEqual(len(self.history), 0) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1739 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1740 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1741 | def test_new_patchset_dequeues_old(self): |
| 1742 | "Test that a new patchset causes the old to be dequeued" |
| 1743 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1744 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1745 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 1746 | M.setMerged() |
| 1747 | |
| 1748 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1749 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1750 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1751 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1752 | A.addApproval('code-review', 2) |
| 1753 | B.addApproval('code-review', 2) |
| 1754 | C.addApproval('code-review', 2) |
| 1755 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1756 | |
| 1757 | C.setDependsOn(B, 1) |
| 1758 | B.setDependsOn(A, 1) |
| 1759 | A.setDependsOn(M, 1) |
| 1760 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1761 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 1762 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 1763 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 1764 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1765 | self.waitUntilSettled() |
| 1766 | |
| 1767 | B.addPatchset() |
| 1768 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1769 | self.waitUntilSettled() |
| 1770 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1771 | self.launch_server.hold_jobs_in_build = False |
| 1772 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 1773 | self.waitUntilSettled() |
| 1774 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1775 | self.assertEqual(A.data['status'], 'MERGED') |
| 1776 | self.assertEqual(A.reported, 2) |
| 1777 | self.assertEqual(B.data['status'], 'NEW') |
| 1778 | self.assertEqual(B.reported, 2) |
| 1779 | self.assertEqual(C.data['status'], 'NEW') |
| 1780 | self.assertEqual(C.reported, 2) |
| 1781 | self.assertEqual(D.data['status'], 'MERGED') |
| 1782 | self.assertEqual(D.reported, 2) |
| 1783 | 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] | 1784 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1785 | @skip("Disabled for early v3 development") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1786 | def test_new_patchset_check(self): |
| 1787 | "Test a new patchset in check" |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1788 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1789 | self.launch_server.hold_jobs_in_build = True |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1790 | |
| 1791 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1792 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1793 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1794 | |
| 1795 | # Add two git-dependent changes |
| 1796 | B.setDependsOn(A, 1) |
| 1797 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1798 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1799 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1800 | self.waitUntilSettled() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1801 | |
| 1802 | # A live item, and a non-live/live pair |
| 1803 | items = check_pipeline.getAllItems() |
| 1804 | self.assertEqual(len(items), 3) |
| 1805 | |
| 1806 | self.assertEqual(items[0].change.number, '1') |
| 1807 | self.assertEqual(items[0].change.patchset, '1') |
| 1808 | self.assertFalse(items[0].live) |
| 1809 | |
| 1810 | self.assertEqual(items[1].change.number, '2') |
| 1811 | self.assertEqual(items[1].change.patchset, '1') |
| 1812 | self.assertTrue(items[1].live) |
| 1813 | |
| 1814 | self.assertEqual(items[2].change.number, '1') |
| 1815 | self.assertEqual(items[2].change.patchset, '1') |
| 1816 | self.assertTrue(items[2].live) |
| 1817 | |
| 1818 | # Add a new patchset to A |
| 1819 | A.addPatchset() |
| 1820 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 1821 | self.waitUntilSettled() |
| 1822 | |
| 1823 | # The live copy of A,1 should be gone, but the non-live and B |
| 1824 | # should continue, and we should have a new A,2 |
| 1825 | items = check_pipeline.getAllItems() |
| 1826 | self.assertEqual(len(items), 3) |
| 1827 | |
| 1828 | self.assertEqual(items[0].change.number, '1') |
| 1829 | self.assertEqual(items[0].change.patchset, '1') |
| 1830 | self.assertFalse(items[0].live) |
| 1831 | |
| 1832 | self.assertEqual(items[1].change.number, '2') |
| 1833 | self.assertEqual(items[1].change.patchset, '1') |
| 1834 | self.assertTrue(items[1].live) |
| 1835 | |
| 1836 | self.assertEqual(items[2].change.number, '1') |
| 1837 | self.assertEqual(items[2].change.patchset, '2') |
| 1838 | self.assertTrue(items[2].live) |
| 1839 | |
| 1840 | # Add a new patchset to B |
| 1841 | B.addPatchset() |
| 1842 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 1843 | self.waitUntilSettled() |
| 1844 | |
| 1845 | # The live copy of B,1 should be gone, and it's non-live copy of A,1 |
| 1846 | # but we should have a new B,2 (still based on A,1) |
| 1847 | items = check_pipeline.getAllItems() |
| 1848 | self.assertEqual(len(items), 3) |
| 1849 | |
| 1850 | self.assertEqual(items[0].change.number, '1') |
| 1851 | self.assertEqual(items[0].change.patchset, '2') |
| 1852 | self.assertTrue(items[0].live) |
| 1853 | |
| 1854 | self.assertEqual(items[1].change.number, '1') |
| 1855 | self.assertEqual(items[1].change.patchset, '1') |
| 1856 | self.assertFalse(items[1].live) |
| 1857 | |
| 1858 | self.assertEqual(items[2].change.number, '2') |
| 1859 | self.assertEqual(items[2].change.patchset, '2') |
| 1860 | self.assertTrue(items[2].live) |
| 1861 | |
| 1862 | self.builds[0].release() |
| 1863 | self.waitUntilSettled() |
| 1864 | self.builds[0].release() |
| 1865 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1866 | self.launch_server.hold_jobs_in_build = False |
| 1867 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1868 | self.waitUntilSettled() |
| 1869 | |
| 1870 | self.assertEqual(A.reported, 1) |
| 1871 | self.assertEqual(B.reported, 1) |
| 1872 | self.assertEqual(self.history[0].result, 'ABORTED') |
| 1873 | self.assertEqual(self.history[0].changes, '1,1') |
| 1874 | self.assertEqual(self.history[1].result, 'ABORTED') |
| 1875 | self.assertEqual(self.history[1].changes, '1,1 2,1') |
| 1876 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 1877 | self.assertEqual(self.history[2].changes, '1,2') |
| 1878 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 1879 | self.assertEqual(self.history[3].changes, '1,1 2,2') |
| 1880 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1881 | @skip("Disabled for early v3 development") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1882 | def test_abandoned_gate(self): |
| 1883 | "Test that an abandoned change is dequeued from gate" |
| 1884 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1885 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1886 | |
| 1887 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 1888 | A.addApproval('code-review', 2) |
| 1889 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1890 | self.waitUntilSettled() |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1891 | self.assertEqual(len(self.builds), 1, "One job being built (on hold)") |
| 1892 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1893 | |
| 1894 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1895 | self.waitUntilSettled() |
| 1896 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1897 | self.launch_server.release('.*-merge') |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1898 | self.waitUntilSettled() |
| 1899 | |
| 1900 | self.assertEqual(len(self.builds), 0, "No job running") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1901 | self.assertEqual(len(self.history), 1, "Only one build in history") |
| 1902 | self.assertEqual(self.history[0].result, 'ABORTED', |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1903 | "Build should have been aborted") |
| 1904 | self.assertEqual(A.reported, 1, |
| 1905 | "Abandoned gate change should report only start") |
| 1906 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1907 | @skip("Disabled for early v3 development") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1908 | def test_abandoned_check(self): |
| 1909 | "Test that an abandoned change is dequeued from check" |
| 1910 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1911 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1912 | |
| 1913 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1914 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1915 | check_pipeline = self.sched.layout.pipelines['check'] |
| 1916 | |
| 1917 | # Add two git-dependent changes |
| 1918 | B.setDependsOn(A, 1) |
| 1919 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 1920 | self.waitUntilSettled() |
| 1921 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1922 | self.waitUntilSettled() |
| 1923 | # A live item, and a non-live/live pair |
| 1924 | items = check_pipeline.getAllItems() |
| 1925 | self.assertEqual(len(items), 3) |
| 1926 | |
| 1927 | self.assertEqual(items[0].change.number, '1') |
| 1928 | self.assertFalse(items[0].live) |
| 1929 | |
| 1930 | self.assertEqual(items[1].change.number, '2') |
| 1931 | self.assertTrue(items[1].live) |
| 1932 | |
| 1933 | self.assertEqual(items[2].change.number, '1') |
| 1934 | self.assertTrue(items[2].live) |
| 1935 | |
| 1936 | # Abandon A |
| 1937 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1938 | self.waitUntilSettled() |
| 1939 | |
| 1940 | # The live copy of A should be gone, but the non-live and B |
| 1941 | # should continue |
| 1942 | items = check_pipeline.getAllItems() |
| 1943 | self.assertEqual(len(items), 2) |
| 1944 | |
| 1945 | self.assertEqual(items[0].change.number, '1') |
| 1946 | self.assertFalse(items[0].live) |
| 1947 | |
| 1948 | self.assertEqual(items[1].change.number, '2') |
| 1949 | self.assertTrue(items[1].live) |
| 1950 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1951 | self.launch_server.hold_jobs_in_build = False |
| 1952 | self.launch_server.release() |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1953 | self.waitUntilSettled() |
| 1954 | |
| 1955 | self.assertEqual(len(self.history), 4) |
| 1956 | self.assertEqual(self.history[0].result, 'ABORTED', |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1957 | 'Build should have been aborted') |
| 1958 | self.assertEqual(A.reported, 0, "Abandoned change should not report") |
James E. Blair | ba43736 | 2015-02-07 11:41:52 -0800 | [diff] [blame] | 1959 | self.assertEqual(B.reported, 1, "Change should report") |
Antoine Musso | bd86a31 | 2014-01-08 14:51:33 +0100 | [diff] [blame] | 1960 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1961 | @skip("Disabled for early v3 development") |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1962 | def test_abandoned_not_timer(self): |
| 1963 | "Test that an abandoned change does not cancel timer jobs" |
| 1964 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1965 | self.launch_server.hold_jobs_in_build = True |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1966 | |
| 1967 | # Start timer trigger - also org/project |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1968 | self.updateConfigLayout( |
| 1969 | 'tests/fixtures/layout-idle.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1970 | self.sched.reconfigure(self.config) |
| 1971 | self.registerJobs() |
| 1972 | # The pipeline triggers every second, so we should have seen |
| 1973 | # several by now. |
| 1974 | time.sleep(5) |
| 1975 | self.waitUntilSettled() |
| 1976 | # Stop queuing timer triggered jobs so that the assertions |
| 1977 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 1978 | self.updateConfigLayout( |
| 1979 | 'tests/fixtures/layout-no-timer.yaml') |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1980 | self.sched.reconfigure(self.config) |
| 1981 | self.registerJobs() |
| 1982 | self.assertEqual(len(self.builds), 2, "Two timer jobs") |
| 1983 | |
| 1984 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1985 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1986 | self.waitUntilSettled() |
| 1987 | self.assertEqual(len(self.builds), 3, "One change plus two timer jobs") |
| 1988 | |
| 1989 | self.fake_gerrit.addEvent(A.getChangeAbandonedEvent()) |
| 1990 | self.waitUntilSettled() |
| 1991 | |
| 1992 | self.assertEqual(len(self.builds), 2, "Two timer jobs remain") |
| 1993 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 1994 | self.launch_server.release() |
Steve Varnau | 7b78b31 | 2015-04-03 14:49:46 -0700 | [diff] [blame] | 1995 | self.waitUntilSettled() |
| 1996 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 1997 | @skip("Disabled for early v3 development") |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 1998 | def test_zuul_url_return(self): |
| 1999 | "Test if ZUUL_URL is returning when zuul_url is set in zuul.conf" |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame] | 2000 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2001 | self.launch_server.hold_jobs_in_build = True |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2002 | |
| 2003 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2004 | A.addApproval('code-review', 2) |
| 2005 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2006 | self.waitUntilSettled() |
| 2007 | |
| 2008 | self.assertEqual(len(self.builds), 1) |
| 2009 | for build in self.builds: |
| 2010 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 2011 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2012 | self.launch_server.hold_jobs_in_build = False |
| 2013 | self.launch_server.release() |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2014 | self.waitUntilSettled() |
| 2015 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2016 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2017 | def test_new_patchset_dequeues_old_on_head(self): |
| 2018 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2019 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2020 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2021 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2022 | M.setMerged() |
| 2023 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2024 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2025 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2026 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2027 | A.addApproval('code-review', 2) |
| 2028 | B.addApproval('code-review', 2) |
| 2029 | C.addApproval('code-review', 2) |
| 2030 | D.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2031 | |
| 2032 | C.setDependsOn(B, 1) |
| 2033 | B.setDependsOn(A, 1) |
| 2034 | A.setDependsOn(M, 1) |
| 2035 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2036 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2037 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2038 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2039 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2040 | self.waitUntilSettled() |
| 2041 | |
| 2042 | A.addPatchset() |
| 2043 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2044 | self.waitUntilSettled() |
| 2045 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2046 | self.launch_server.hold_jobs_in_build = False |
| 2047 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2048 | self.waitUntilSettled() |
| 2049 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2050 | self.assertEqual(A.data['status'], 'NEW') |
| 2051 | self.assertEqual(A.reported, 2) |
| 2052 | self.assertEqual(B.data['status'], 'NEW') |
| 2053 | self.assertEqual(B.reported, 2) |
| 2054 | self.assertEqual(C.data['status'], 'NEW') |
| 2055 | self.assertEqual(C.reported, 2) |
| 2056 | self.assertEqual(D.data['status'], 'MERGED') |
| 2057 | self.assertEqual(D.reported, 2) |
| 2058 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2059 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2060 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2061 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2062 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2063 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2064 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2065 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2066 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2067 | A.addApproval('code-review', 2) |
| 2068 | B.addApproval('code-review', 2) |
| 2069 | C.addApproval('code-review', 2) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2070 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2071 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2072 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2073 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2074 | self.waitUntilSettled() |
| 2075 | |
| 2076 | B.addPatchset() |
| 2077 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2078 | self.waitUntilSettled() |
| 2079 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2080 | self.launch_server.hold_jobs_in_build = False |
| 2081 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2082 | self.waitUntilSettled() |
| 2083 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2084 | self.assertEqual(A.data['status'], 'MERGED') |
| 2085 | self.assertEqual(A.reported, 2) |
| 2086 | self.assertEqual(B.data['status'], 'NEW') |
| 2087 | self.assertEqual(B.reported, 2) |
| 2088 | self.assertEqual(C.data['status'], 'MERGED') |
| 2089 | self.assertEqual(C.reported, 2) |
| 2090 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2091 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2092 | @skip("Disabled for early v3 development") |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2093 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2094 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2095 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2096 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2097 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2098 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2099 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2100 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2101 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2102 | self.waitUntilSettled() |
| 2103 | |
| 2104 | B.addPatchset() |
| 2105 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2106 | self.waitUntilSettled() |
| 2107 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2108 | self.launch_server.hold_jobs_in_build = False |
| 2109 | self.launch_server.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2110 | self.waitUntilSettled() |
| 2111 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2112 | self.assertEqual(A.data['status'], 'NEW') |
| 2113 | self.assertEqual(A.reported, 1) |
| 2114 | self.assertEqual(B.data['status'], 'NEW') |
| 2115 | self.assertEqual(B.reported, 1) |
| 2116 | self.assertEqual(C.data['status'], 'NEW') |
| 2117 | self.assertEqual(C.reported, 1) |
| 2118 | self.assertEqual(len(self.history), 10) |
| 2119 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2120 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2121 | @skip("Disabled for early v3 development") |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2122 | def test_noop_job(self): |
| 2123 | "Test that the internal noop job works" |
| 2124 | A = self.fake_gerrit.addFakeChange('org/noop-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2125 | A.addApproval('code-review', 2) |
| 2126 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2127 | self.waitUntilSettled() |
| 2128 | |
| 2129 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2130 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2131 | self.assertEqual(len(self.history), 0) |
| 2132 | self.assertEqual(A.data['status'], 'MERGED') |
| 2133 | self.assertEqual(A.reported, 2) |
| 2134 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2135 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | d6e546c | 2015-06-11 15:13:57 +0000 | [diff] [blame] | 2136 | def test_no_job_project(self): |
| 2137 | "Test that reports with no jobs don't get sent" |
| 2138 | A = self.fake_gerrit.addFakeChange('org/no-jobs-project', |
| 2139 | 'master', 'A') |
| 2140 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2141 | self.waitUntilSettled() |
| 2142 | |
| 2143 | # Change wasn't reported to |
| 2144 | self.assertEqual(A.reported, False) |
| 2145 | |
| 2146 | # Check queue is empty afterwards |
| 2147 | check_pipeline = self.sched.layout.pipelines['check'] |
| 2148 | items = check_pipeline.getAllItems() |
| 2149 | self.assertEqual(len(items), 0) |
| 2150 | |
| 2151 | self.assertEqual(len(self.history), 0) |
| 2152 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2153 | @skip("Disabled for early v3 development") |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2154 | def test_zuul_refs(self): |
| 2155 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2156 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2157 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2158 | M1.setMerged() |
| 2159 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2160 | M2.setMerged() |
| 2161 | |
| 2162 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2163 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2164 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2165 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2166 | A.addApproval('code-review', 2) |
| 2167 | B.addApproval('code-review', 2) |
| 2168 | C.addApproval('code-review', 2) |
| 2169 | D.addApproval('code-review', 2) |
| 2170 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2171 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 2172 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
| 2173 | self.fake_gerrit.addEvent(D.addApproval('approved', 1)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2174 | |
| 2175 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2176 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2177 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2178 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2179 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2180 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2181 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2182 | self.launch_server.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2183 | self.waitUntilSettled() |
| 2184 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2185 | a_zref = b_zref = c_zref = d_zref = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2186 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2187 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2188 | a_zref = x.parameters['ZUUL_REF'] |
| 2189 | if x.parameters['ZUUL_CHANGE'] == '4': |
| 2190 | b_zref = x.parameters['ZUUL_REF'] |
| 2191 | if x.parameters['ZUUL_CHANGE'] == '5': |
| 2192 | c_zref = x.parameters['ZUUL_REF'] |
| 2193 | if x.parameters['ZUUL_CHANGE'] == '6': |
| 2194 | d_zref = x.parameters['ZUUL_REF'] |
| 2195 | |
| 2196 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2197 | self.assertIsNotNone(a_zref) |
| 2198 | self.assertIsNotNone(b_zref) |
| 2199 | self.assertIsNotNone(c_zref) |
| 2200 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2201 | |
| 2202 | # And they should all be different |
| 2203 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2204 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2205 | |
| 2206 | # a ref should have a, not b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2207 | self.assertTrue(self.ref_has_change(a_zref, A)) |
| 2208 | self.assertFalse(self.ref_has_change(a_zref, B)) |
| 2209 | self.assertFalse(self.ref_has_change(a_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2210 | |
| 2211 | # b ref should have a and b, and should not be in project2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2212 | self.assertTrue(self.ref_has_change(b_zref, A)) |
| 2213 | self.assertTrue(self.ref_has_change(b_zref, B)) |
| 2214 | self.assertFalse(self.ref_has_change(b_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2215 | |
| 2216 | # c ref should have a and b in 1, c in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2217 | self.assertTrue(self.ref_has_change(c_zref, A)) |
| 2218 | self.assertTrue(self.ref_has_change(c_zref, B)) |
| 2219 | self.assertTrue(self.ref_has_change(c_zref, C)) |
| 2220 | self.assertFalse(self.ref_has_change(c_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2221 | |
| 2222 | # d ref should have a and b in 1, c and d in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2223 | self.assertTrue(self.ref_has_change(d_zref, A)) |
| 2224 | self.assertTrue(self.ref_has_change(d_zref, B)) |
| 2225 | self.assertTrue(self.ref_has_change(d_zref, C)) |
| 2226 | self.assertTrue(self.ref_has_change(d_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2227 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2228 | self.launch_server.hold_jobs_in_build = False |
| 2229 | self.launch_server.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2230 | self.waitUntilSettled() |
| 2231 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2232 | self.assertEqual(A.data['status'], 'MERGED') |
| 2233 | self.assertEqual(A.reported, 2) |
| 2234 | self.assertEqual(B.data['status'], 'MERGED') |
| 2235 | self.assertEqual(B.reported, 2) |
| 2236 | self.assertEqual(C.data['status'], 'MERGED') |
| 2237 | self.assertEqual(C.reported, 2) |
| 2238 | self.assertEqual(D.data['status'], 'MERGED') |
| 2239 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2240 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2241 | @skip("Disabled for early v3 development") |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2242 | def test_rerun_on_error(self): |
| 2243 | "Test that if a worker fails to run a job, it is run again" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2244 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2245 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2246 | A.addApproval('code-review', 2) |
| 2247 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2248 | self.waitUntilSettled() |
| 2249 | |
| 2250 | self.builds[0].run_error = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2251 | self.launch_server.hold_jobs_in_build = False |
| 2252 | self.launch_server.release() |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2253 | self.waitUntilSettled() |
| 2254 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2255 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2256 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2257 | @skip("Disabled for early v3 development") |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2258 | def test_statsd(self): |
| 2259 | "Test each of the statsd methods used in the scheduler" |
| 2260 | import extras |
| 2261 | statsd = extras.try_import('statsd.statsd') |
| 2262 | statsd.incr('test-incr') |
| 2263 | statsd.timing('test-timing', 3) |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2264 | statsd.gauge('test-gauge', 12) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2265 | self.assertReportedStat('test-incr', '1|c') |
| 2266 | self.assertReportedStat('test-timing', '3|ms') |
Alex Gaynor | 813d39b | 2014-05-17 16:17:16 -0700 | [diff] [blame] | 2267 | self.assertReportedStat('test-gauge', '12|g') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2268 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2269 | @skip("Disabled for early v3 development") |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2270 | def test_stuck_job_cleanup(self): |
| 2271 | "Test that pending jobs are cleaned up if removed from layout" |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2272 | # This job won't be registered at startup because it is not in |
| 2273 | # the standard layout, but we need it to already be registerd |
| 2274 | # for when we reconfigure, as that is when Zuul will attempt |
| 2275 | # to run the new job. |
| 2276 | self.worker.registerFunction('build:gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2277 | self.gearman_server.hold_jobs_in_queue = True |
| 2278 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2279 | A.addApproval('code-review', 2) |
| 2280 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2281 | self.waitUntilSettled() |
| 2282 | self.assertEqual(len(self.gearman_server.getQueue()), 1) |
| 2283 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2284 | self.updateConfigLayout( |
| 2285 | 'tests/fixtures/layout-no-jobs.yaml') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2286 | self.sched.reconfigure(self.config) |
| 2287 | self.waitUntilSettled() |
| 2288 | |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2289 | self.gearman_server.release('gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2290 | self.waitUntilSettled() |
| 2291 | self.assertEqual(len(self.gearman_server.getQueue()), 0) |
| 2292 | self.assertTrue(self.sched._areAllBuildsComplete()) |
| 2293 | |
| 2294 | self.assertEqual(len(self.history), 1) |
James E. Blair | 18c6444 | 2014-03-18 10:14:45 -0700 | [diff] [blame] | 2295 | self.assertEqual(self.history[0].name, 'gate-noop') |
James E. Blair | dad5225 | 2014-02-07 16:59:17 -0800 | [diff] [blame] | 2296 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2297 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2298 | @skip("Disabled for early v3 development") |
James E. Blair | 879dafb | 2015-07-17 14:04:49 -0700 | [diff] [blame] | 2299 | def test_file_head(self): |
| 2300 | # This is a regression test for an observed bug. A change |
| 2301 | # with a file named "HEAD" in the root directory of the repo |
| 2302 | # was processed by a merger. It then was unable to reset the |
| 2303 | # repo because of: |
| 2304 | # GitCommandError: 'git reset --hard HEAD' returned |
| 2305 | # with exit code 128 |
| 2306 | # stderr: 'fatal: ambiguous argument 'HEAD': both revision |
| 2307 | # and filename |
| 2308 | # Use '--' to separate filenames from revisions' |
| 2309 | |
| 2310 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2311 | A.addPatchset(['HEAD']) |
| 2312 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2313 | |
| 2314 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2315 | self.waitUntilSettled() |
| 2316 | |
| 2317 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2318 | self.waitUntilSettled() |
| 2319 | |
| 2320 | self.assertIn('Build succeeded', A.messages[0]) |
| 2321 | self.assertIn('Build succeeded', B.messages[0]) |
| 2322 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2323 | @skip("Disabled for early v3 development") |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2324 | def test_file_jobs(self): |
| 2325 | "Test that file jobs run only when appropriate" |
| 2326 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2327 | A.addPatchset(['pip-requires']) |
| 2328 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2329 | A.addApproval('code-review', 2) |
| 2330 | B.addApproval('code-review', 2) |
| 2331 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2332 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2333 | self.waitUntilSettled() |
| 2334 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2335 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2336 | if x.name == 'project-testfile'] |
| 2337 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2338 | self.assertEqual(len(testfile_jobs), 1) |
| 2339 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2340 | self.assertEqual(A.data['status'], 'MERGED') |
| 2341 | self.assertEqual(A.reported, 2) |
| 2342 | self.assertEqual(B.data['status'], 'MERGED') |
| 2343 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2344 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2345 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2346 | def _test_skip_if_jobs(self, branch, should_skip): |
| 2347 | "Test that jobs with a skip-if filter run only when appropriate" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2348 | self.updateConfigLayout( |
| 2349 | 'tests/fixtures/layout-skip-if.yaml') |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2350 | self.sched.reconfigure(self.config) |
| 2351 | self.registerJobs() |
| 2352 | |
| 2353 | change = self.fake_gerrit.addFakeChange('org/project', |
| 2354 | branch, |
| 2355 | 'test skip-if') |
| 2356 | self.fake_gerrit.addEvent(change.getPatchsetCreatedEvent(1)) |
| 2357 | self.waitUntilSettled() |
| 2358 | |
| 2359 | tested_change_ids = [x.changes[0] for x in self.history |
| 2360 | if x.name == 'project-test-skip-if'] |
| 2361 | |
| 2362 | if should_skip: |
| 2363 | self.assertEqual([], tested_change_ids) |
| 2364 | else: |
| 2365 | self.assertIn(change.data['number'], tested_change_ids) |
| 2366 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2367 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2368 | def test_skip_if_match_skips_job(self): |
| 2369 | self._test_skip_if_jobs(branch='master', should_skip=True) |
| 2370 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2371 | @skip("Disabled for early v3 development") |
Maru Newby | 3fe5f85 | 2015-01-13 04:22:14 +0000 | [diff] [blame] | 2372 | def test_skip_if_no_match_runs_job(self): |
| 2373 | self._test_skip_if_jobs(branch='mp', should_skip=False) |
| 2374 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2375 | @skip("Disabled for early v3 development") |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2376 | def test_test_config(self): |
| 2377 | "Test that we can test the config" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2378 | self.sched.testConfig(self.config.get('zuul', 'tenant_config'), |
Joshua Hesketh | 352264b | 2015-08-11 23:42:08 +1000 | [diff] [blame] | 2379 | self.connections) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2380 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2381 | @skip("Disabled for early v3 development") |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2382 | def test_queue_names(self): |
| 2383 | "Test shared change queue names" |
| 2384 | project1 = self.sched.layout.projects['org/project1'] |
| 2385 | project2 = self.sched.layout.projects['org/project2'] |
| 2386 | q1 = self.sched.layout.pipelines['gate'].getQueue(project1) |
| 2387 | q2 = self.sched.layout.pipelines['gate'].getQueue(project2) |
| 2388 | self.assertEqual(q1.name, 'integration') |
| 2389 | self.assertEqual(q2.name, 'integration') |
| 2390 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2391 | self.updateConfigLayout( |
| 2392 | 'tests/fixtures/layout-bad-queue.yaml') |
James E. Blair | c8a1e05 | 2014-02-25 09:29:26 -0800 | [diff] [blame] | 2393 | with testtools.ExpectedException( |
| 2394 | Exception, "More than one name assigned to change queue"): |
| 2395 | self.sched.reconfigure(self.config) |
| 2396 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2397 | @skip("Disabled for early v3 development") |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2398 | def test_queue_precedence(self): |
| 2399 | "Test that queue precedence works" |
| 2400 | |
| 2401 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2402 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2403 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2404 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2405 | A.addApproval('code-review', 2) |
| 2406 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2407 | |
| 2408 | self.waitUntilSettled() |
| 2409 | self.gearman_server.hold_jobs_in_queue = False |
| 2410 | self.gearman_server.release() |
| 2411 | self.waitUntilSettled() |
| 2412 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2413 | # Run one build at a time to ensure non-race order: |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 2414 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2415 | self.launch_server.hold_jobs_in_build = False |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2416 | self.waitUntilSettled() |
| 2417 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2418 | self.log.debug(self.history) |
| 2419 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2420 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2421 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2422 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2423 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2424 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2425 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2426 | @skip("Disabled for early v3 development") |
Clark Boylan | a5edbe4 | 2014-06-03 16:39:10 -0700 | [diff] [blame] | 2427 | def test_json_status(self): |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2428 | "Test that we can retrieve JSON status info" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2429 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2430 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2431 | A.addApproval('code-review', 2) |
| 2432 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2433 | self.waitUntilSettled() |
| 2434 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2435 | self.launch_server.release('project-merge') |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2436 | self.waitUntilSettled() |
| 2437 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2438 | port = self.webapp.server.socket.getsockname()[1] |
| 2439 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 2440 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 2441 | f = urllib.request.urlopen(req) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2442 | headers = f.info() |
| 2443 | self.assertIn('Content-Length', headers) |
| 2444 | self.assertIn('Content-Type', headers) |
Sachi King | dc963fc | 2016-03-23 16:00:33 +1100 | [diff] [blame] | 2445 | self.assertIsNotNone(re.match('^application/json(; charset=UTF-8)?$', |
| 2446 | headers['Content-Type'])) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2447 | self.assertIn('Access-Control-Allow-Origin', headers) |
| 2448 | self.assertIn('Cache-Control', headers) |
Clark Boylan | aa4f2e7 | 2014-06-03 21:22:40 -0700 | [diff] [blame] | 2449 | self.assertIn('Last-Modified', headers) |
Timo Tijhof | 0ebd293 | 2015-04-02 12:11:21 +0100 | [diff] [blame] | 2450 | self.assertIn('Expires', headers) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2451 | data = f.read() |
| 2452 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2453 | self.launch_server.hold_jobs_in_build = False |
| 2454 | self.launch_server.release() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2455 | self.waitUntilSettled() |
| 2456 | |
| 2457 | data = json.loads(data) |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2458 | status_jobs = [] |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2459 | for p in data['pipelines']: |
| 2460 | for q in p['change_queues']: |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 2461 | if p['name'] in ['gate', 'conflict']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2462 | self.assertEqual(q['window'], 20) |
| 2463 | else: |
| 2464 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2465 | for head in q['heads']: |
| 2466 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2467 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2468 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2469 | for job in change['jobs']: |
James E. Blair | b7273ef | 2016-04-19 08:58:51 -0700 | [diff] [blame] | 2470 | status_jobs.append(job) |
| 2471 | self.assertEqual('project-merge', status_jobs[0]['name']) |
| 2472 | self.assertEqual('https://server/job/project-merge/0/', |
| 2473 | status_jobs[0]['url']) |
| 2474 | self.assertEqual('http://logs.example.com/1/1/gate/project-merge/0', |
| 2475 | status_jobs[0]['report_url']) |
| 2476 | |
| 2477 | self.assertEqual('project-test1', status_jobs[1]['name']) |
| 2478 | self.assertEqual('https://server/job/project-test1/1/', |
| 2479 | status_jobs[1]['url']) |
| 2480 | self.assertEqual('http://logs.example.com/1/1/gate/project-test1/1', |
| 2481 | status_jobs[1]['report_url']) |
| 2482 | |
| 2483 | self.assertEqual('project-test2', status_jobs[2]['name']) |
| 2484 | self.assertEqual('https://server/job/project-test2/2/', |
| 2485 | status_jobs[2]['url']) |
| 2486 | self.assertEqual('http://logs.example.com/1/1/gate/project-test2/2', |
| 2487 | status_jobs[2]['report_url']) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2488 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2489 | @skip("Disabled for early v3 development") |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2490 | def test_merging_queues(self): |
| 2491 | "Test that transitively-connected change queues are merged" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2492 | self.updateConfigLayout( |
| 2493 | 'tests/fixtures/layout-merge-queues.yaml') |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2494 | self.sched.reconfigure(self.config) |
| 2495 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2496 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2497 | @skip("Disabled for early v3 development") |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2498 | def test_mutex(self): |
| 2499 | "Test job mutexes" |
| 2500 | self.config.set('zuul', 'layout_config', |
| 2501 | 'tests/fixtures/layout-mutex.yaml') |
| 2502 | self.sched.reconfigure(self.config) |
| 2503 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2504 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2505 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2506 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2507 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2508 | |
| 2509 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2510 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2511 | self.waitUntilSettled() |
| 2512 | self.assertEqual(len(self.builds), 3) |
| 2513 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2514 | self.assertEqual(self.builds[1].name, 'mutex-one') |
| 2515 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 2516 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2517 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2518 | self.waitUntilSettled() |
| 2519 | |
| 2520 | self.assertEqual(len(self.builds), 3) |
| 2521 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2522 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2523 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2524 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2525 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2526 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2527 | self.waitUntilSettled() |
| 2528 | |
| 2529 | self.assertEqual(len(self.builds), 3) |
| 2530 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2531 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2532 | self.assertEqual(self.builds[2].name, 'mutex-one') |
| 2533 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2534 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2535 | self.launch_server.release('mutex-one') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2536 | self.waitUntilSettled() |
| 2537 | |
| 2538 | self.assertEqual(len(self.builds), 3) |
| 2539 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2540 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2541 | self.assertEqual(self.builds[2].name, 'mutex-two') |
| 2542 | self.assertTrue('test-mutex' in self.sched.mutex.mutexes) |
| 2543 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2544 | self.launch_server.release('mutex-two') |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2545 | self.waitUntilSettled() |
| 2546 | |
| 2547 | self.assertEqual(len(self.builds), 2) |
| 2548 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 2549 | self.assertEqual(self.builds[1].name, 'project-test1') |
| 2550 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2551 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2552 | self.launch_server.hold_jobs_in_build = False |
| 2553 | self.launch_server.release() |
James E. Blair | af17a97 | 2016-02-03 15:07:18 -0800 | [diff] [blame] | 2554 | |
| 2555 | self.waitUntilSettled() |
| 2556 | self.assertEqual(len(self.builds), 0) |
| 2557 | |
| 2558 | self.assertEqual(A.reported, 1) |
| 2559 | self.assertEqual(B.reported, 1) |
| 2560 | self.assertFalse('test-mutex' in self.sched.mutex.mutexes) |
| 2561 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2562 | @skip("Disabled for early v3 development") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2563 | def test_node_label(self): |
| 2564 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2565 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2566 | |
| 2567 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2568 | A.addApproval('code-review', 2) |
| 2569 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2570 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2571 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2572 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2573 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2574 | 'debian') |
| 2575 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2576 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2577 | @skip("Disabled for early v3 development") |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2578 | def test_live_reconfiguration(self): |
| 2579 | "Test that live reconfiguration works" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2580 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2581 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2582 | A.addApproval('code-review', 2) |
| 2583 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2584 | self.waitUntilSettled() |
| 2585 | |
| 2586 | self.sched.reconfigure(self.config) |
| 2587 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2588 | self.launch_server.hold_jobs_in_build = False |
| 2589 | self.launch_server.release() |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2590 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2591 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2592 | 'SUCCESS') |
| 2593 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2594 | 'SUCCESS') |
| 2595 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2596 | 'SUCCESS') |
| 2597 | self.assertEqual(A.data['status'], 'MERGED') |
| 2598 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2599 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2600 | @skip("Disabled for early v3 development") |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2601 | def test_live_reconfiguration_merge_conflict(self): |
| 2602 | # A real-world bug: a change in a gate queue has a merge |
| 2603 | # conflict and a job is added to its project while it's |
| 2604 | # sitting in the queue. The job gets added to the change and |
| 2605 | # enqueued and the change gets stuck. |
| 2606 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2607 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2608 | |
| 2609 | # This change is fine. It's here to stop the queue long |
| 2610 | # enough for the next change to be subject to the |
| 2611 | # reconfiguration, as well as to provide a conflict for the |
| 2612 | # next change. This change will succeed and merge. |
| 2613 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2614 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2615 | A.addApproval('code-review', 2) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2616 | |
| 2617 | # This change will be in merge conflict. During the |
| 2618 | # reconfiguration, we will add a job. We want to make sure |
| 2619 | # that doesn't cause it to get stuck. |
| 2620 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2621 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2622 | B.addApproval('code-review', 2) |
James E. Blair | 4eb21fa | 2015-07-27 14:56:47 -0700 | [diff] [blame] | 2623 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2624 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 2625 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2626 | |
| 2627 | self.waitUntilSettled() |
| 2628 | |
| 2629 | # No jobs have run yet |
| 2630 | self.assertEqual(A.data['status'], 'NEW') |
| 2631 | self.assertEqual(A.reported, 1) |
| 2632 | self.assertEqual(B.data['status'], 'NEW') |
| 2633 | self.assertEqual(B.reported, 1) |
| 2634 | self.assertEqual(len(self.history), 0) |
| 2635 | |
| 2636 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2637 | self.updateConfigLayout( |
| 2638 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2639 | self.sched.reconfigure(self.config) |
| 2640 | self.waitUntilSettled() |
| 2641 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2642 | self.launch_server.hold_jobs_in_build = False |
| 2643 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2644 | self.waitUntilSettled() |
| 2645 | |
| 2646 | self.assertEqual(A.data['status'], 'MERGED') |
| 2647 | self.assertEqual(A.reported, 2) |
| 2648 | self.assertEqual(B.data['status'], 'NEW') |
| 2649 | self.assertEqual(B.reported, 2) |
| 2650 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2651 | 'SUCCESS') |
| 2652 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2653 | 'SUCCESS') |
| 2654 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2655 | 'SUCCESS') |
| 2656 | self.assertEqual(self.getJobFromHistory('project-test3').result, |
| 2657 | 'SUCCESS') |
| 2658 | self.assertEqual(len(self.history), 4) |
| 2659 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2660 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2661 | def test_live_reconfiguration_failed_root(self): |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2662 | # An extrapolation of test_live_reconfiguration_merge_conflict |
| 2663 | # that tests a job added to a job tree with a failed root does |
| 2664 | # not run. |
| 2665 | self.worker.registerFunction('build:project-test3') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2666 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2667 | |
| 2668 | # This change is fine. It's here to stop the queue long |
| 2669 | # enough for the next change to be subject to the |
| 2670 | # reconfiguration. This change will succeed and merge. |
| 2671 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2672 | A.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2673 | A.addApproval('code-review', 2) |
| 2674 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2675 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2676 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2677 | self.waitUntilSettled() |
| 2678 | |
| 2679 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2680 | self.launch_server.failJob('project-merge', B) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2681 | B.addApproval('code-review', 2) |
| 2682 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2683 | self.waitUntilSettled() |
| 2684 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2685 | self.launch_server.release('.*-merge') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2686 | self.waitUntilSettled() |
| 2687 | |
| 2688 | # Both -merge jobs have run, but no others. |
| 2689 | self.assertEqual(A.data['status'], 'NEW') |
| 2690 | self.assertEqual(A.reported, 1) |
| 2691 | self.assertEqual(B.data['status'], 'NEW') |
| 2692 | self.assertEqual(B.reported, 1) |
| 2693 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2694 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2695 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2696 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2697 | self.assertEqual(len(self.history), 2) |
| 2698 | |
| 2699 | # Add the "project-test3" job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2700 | self.updateConfigLayout( |
| 2701 | 'tests/fixtures/layout-live-reconfiguration-add-job.yaml') |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2702 | self.sched.reconfigure(self.config) |
| 2703 | self.waitUntilSettled() |
| 2704 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2705 | self.launch_server.hold_jobs_in_build = False |
| 2706 | self.launch_server.release() |
James E. Blair | 6bc782d | 2015-07-17 16:20:21 -0700 | [diff] [blame] | 2707 | self.waitUntilSettled() |
| 2708 | |
| 2709 | self.assertEqual(A.data['status'], 'MERGED') |
| 2710 | self.assertEqual(A.reported, 2) |
| 2711 | self.assertEqual(B.data['status'], 'NEW') |
| 2712 | self.assertEqual(B.reported, 2) |
| 2713 | self.assertEqual(self.history[0].result, 'SUCCESS') |
| 2714 | self.assertEqual(self.history[0].name, 'project-merge') |
| 2715 | self.assertEqual(self.history[1].result, 'FAILURE') |
| 2716 | self.assertEqual(self.history[1].name, 'project-merge') |
| 2717 | self.assertEqual(self.history[2].result, 'SUCCESS') |
| 2718 | self.assertEqual(self.history[3].result, 'SUCCESS') |
| 2719 | self.assertEqual(self.history[4].result, 'SUCCESS') |
| 2720 | self.assertEqual(len(self.history), 5) |
| 2721 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2722 | @skip("Disabled for early v3 development") |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2723 | def test_live_reconfiguration_failed_job(self): |
| 2724 | # Test that a change with a removed failing job does not |
| 2725 | # disrupt reconfiguration. If a change has a failed job and |
| 2726 | # that job is removed during a reconfiguration, we observed a |
| 2727 | # bug where the code to re-set build statuses would run on |
| 2728 | # that build and raise an exception because the job no longer |
| 2729 | # existed. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2730 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2731 | |
| 2732 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2733 | |
| 2734 | # This change will fail and later be removed by the reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2735 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2736 | |
| 2737 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2738 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2739 | self.launch_server.release('.*-merge') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2740 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2741 | self.launch_server.release('project-test1') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2742 | self.waitUntilSettled() |
| 2743 | |
| 2744 | self.assertEqual(A.data['status'], 'NEW') |
| 2745 | self.assertEqual(A.reported, 0) |
| 2746 | |
| 2747 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2748 | 'SUCCESS') |
| 2749 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2750 | 'FAILURE') |
| 2751 | self.assertEqual(len(self.history), 2) |
| 2752 | |
| 2753 | # Remove the test1 job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2754 | self.updateConfigLayout( |
| 2755 | 'tests/fixtures/layout-live-reconfiguration-failed-job.yaml') |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2756 | self.sched.reconfigure(self.config) |
| 2757 | self.waitUntilSettled() |
| 2758 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2759 | self.launch_server.hold_jobs_in_build = False |
| 2760 | self.launch_server.release() |
James E. Blair | 400e8fd | 2015-07-30 17:44:45 -0700 | [diff] [blame] | 2761 | self.waitUntilSettled() |
| 2762 | |
| 2763 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2764 | 'SUCCESS') |
| 2765 | self.assertEqual(self.getJobFromHistory('project-testfile').result, |
| 2766 | 'SUCCESS') |
| 2767 | self.assertEqual(len(self.history), 4) |
| 2768 | |
| 2769 | self.assertEqual(A.data['status'], 'NEW') |
| 2770 | self.assertEqual(A.reported, 1) |
| 2771 | self.assertIn('Build succeeded', A.messages[0]) |
| 2772 | # Ensure the removed job was not included in the report. |
| 2773 | self.assertNotIn('project-test1', A.messages[0]) |
| 2774 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2775 | @skip("Disabled for early v3 development") |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2776 | def test_live_reconfiguration_shared_queue(self): |
| 2777 | # Test that a change with a failing job which was removed from |
| 2778 | # this project but otherwise still exists in the system does |
| 2779 | # not disrupt reconfiguration. |
| 2780 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2781 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2782 | |
| 2783 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2784 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2785 | self.launch_server.failJob('project1-project2-integration', A) |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2786 | |
| 2787 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2788 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2789 | self.launch_server.release('.*-merge') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2790 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2791 | self.launch_server.release('project1-project2-integration') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2792 | self.waitUntilSettled() |
| 2793 | |
| 2794 | self.assertEqual(A.data['status'], 'NEW') |
| 2795 | self.assertEqual(A.reported, 0) |
| 2796 | |
| 2797 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2798 | 'SUCCESS') |
| 2799 | self.assertEqual(self.getJobFromHistory( |
| 2800 | 'project1-project2-integration').result, 'FAILURE') |
| 2801 | self.assertEqual(len(self.history), 2) |
| 2802 | |
| 2803 | # Remove the integration job. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2804 | self.updateConfigLayout( |
| 2805 | 'tests/fixtures/layout-live-reconfiguration-shared-queue.yaml') |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2806 | self.sched.reconfigure(self.config) |
| 2807 | self.waitUntilSettled() |
| 2808 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2809 | self.launch_server.hold_jobs_in_build = False |
| 2810 | self.launch_server.release() |
James E. Blair | fe707d1 | 2015-08-05 15:18:15 -0700 | [diff] [blame] | 2811 | self.waitUntilSettled() |
| 2812 | |
| 2813 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2814 | 'SUCCESS') |
| 2815 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2816 | 'SUCCESS') |
| 2817 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2818 | 'SUCCESS') |
| 2819 | self.assertEqual(self.getJobFromHistory( |
| 2820 | 'project1-project2-integration').result, 'FAILURE') |
| 2821 | self.assertEqual(len(self.history), 4) |
| 2822 | |
| 2823 | self.assertEqual(A.data['status'], 'NEW') |
| 2824 | self.assertEqual(A.reported, 1) |
| 2825 | self.assertIn('Build succeeded', A.messages[0]) |
| 2826 | # Ensure the removed job was not included in the report. |
| 2827 | self.assertNotIn('project1-project2-integration', A.messages[0]) |
| 2828 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2829 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2830 | def test_double_live_reconfiguration_shared_queue(self): |
| 2831 | # This was a real-world regression. A change is added to |
| 2832 | # gate; a reconfigure happens, a second change which depends |
| 2833 | # on the first is added, and a second reconfiguration happens. |
| 2834 | # Ensure that both changes merge. |
| 2835 | |
| 2836 | # A failure may indicate incorrect caching or cleaning up of |
| 2837 | # references during a reconfiguration. |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2838 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2839 | |
| 2840 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2841 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2842 | B.setDependsOn(A, 1) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2843 | A.addApproval('code-review', 2) |
| 2844 | B.addApproval('code-review', 2) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2845 | |
| 2846 | # Add the parent change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2847 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2848 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2849 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2850 | self.waitUntilSettled() |
| 2851 | |
| 2852 | # Reconfigure (with only one change in the pipeline). |
| 2853 | self.sched.reconfigure(self.config) |
| 2854 | self.waitUntilSettled() |
| 2855 | |
| 2856 | # Add the child change. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2857 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2858 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2859 | self.launch_server.release('.*-merge') |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2860 | self.waitUntilSettled() |
| 2861 | |
| 2862 | # Reconfigure (with both in the pipeline). |
| 2863 | self.sched.reconfigure(self.config) |
| 2864 | self.waitUntilSettled() |
| 2865 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2866 | self.launch_server.hold_jobs_in_build = False |
| 2867 | self.launch_server.release() |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 2868 | self.waitUntilSettled() |
| 2869 | |
| 2870 | self.assertEqual(len(self.history), 8) |
| 2871 | |
| 2872 | self.assertEqual(A.data['status'], 'MERGED') |
| 2873 | self.assertEqual(A.reported, 2) |
| 2874 | self.assertEqual(B.data['status'], 'MERGED') |
| 2875 | self.assertEqual(B.reported, 2) |
| 2876 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2877 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2878 | def test_live_reconfiguration_del_project(self): |
| 2879 | # Test project deletion from layout |
| 2880 | # while changes are enqueued |
| 2881 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2882 | self.launch_server.hold_jobs_in_build = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2883 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2884 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2885 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2886 | |
| 2887 | # A Depends-On: B |
| 2888 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 2889 | A.subject, B.data['id']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2890 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2891 | |
| 2892 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2893 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2894 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2895 | self.launch_server.release('.*-merge') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2896 | self.waitUntilSettled() |
| 2897 | self.assertEqual(len(self.builds), 5) |
| 2898 | |
| 2899 | # This layout defines only org/project, not org/project1 |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2900 | self.updateConfigLayout( |
| 2901 | 'tests/fixtures/layout-live-reconfiguration-del-project.yaml') |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2902 | self.sched.reconfigure(self.config) |
| 2903 | self.waitUntilSettled() |
| 2904 | |
| 2905 | # Builds for C aborted, builds for A succeed, |
| 2906 | # and have change B applied ahead |
| 2907 | job_c = self.getJobFromHistory('project1-test1') |
| 2908 | self.assertEqual(job_c.changes, '3,1') |
| 2909 | self.assertEqual(job_c.result, 'ABORTED') |
| 2910 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 2911 | self.launch_server.hold_jobs_in_build = False |
| 2912 | self.launch_server.release() |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 2913 | self.waitUntilSettled() |
| 2914 | |
| 2915 | self.assertEqual(self.getJobFromHistory('project-test1').changes, |
| 2916 | '2,1 1,1') |
| 2917 | |
| 2918 | self.assertEqual(A.data['status'], 'NEW') |
| 2919 | self.assertEqual(B.data['status'], 'NEW') |
| 2920 | self.assertEqual(C.data['status'], 'NEW') |
| 2921 | self.assertEqual(A.reported, 1) |
| 2922 | self.assertEqual(B.reported, 0) |
| 2923 | self.assertEqual(C.reported, 0) |
| 2924 | |
| 2925 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 2926 | self.assertIn('Build succeeded', A.messages[0]) |
| 2927 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2928 | @skip("Disabled for early v3 development") |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2929 | def test_live_reconfiguration_functions(self): |
| 2930 | "Test live reconfiguration with a custom function" |
| 2931 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2932 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2933 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2934 | A.addApproval('code-review', 2) |
| 2935 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2936 | self.waitUntilSettled() |
| 2937 | |
| 2938 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2939 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2940 | 'debian') |
| 2941 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2942 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2943 | self.updateConfigLayout( |
| 2944 | 'tests/fixtures/layout-live-reconfiguration-functions.yaml') |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2945 | self.sched.reconfigure(self.config) |
| 2946 | self.worker.build_history = [] |
| 2947 | |
| 2948 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2949 | B.addApproval('code-review', 2) |
| 2950 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2951 | self.waitUntilSettled() |
| 2952 | |
| 2953 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2954 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2955 | 'wheezy') |
| 2956 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2957 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2958 | @skip("Disabled for early v3 development") |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2959 | def test_delayed_repo_init(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2960 | self.updateConfigLayout( |
| 2961 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2962 | self.sched.reconfigure(self.config) |
| 2963 | |
| 2964 | self.init_repo("org/new-project") |
| 2965 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 2966 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2967 | A.addApproval('code-review', 2) |
| 2968 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2969 | self.waitUntilSettled() |
| 2970 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2971 | 'SUCCESS') |
| 2972 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2973 | 'SUCCESS') |
| 2974 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2975 | 'SUCCESS') |
| 2976 | self.assertEqual(A.data['status'], 'MERGED') |
| 2977 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2978 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 2979 | @skip("Disabled for early v3 development") |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2980 | def test_repo_deleted(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 2981 | self.updateConfigLayout( |
| 2982 | 'tests/fixtures/layout-repo-deleted.yaml') |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2983 | self.sched.reconfigure(self.config) |
| 2984 | |
| 2985 | self.init_repo("org/delete-project") |
| 2986 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 2987 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 2988 | A.addApproval('code-review', 2) |
| 2989 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 2990 | self.waitUntilSettled() |
| 2991 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2992 | 'SUCCESS') |
| 2993 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2994 | 'SUCCESS') |
| 2995 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2996 | 'SUCCESS') |
| 2997 | self.assertEqual(A.data['status'], 'MERGED') |
| 2998 | self.assertEqual(A.reported, 2) |
| 2999 | |
| 3000 | # Delete org/new-project zuul repo. Should be recloned. |
| 3001 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 3002 | |
| 3003 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3004 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3005 | B.addApproval('code-review', 2) |
| 3006 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3007 | self.waitUntilSettled() |
| 3008 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3009 | 'SUCCESS') |
| 3010 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3011 | 'SUCCESS') |
| 3012 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3013 | 'SUCCESS') |
| 3014 | self.assertEqual(B.data['status'], 'MERGED') |
| 3015 | self.assertEqual(B.reported, 2) |
| 3016 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3017 | @skip("Disabled for early v3 development") |
James E. Blair | 456f2fb | 2016-02-09 09:29:33 -0800 | [diff] [blame] | 3018 | def test_tags(self): |
| 3019 | "Test job tags" |
| 3020 | self.config.set('zuul', 'layout_config', |
| 3021 | 'tests/fixtures/layout-tags.yaml') |
| 3022 | self.sched.reconfigure(self.config) |
| 3023 | |
| 3024 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3025 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3026 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3027 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 3028 | self.waitUntilSettled() |
| 3029 | |
| 3030 | results = {'project1-merge': 'extratag merge project1', |
| 3031 | 'project2-merge': 'merge'} |
| 3032 | |
| 3033 | for build in self.history: |
| 3034 | self.assertEqual(results.get(build.name, ''), |
| 3035 | build.parameters.get('BUILD_TAGS')) |
| 3036 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3037 | @skip("Disabled for early v3 development") |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3038 | def test_timer(self): |
| 3039 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3040 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3041 | self.updateConfigLayout( |
| 3042 | 'tests/fixtures/layout-timer.yaml') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3043 | self.sched.reconfigure(self.config) |
| 3044 | self.registerJobs() |
| 3045 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3046 | # The pipeline triggers every second, so we should have seen |
| 3047 | # several by now. |
| 3048 | time.sleep(5) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3049 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3050 | |
| 3051 | self.assertEqual(len(self.builds), 2) |
| 3052 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3053 | port = self.webapp.server.socket.getsockname()[1] |
| 3054 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 3055 | req = urllib.request.Request("http://localhost:%s/status.json" % port) |
| 3056 | f = urllib.request.urlopen(req) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3057 | data = f.read() |
| 3058 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3059 | self.launch_server.hold_jobs_in_build = False |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3060 | # Stop queuing timer triggered jobs so that the assertions |
| 3061 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3062 | self.updateConfigLayout( |
| 3063 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3064 | self.sched.reconfigure(self.config) |
| 3065 | self.registerJobs() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3066 | self.launch_server.release() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3067 | self.waitUntilSettled() |
| 3068 | |
| 3069 | self.assertEqual(self.getJobFromHistory( |
| 3070 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3071 | self.assertEqual(self.getJobFromHistory( |
| 3072 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3073 | |
| 3074 | data = json.loads(data) |
| 3075 | status_jobs = set() |
| 3076 | for p in data['pipelines']: |
| 3077 | for q in p['change_queues']: |
| 3078 | for head in q['heads']: |
| 3079 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 3080 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3081 | for job in change['jobs']: |
| 3082 | status_jobs.add(job['name']) |
| 3083 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 3084 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3085 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3086 | @skip("Disabled for early v3 development") |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3087 | def test_idle(self): |
| 3088 | "Test that frequent periodic jobs work" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3089 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3090 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3091 | for x in range(1, 3): |
| 3092 | # Test that timer triggers periodic jobs even across |
| 3093 | # layout config reloads. |
| 3094 | # Start timer trigger |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3095 | self.updateConfigLayout( |
| 3096 | 'tests/fixtures/layout-idle.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3097 | self.sched.reconfigure(self.config) |
| 3098 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3099 | self.waitUntilSettled() |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3100 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3101 | # The pipeline triggers every second, so we should have seen |
| 3102 | # several by now. |
| 3103 | time.sleep(5) |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3104 | |
| 3105 | # Stop queuing timer triggered jobs so that the assertions |
| 3106 | # below don't race against more jobs being queued. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3107 | self.updateConfigLayout( |
| 3108 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3109 | self.sched.reconfigure(self.config) |
| 3110 | self.registerJobs() |
James E. Blair | 995fc0f | 2016-02-04 16:48:31 -0800 | [diff] [blame] | 3111 | self.waitUntilSettled() |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3112 | |
| 3113 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3114 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3115 | self.waitUntilSettled() |
| 3116 | self.assertEqual(len(self.builds), 0) |
| 3117 | self.assertEqual(len(self.history), x * 2) |
James E. Blair | 4f6033c | 2014-03-27 15:49:09 -0700 | [diff] [blame] | 3118 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3119 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3120 | def test_check_smtp_pool(self): |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3121 | self.updateConfigLayout( |
| 3122 | 'tests/fixtures/layout-smtp.yaml') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3123 | self.sched.reconfigure(self.config) |
| 3124 | |
| 3125 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3126 | self.waitUntilSettled() |
| 3127 | |
| 3128 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3129 | self.waitUntilSettled() |
| 3130 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3131 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3132 | |
| 3133 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3134 | # work on the knowledge of what the first message should be as |
| 3135 | # it is only configured to go to SMTP. |
| 3136 | |
| 3137 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3138 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3139 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3140 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3141 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3142 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3143 | |
| 3144 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3145 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3146 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3147 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3148 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3149 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3150 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3151 | @skip("Disabled for early v3 development") |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3152 | def test_timer_smtp(self): |
| 3153 | "Test that a periodic job is triggered" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3154 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3155 | self.updateConfigLayout( |
| 3156 | 'tests/fixtures/layout-timer-smtp.yaml') |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3157 | self.sched.reconfigure(self.config) |
| 3158 | self.registerJobs() |
| 3159 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3160 | # The pipeline triggers every second, so we should have seen |
| 3161 | # several by now. |
| 3162 | time.sleep(5) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3163 | self.waitUntilSettled() |
| 3164 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3165 | self.assertEqual(len(self.builds), 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3166 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3167 | self.waitUntilSettled() |
| 3168 | self.assertEqual(len(self.history), 2) |
| 3169 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3170 | self.assertEqual(self.getJobFromHistory( |
| 3171 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3172 | self.assertEqual(self.getJobFromHistory( |
| 3173 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3174 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3175 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3176 | |
| 3177 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3178 | # work on the knowledge of what the first message should be as |
| 3179 | # it is only configured to go to SMTP. |
| 3180 | |
| 3181 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3182 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3183 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3184 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3185 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3186 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3187 | |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3188 | # Stop queuing timer triggered jobs and let any that may have |
| 3189 | # queued through so that end of test assertions pass. |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3190 | self.updateConfigLayout( |
| 3191 | 'tests/fixtures/layout-no-timer.yaml') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3192 | self.sched.reconfigure(self.config) |
| 3193 | self.registerJobs() |
James E. Blair | f805897 | 2014-08-15 16:09:16 -0700 | [diff] [blame] | 3194 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3195 | self.launch_server.release('.*') |
Clark Boylan | 3ee090a | 2014-04-03 20:55:09 -0700 | [diff] [blame] | 3196 | self.waitUntilSettled() |
| 3197 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3198 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3199 | def test_client_enqueue_change(self): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3200 | "Test that the RPC client can enqueue a change" |
| 3201 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3202 | A.addApproval('code-review', 2) |
| 3203 | A.addApproval('approved', 1) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3204 | |
| 3205 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3206 | self.gearman_server.port) |
| 3207 | r = client.enqueue(pipeline='gate', |
| 3208 | project='org/project', |
| 3209 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3210 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3211 | self.waitUntilSettled() |
| 3212 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3213 | 'SUCCESS') |
| 3214 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3215 | 'SUCCESS') |
| 3216 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3217 | 'SUCCESS') |
| 3218 | self.assertEqual(A.data['status'], 'MERGED') |
| 3219 | self.assertEqual(A.reported, 2) |
| 3220 | self.assertEqual(r, True) |
| 3221 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3222 | @skip("Disabled for early v3 development") |
James E. Blair | 91e3459 | 2015-07-31 16:45:59 -0700 | [diff] [blame] | 3223 | def test_client_enqueue_ref(self): |
| 3224 | "Test that the RPC client can enqueue a ref" |
| 3225 | |
| 3226 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3227 | self.gearman_server.port) |
| 3228 | r = client.enqueue_ref( |
| 3229 | pipeline='post', |
| 3230 | project='org/project', |
| 3231 | trigger='gerrit', |
| 3232 | ref='master', |
| 3233 | oldrev='90f173846e3af9154517b88543ffbd1691f31366', |
| 3234 | newrev='d479a0bfcb34da57a31adb2a595c0cf687812543') |
| 3235 | self.waitUntilSettled() |
| 3236 | job_names = [x.name for x in self.history] |
| 3237 | self.assertEqual(len(self.history), 1) |
| 3238 | self.assertIn('project-post', job_names) |
| 3239 | self.assertEqual(r, True) |
| 3240 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3241 | @skip("Disabled for early v3 development") |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3242 | def test_client_enqueue_negative(self): |
| 3243 | "Test that the RPC client returns errors" |
| 3244 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3245 | self.gearman_server.port) |
| 3246 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3247 | "Invalid project"): |
| 3248 | r = client.enqueue(pipeline='gate', |
| 3249 | project='project-does-not-exist', |
| 3250 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3251 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3252 | client.shutdown() |
| 3253 | self.assertEqual(r, False) |
| 3254 | |
| 3255 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3256 | "Invalid pipeline"): |
| 3257 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 3258 | project='org/project', |
| 3259 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3260 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3261 | client.shutdown() |
| 3262 | self.assertEqual(r, False) |
| 3263 | |
| 3264 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3265 | "Invalid trigger"): |
| 3266 | r = client.enqueue(pipeline='gate', |
| 3267 | project='org/project', |
| 3268 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3269 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3270 | client.shutdown() |
| 3271 | self.assertEqual(r, False) |
| 3272 | |
| 3273 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3274 | "Invalid change"): |
| 3275 | r = client.enqueue(pipeline='gate', |
| 3276 | project='org/project', |
| 3277 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3278 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3279 | client.shutdown() |
| 3280 | self.assertEqual(r, False) |
| 3281 | |
| 3282 | self.waitUntilSettled() |
| 3283 | self.assertEqual(len(self.history), 0) |
| 3284 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3285 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3286 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3287 | def test_client_promote(self): |
| 3288 | "Test that the RPC client can promote a change" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3289 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3290 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3291 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3292 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3293 | A.addApproval('code-review', 2) |
| 3294 | B.addApproval('code-review', 2) |
| 3295 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3296 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3297 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3298 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3299 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3300 | |
| 3301 | self.waitUntilSettled() |
| 3302 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3303 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3304 | enqueue_times = {} |
| 3305 | for item in items: |
| 3306 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3307 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3308 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3309 | self.gearman_server.port) |
| 3310 | r = client.promote(pipeline='gate', |
| 3311 | change_ids=['2,1', '3,1']) |
| 3312 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3313 | # ensure that enqueue times are durable |
| 3314 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3315 | for item in items: |
| 3316 | self.assertEqual( |
| 3317 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3318 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3319 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3320 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3321 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3322 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3323 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3324 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3325 | self.waitUntilSettled() |
| 3326 | |
| 3327 | self.assertEqual(len(self.builds), 6) |
| 3328 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3329 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3330 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3331 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3332 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3333 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3334 | |
| 3335 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3336 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3337 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3338 | |
| 3339 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3340 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3341 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3342 | |
| 3343 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3344 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3345 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3346 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3347 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3348 | self.waitUntilSettled() |
| 3349 | |
| 3350 | self.assertEqual(A.data['status'], 'MERGED') |
| 3351 | self.assertEqual(A.reported, 2) |
| 3352 | self.assertEqual(B.data['status'], 'MERGED') |
| 3353 | self.assertEqual(B.reported, 2) |
| 3354 | self.assertEqual(C.data['status'], 'MERGED') |
| 3355 | self.assertEqual(C.reported, 2) |
| 3356 | |
| 3357 | client.shutdown() |
| 3358 | self.assertEqual(r, True) |
| 3359 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3360 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3361 | def test_client_promote_dependent(self): |
| 3362 | "Test that the RPC client can promote a dependent change" |
| 3363 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3364 | # A -> C (depends on B) -> B |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3365 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3366 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3367 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3368 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3369 | |
| 3370 | C.setDependsOn(B, 1) |
| 3371 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3372 | A.addApproval('code-review', 2) |
| 3373 | B.addApproval('code-review', 2) |
| 3374 | C.addApproval('code-review', 2) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3375 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3376 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3377 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3378 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3379 | |
| 3380 | self.waitUntilSettled() |
| 3381 | |
| 3382 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3383 | self.gearman_server.port) |
| 3384 | r = client.promote(pipeline='gate', |
| 3385 | change_ids=['3,1']) |
| 3386 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3387 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3388 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3389 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3390 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3391 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3392 | self.launch_server.release('.*-merge') |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3393 | self.waitUntilSettled() |
| 3394 | |
| 3395 | self.assertEqual(len(self.builds), 6) |
| 3396 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3397 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3398 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3399 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3400 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3401 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3402 | |
| 3403 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3404 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3405 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3406 | |
| 3407 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3408 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3409 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3410 | |
| 3411 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3412 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3413 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3414 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3415 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3416 | self.waitUntilSettled() |
| 3417 | |
| 3418 | self.assertEqual(A.data['status'], 'MERGED') |
| 3419 | self.assertEqual(A.reported, 2) |
| 3420 | self.assertEqual(B.data['status'], 'MERGED') |
| 3421 | self.assertEqual(B.reported, 2) |
| 3422 | self.assertEqual(C.data['status'], 'MERGED') |
| 3423 | self.assertEqual(C.reported, 2) |
| 3424 | |
| 3425 | client.shutdown() |
| 3426 | self.assertEqual(r, True) |
| 3427 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3428 | @skip("Disabled for early v3 development") |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3429 | def test_client_promote_negative(self): |
| 3430 | "Test that the RPC client returns errors for promotion" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3431 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3432 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3433 | A.addApproval('code-review', 2) |
| 3434 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3435 | self.waitUntilSettled() |
| 3436 | |
| 3437 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3438 | self.gearman_server.port) |
| 3439 | |
| 3440 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3441 | r = client.promote(pipeline='nonexistent', |
| 3442 | change_ids=['2,1', '3,1']) |
| 3443 | client.shutdown() |
| 3444 | self.assertEqual(r, False) |
| 3445 | |
| 3446 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3447 | r = client.promote(pipeline='gate', |
| 3448 | change_ids=['4,1']) |
| 3449 | client.shutdown() |
| 3450 | self.assertEqual(r, False) |
| 3451 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3452 | self.launch_server.hold_jobs_in_build = False |
| 3453 | self.launch_server.release() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3454 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3455 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3456 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3457 | def test_queue_rate_limiting(self): |
| 3458 | "Test that DependentPipelines are rate limited with dep across window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3459 | self.updateConfigLayout( |
| 3460 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3461 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3462 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3463 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3464 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3465 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3466 | |
| 3467 | C.setDependsOn(B, 1) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3468 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3469 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3470 | A.addApproval('code-review', 2) |
| 3471 | B.addApproval('code-review', 2) |
| 3472 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3473 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3474 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3475 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3476 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3477 | self.waitUntilSettled() |
| 3478 | |
| 3479 | # Only A and B will have their merge jobs queued because |
| 3480 | # window is 2. |
| 3481 | self.assertEqual(len(self.builds), 2) |
| 3482 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3483 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3484 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3485 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3486 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3487 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3488 | self.waitUntilSettled() |
| 3489 | |
| 3490 | # Only A and B will have their test jobs queued because |
| 3491 | # window is 2. |
| 3492 | self.assertEqual(len(self.builds), 4) |
| 3493 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3494 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3495 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3496 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3497 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3498 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3499 | self.waitUntilSettled() |
| 3500 | |
| 3501 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3502 | # A failed so window is reduced by 1 to 1. |
| 3503 | self.assertEqual(queue.window, 1) |
| 3504 | self.assertEqual(queue.window_floor, 1) |
| 3505 | self.assertEqual(A.data['status'], 'NEW') |
| 3506 | |
| 3507 | # Gate is reset and only B's merge job is queued because |
| 3508 | # window shrunk to 1. |
| 3509 | self.assertEqual(len(self.builds), 1) |
| 3510 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3511 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3512 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3513 | self.waitUntilSettled() |
| 3514 | |
| 3515 | # Only B's test jobs are queued because window is still 1. |
| 3516 | self.assertEqual(len(self.builds), 2) |
| 3517 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3518 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3519 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3520 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3521 | self.waitUntilSettled() |
| 3522 | |
| 3523 | # B was successfully merged so window is increased to 2. |
| 3524 | self.assertEqual(queue.window, 2) |
| 3525 | self.assertEqual(queue.window_floor, 1) |
| 3526 | self.assertEqual(B.data['status'], 'MERGED') |
| 3527 | |
| 3528 | # Only C is left and its merge job is queued. |
| 3529 | self.assertEqual(len(self.builds), 1) |
| 3530 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3531 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3532 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3533 | self.waitUntilSettled() |
| 3534 | |
| 3535 | # After successful merge job the test jobs for C are queued. |
| 3536 | self.assertEqual(len(self.builds), 2) |
| 3537 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3538 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3539 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3540 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3541 | self.waitUntilSettled() |
| 3542 | |
| 3543 | # C successfully merged so window is bumped to 3. |
| 3544 | self.assertEqual(queue.window, 3) |
| 3545 | self.assertEqual(queue.window_floor, 1) |
| 3546 | self.assertEqual(C.data['status'], 'MERGED') |
| 3547 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3548 | @skip("Disabled for early v3 development") |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3549 | def test_queue_rate_limiting_dependent(self): |
| 3550 | "Test that DependentPipelines are rate limited with dep in window" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3551 | self.updateConfigLayout( |
| 3552 | 'tests/fixtures/layout-rate-limit.yaml') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3553 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3554 | self.launch_server.hold_jobs_in_build = True |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3555 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3556 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3557 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3558 | |
| 3559 | B.setDependsOn(A, 1) |
| 3560 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3561 | self.launch_server.failJob('project-test1', A) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3562 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3563 | A.addApproval('code-review', 2) |
| 3564 | B.addApproval('code-review', 2) |
| 3565 | C.addApproval('code-review', 2) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3566 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3567 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3568 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3569 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3570 | self.waitUntilSettled() |
| 3571 | |
| 3572 | # Only A and B will have their merge jobs queued because |
| 3573 | # window is 2. |
| 3574 | self.assertEqual(len(self.builds), 2) |
| 3575 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3576 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3577 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3578 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3579 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3580 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3581 | self.waitUntilSettled() |
| 3582 | |
| 3583 | # Only A and B will have their test jobs queued because |
| 3584 | # window is 2. |
| 3585 | self.assertEqual(len(self.builds), 4) |
| 3586 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3587 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3588 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3589 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3590 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3591 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3592 | self.waitUntilSettled() |
| 3593 | |
| 3594 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3595 | # A failed so window is reduced by 1 to 1. |
| 3596 | self.assertEqual(queue.window, 1) |
| 3597 | self.assertEqual(queue.window_floor, 1) |
| 3598 | self.assertEqual(A.data['status'], 'NEW') |
| 3599 | self.assertEqual(B.data['status'], 'NEW') |
| 3600 | |
| 3601 | # Gate is reset and only C's merge job is queued because |
| 3602 | # window shrunk to 1 and A and B were dequeued. |
| 3603 | self.assertEqual(len(self.builds), 1) |
| 3604 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3605 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3606 | self.launch_server.release('.*-merge') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3607 | self.waitUntilSettled() |
| 3608 | |
| 3609 | # Only C's test jobs are queued because window is still 1. |
| 3610 | self.assertEqual(len(self.builds), 2) |
| 3611 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3612 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3613 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3614 | self.launch_server.release('project-.*') |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3615 | self.waitUntilSettled() |
| 3616 | |
| 3617 | # C was successfully merged so window is increased to 2. |
| 3618 | self.assertEqual(queue.window, 2) |
| 3619 | self.assertEqual(queue.window_floor, 1) |
| 3620 | self.assertEqual(C.data['status'], 'MERGED') |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3621 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3622 | @skip("Disabled for early v3 development") |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3623 | def test_worker_update_metadata(self): |
| 3624 | "Test if a worker can send back metadata about itself" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3625 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3626 | |
| 3627 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3628 | A.addApproval('code-review', 2) |
| 3629 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3630 | self.waitUntilSettled() |
| 3631 | |
| 3632 | self.assertEqual(len(self.launcher.builds), 1) |
| 3633 | |
| 3634 | self.log.debug('Current builds:') |
| 3635 | self.log.debug(self.launcher.builds) |
| 3636 | |
| 3637 | start = time.time() |
| 3638 | while True: |
| 3639 | if time.time() - start > 10: |
| 3640 | raise Exception("Timeout waiting for gearman server to report " |
| 3641 | + "back to the client") |
| 3642 | build = self.launcher.builds.values()[0] |
| 3643 | if build.worker.name == "My Worker": |
| 3644 | break |
| 3645 | else: |
| 3646 | time.sleep(0) |
| 3647 | |
| 3648 | self.log.debug(build) |
| 3649 | self.assertEqual("My Worker", build.worker.name) |
| 3650 | self.assertEqual("localhost", build.worker.hostname) |
| 3651 | self.assertEqual(['127.0.0.1', '192.168.1.1'], build.worker.ips) |
| 3652 | self.assertEqual("zuul.example.org", build.worker.fqdn) |
| 3653 | self.assertEqual("FakeBuilder", build.worker.program) |
| 3654 | self.assertEqual("v1.1", build.worker.version) |
| 3655 | self.assertEqual({'something': 'else'}, build.worker.extra) |
| 3656 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3657 | self.launch_server.hold_jobs_in_build = False |
| 3658 | self.launch_server.release() |
Joshua Hesketh | ba8776a | 2014-01-12 14:35:40 +0800 | [diff] [blame] | 3659 | self.waitUntilSettled() |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3660 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3661 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3662 | def test_footer_message(self): |
| 3663 | "Test a pipeline's footer message is correctly added to the report." |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3664 | self.updateConfigLayout( |
| 3665 | 'tests/fixtures/layout-footer-message.yaml') |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3666 | self.sched.reconfigure(self.config) |
| 3667 | self.registerJobs() |
| 3668 | |
| 3669 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3670 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3671 | self.launch_server.failJob('test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3672 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3673 | self.waitUntilSettled() |
| 3674 | |
| 3675 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3676 | B.addApproval('code-review', 2) |
| 3677 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Joshua Hesketh | 3979e3e | 2014-03-04 11:21:10 +1100 | [diff] [blame] | 3678 | self.waitUntilSettled() |
| 3679 | |
| 3680 | self.assertEqual(2, len(self.smtp_messages)) |
| 3681 | |
| 3682 | failure_body = """\ |
| 3683 | Build failed. For information on how to proceed, see \ |
| 3684 | http://wiki.example.org/Test_Failures |
| 3685 | |
| 3686 | - test1 http://logs.example.com/1/1/gate/test1/0 : FAILURE in 0s |
| 3687 | - test2 http://logs.example.com/1/1/gate/test2/1 : SUCCESS in 0s |
| 3688 | |
| 3689 | For CI problems and help debugging, contact ci@example.org""" |
| 3690 | |
| 3691 | success_body = """\ |
| 3692 | Build succeeded. |
| 3693 | |
| 3694 | - test1 http://logs.example.com/2/1/gate/test1/2 : SUCCESS in 0s |
| 3695 | - test2 http://logs.example.com/2/1/gate/test2/3 : SUCCESS in 0s |
| 3696 | |
| 3697 | For CI problems and help debugging, contact ci@example.org""" |
| 3698 | |
| 3699 | self.assertEqual(failure_body, self.smtp_messages[0]['body']) |
| 3700 | self.assertEqual(success_body, self.smtp_messages[1]['body']) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3701 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3702 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3703 | def test_merge_failure_reporters(self): |
| 3704 | """Check that the config is set up correctly""" |
| 3705 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3706 | self.updateConfigLayout( |
| 3707 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3708 | self.sched.reconfigure(self.config) |
| 3709 | self.registerJobs() |
| 3710 | |
| 3711 | self.assertEqual( |
Jeremy Stanley | 1c2c3c2 | 2015-06-15 21:23:19 +0000 | [diff] [blame] | 3712 | "Merge Failed.\n\nThis change or one of its cross-repo " |
| 3713 | "dependencies was unable to be automatically merged with the " |
| 3714 | "current state of its repository. Please rebase the change and " |
| 3715 | "upload a new patchset.", |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3716 | self.sched.layout.pipelines['check'].merge_failure_message) |
| 3717 | self.assertEqual( |
| 3718 | "The merge failed! For more information...", |
| 3719 | self.sched.layout.pipelines['gate'].merge_failure_message) |
| 3720 | |
| 3721 | self.assertEqual( |
| 3722 | len(self.sched.layout.pipelines['check'].merge_failure_actions), 1) |
| 3723 | self.assertEqual( |
| 3724 | len(self.sched.layout.pipelines['gate'].merge_failure_actions), 2) |
| 3725 | |
| 3726 | self.assertTrue(isinstance( |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3727 | self.sched.layout.pipelines['check'].merge_failure_actions[0], |
| 3728 | zuul.reporter.gerrit.GerritReporter)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3729 | |
| 3730 | self.assertTrue( |
| 3731 | ( |
| 3732 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3733 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3734 | zuul.reporter.smtp.SMTPReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3735 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3736 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3737 | zuul.reporter.gerrit.GerritReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3738 | ) or ( |
| 3739 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3740 | merge_failure_actions[0], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3741 | zuul.reporter.gerrit.GerritReporter) and |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3742 | isinstance(self.sched.layout.pipelines['gate']. |
Joshua Hesketh | de95865 | 2015-11-10 19:19:50 +1100 | [diff] [blame] | 3743 | merge_failure_actions[1], |
Joshua Hesketh | ffe4206 | 2014-09-05 21:43:52 +1000 | [diff] [blame] | 3744 | zuul.reporter.smtp.SMTPReporter) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3745 | ) |
| 3746 | ) |
| 3747 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3748 | @skip("Disabled for early v3 development") |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3749 | def test_merge_failure_reports(self): |
| 3750 | """Check that when a change fails to merge the correct message is sent |
| 3751 | to the correct reporter""" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3752 | self.updateConfigLayout( |
| 3753 | 'tests/fixtures/layout-merge-failure.yaml') |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3754 | self.sched.reconfigure(self.config) |
| 3755 | self.registerJobs() |
| 3756 | |
| 3757 | # Check a test failure isn't reported to SMTP |
| 3758 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3759 | A.addApproval('code-review', 2) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3760 | self.launch_server.failJob('project-test1', A) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3761 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3762 | self.waitUntilSettled() |
| 3763 | |
| 3764 | self.assertEqual(3, len(self.history)) # 3 jobs |
| 3765 | self.assertEqual(0, len(self.smtp_messages)) |
| 3766 | |
| 3767 | # Check a merge failure is reported to SMTP |
| 3768 | # B should be merged, but C will conflict with B |
| 3769 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3770 | B.addPatchset(['conflict']) |
| 3771 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3772 | C.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3773 | B.addApproval('code-review', 2) |
| 3774 | C.addApproval('code-review', 2) |
| 3775 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
| 3776 | self.fake_gerrit.addEvent(C.addApproval('approved', 1)) |
Joshua Hesketh | b717977 | 2014-01-30 23:30:46 +1100 | [diff] [blame] | 3777 | self.waitUntilSettled() |
| 3778 | |
| 3779 | self.assertEqual(6, len(self.history)) # A and B jobs |
| 3780 | self.assertEqual(1, len(self.smtp_messages)) |
| 3781 | self.assertEqual('The merge failed! For more information...', |
| 3782 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3783 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3784 | @skip("Disabled for early v3 development") |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3785 | def test_default_merge_failure_reports(self): |
| 3786 | """Check that the default merge failure reports are correct.""" |
| 3787 | |
| 3788 | # A should report success, B should report merge failure. |
| 3789 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3790 | A.addPatchset(['conflict']) |
| 3791 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3792 | B.addPatchset(['conflict']) |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3793 | A.addApproval('code-review', 2) |
| 3794 | B.addApproval('code-review', 2) |
| 3795 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
| 3796 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | f760f0e | 2016-02-09 08:44:52 -0800 | [diff] [blame] | 3797 | self.waitUntilSettled() |
| 3798 | |
| 3799 | self.assertEqual(3, len(self.history)) # A jobs |
| 3800 | self.assertEqual(A.reported, 2) |
| 3801 | self.assertEqual(B.reported, 2) |
| 3802 | self.assertEqual(A.data['status'], 'MERGED') |
| 3803 | self.assertEqual(B.data['status'], 'NEW') |
| 3804 | self.assertIn('Build succeeded', A.messages[1]) |
| 3805 | self.assertIn('Merge Failed', B.messages[1]) |
| 3806 | self.assertIn('automatically merged', B.messages[1]) |
| 3807 | self.assertNotIn('logs.example.com', B.messages[1]) |
| 3808 | self.assertNotIn('SKIPPED', B.messages[1]) |
| 3809 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3810 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3811 | def test_swift_instructions(self): |
| 3812 | "Test that the correct swift instructions are sent to the workers" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 3813 | self.updateConfigLayout( |
| 3814 | 'tests/fixtures/layout-swift.yaml') |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3815 | self.sched.reconfigure(self.config) |
| 3816 | self.registerJobs() |
| 3817 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3818 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3819 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3820 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3821 | A.addApproval('code-review', 2) |
| 3822 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3823 | self.waitUntilSettled() |
| 3824 | |
| 3825 | self.assertEqual( |
| 3826 | "https://storage.example.org/V1/AUTH_account/merge_logs/1/1/1/" |
| 3827 | "gate/test-merge/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3828 | self.builds[0].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3829 | self.assertEqual(5, |
| 3830 | len(self.builds[0].parameters['SWIFT_logs_HMAC_BODY']. |
| 3831 | split('\n'))) |
| 3832 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[0].parameters) |
| 3833 | |
| 3834 | self.assertEqual( |
| 3835 | "https://storage.example.org/V1/AUTH_account/logs/1/1/1/" |
| 3836 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3837 | self.builds[1].parameters['SWIFT_logs_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3838 | self.assertEqual(5, |
| 3839 | len(self.builds[1].parameters['SWIFT_logs_HMAC_BODY']. |
| 3840 | split('\n'))) |
| 3841 | self.assertIn('SWIFT_logs_SIGNATURE', self.builds[1].parameters) |
| 3842 | |
| 3843 | self.assertEqual( |
| 3844 | "https://storage.example.org/V1/AUTH_account/stash/1/1/1/" |
| 3845 | "gate/test-test/", |
Joshua Hesketh | 76dee53 | 2014-07-03 15:39:13 +1000 | [diff] [blame] | 3846 | self.builds[1].parameters['SWIFT_MOSTLY_URL'][:-7]) |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3847 | self.assertEqual(5, |
| 3848 | len(self.builds[1]. |
| 3849 | parameters['SWIFT_MOSTLY_HMAC_BODY'].split('\n'))) |
| 3850 | self.assertIn('SWIFT_MOSTLY_SIGNATURE', self.builds[1].parameters) |
| 3851 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3852 | self.launch_server.hold_jobs_in_build = False |
| 3853 | self.launch_server.release() |
Joshua Hesketh | 36c3fa5 | 2014-01-22 11:40:52 +1100 | [diff] [blame] | 3854 | self.waitUntilSettled() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3855 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3856 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3857 | def test_client_get_running_jobs(self): |
| 3858 | "Test that the RPC client can get a list of running jobs" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3859 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3860 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3861 | A.addApproval('code-review', 2) |
| 3862 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3863 | self.waitUntilSettled() |
| 3864 | |
| 3865 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3866 | self.gearman_server.port) |
| 3867 | |
| 3868 | # Wait for gearman server to send the initial workData back to zuul |
| 3869 | start = time.time() |
| 3870 | while True: |
| 3871 | if time.time() - start > 10: |
| 3872 | raise Exception("Timeout waiting for gearman server to report " |
| 3873 | + "back to the client") |
| 3874 | build = self.launcher.builds.values()[0] |
| 3875 | if build.worker.name == "My Worker": |
| 3876 | break |
| 3877 | else: |
| 3878 | time.sleep(0) |
| 3879 | |
| 3880 | running_items = client.get_running_jobs() |
| 3881 | |
| 3882 | self.assertEqual(1, len(running_items)) |
| 3883 | running_item = running_items[0] |
| 3884 | self.assertEqual([], running_item['failing_reasons']) |
| 3885 | self.assertEqual([], running_item['items_behind']) |
| 3886 | self.assertEqual('https://hostname/1', running_item['url']) |
| 3887 | self.assertEqual(None, running_item['item_ahead']) |
| 3888 | self.assertEqual('org/project', running_item['project']) |
| 3889 | self.assertEqual(None, running_item['remaining_time']) |
| 3890 | self.assertEqual(True, running_item['active']) |
| 3891 | self.assertEqual('1,1', running_item['id']) |
| 3892 | |
| 3893 | self.assertEqual(3, len(running_item['jobs'])) |
| 3894 | for job in running_item['jobs']: |
| 3895 | if job['name'] == 'project-merge': |
| 3896 | self.assertEqual('project-merge', job['name']) |
| 3897 | self.assertEqual('gate', job['pipeline']) |
| 3898 | self.assertEqual(False, job['retry']) |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3899 | self.assertEqual('https://server/job/project-merge/0/', |
| 3900 | job['url']) |
| 3901 | self.assertEqual(7, len(job['worker'])) |
| 3902 | self.assertEqual(False, job['canceled']) |
| 3903 | self.assertEqual(True, job['voting']) |
| 3904 | self.assertEqual(None, job['result']) |
| 3905 | self.assertEqual('gate', job['pipeline']) |
| 3906 | break |
| 3907 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3908 | self.launch_server.hold_jobs_in_build = False |
| 3909 | self.launch_server.release() |
Joshua Hesketh | 85af4e9 | 2014-02-21 08:28:58 -0800 | [diff] [blame] | 3910 | self.waitUntilSettled() |
| 3911 | |
| 3912 | running_items = client.get_running_jobs() |
| 3913 | self.assertEqual(0, len(running_items)) |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3914 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3915 | @skip("Disabled for early v3 development") |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3916 | def test_nonvoting_pipeline(self): |
| 3917 | "Test that a nonvoting pipeline (experimental) can still report" |
| 3918 | |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3919 | A = self.fake_gerrit.addFakeChange('org/experimental-project', |
| 3920 | 'master', 'A') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3921 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3922 | self.waitUntilSettled() |
Joshua Hesketh | cc017ea | 2014-04-30 19:55:25 +1000 | [diff] [blame] | 3923 | self.assertEqual( |
| 3924 | self.getJobFromHistory('experimental-project-test').result, |
| 3925 | 'SUCCESS') |
James E. Blair | badc1ad | 2014-04-28 13:55:14 -0700 | [diff] [blame] | 3926 | self.assertEqual(A.reported, 1) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3927 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3928 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3929 | def test_crd_gate(self): |
| 3930 | "Test cross-repo dependencies" |
| 3931 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3932 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3933 | A.addApproval('code-review', 2) |
| 3934 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3935 | |
| 3936 | AM2 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM2') |
| 3937 | AM1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'AM1') |
| 3938 | AM2.setMerged() |
| 3939 | AM1.setMerged() |
| 3940 | |
| 3941 | BM2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM2') |
| 3942 | BM1 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'BM1') |
| 3943 | BM2.setMerged() |
| 3944 | BM1.setMerged() |
| 3945 | |
| 3946 | # A -> AM1 -> AM2 |
| 3947 | # B -> BM1 -> BM2 |
| 3948 | # A Depends-On: B |
| 3949 | # M2 is here to make sure it is never queried. If it is, it |
| 3950 | # means zuul is walking down the entire history of merged |
| 3951 | # changes. |
| 3952 | |
| 3953 | B.setDependsOn(BM1, 1) |
| 3954 | BM1.setDependsOn(BM2, 1) |
| 3955 | |
| 3956 | A.setDependsOn(AM1, 1) |
| 3957 | AM1.setDependsOn(AM2, 1) |
| 3958 | |
| 3959 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 3960 | A.subject, B.data['id']) |
| 3961 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3962 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3963 | self.waitUntilSettled() |
| 3964 | |
| 3965 | self.assertEqual(A.data['status'], 'NEW') |
| 3966 | self.assertEqual(B.data['status'], 'NEW') |
| 3967 | |
Joshua Hesketh | 4bd7da3 | 2016-02-17 20:58:47 +1100 | [diff] [blame] | 3968 | for connection in self.connections.values(): |
| 3969 | connection.maintainCache([]) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3970 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3971 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 3972 | B.addApproval('approved', 1) |
| 3973 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3974 | self.waitUntilSettled() |
| 3975 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3976 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3977 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3978 | self.launch_server.release('.*-merge') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3979 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 3980 | self.launch_server.hold_jobs_in_build = False |
| 3981 | self.launch_server.release() |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 3982 | self.waitUntilSettled() |
| 3983 | |
| 3984 | self.assertEqual(AM2.queried, 0) |
| 3985 | self.assertEqual(BM2.queried, 0) |
| 3986 | self.assertEqual(A.data['status'], 'MERGED') |
| 3987 | self.assertEqual(B.data['status'], 'MERGED') |
| 3988 | self.assertEqual(A.reported, 2) |
| 3989 | self.assertEqual(B.reported, 2) |
| 3990 | |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3991 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 3992 | '2,1 1,1') |
| 3993 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 3994 | @skip("Disabled for early v3 development") |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 3995 | def test_crd_branch(self): |
| 3996 | "Test cross-repo dependencies in multiple branches" |
| 3997 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 3998 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 3999 | C = self.fake_gerrit.addFakeChange('org/project2', 'mp', 'C') |
| 4000 | C.data['id'] = B.data['id'] |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4001 | A.addApproval('code-review', 2) |
| 4002 | B.addApproval('code-review', 2) |
| 4003 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4004 | |
| 4005 | # A Depends-On: B+C |
| 4006 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4007 | A.subject, B.data['id']) |
| 4008 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4009 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4010 | B.addApproval('approved', 1) |
| 4011 | C.addApproval('approved', 1) |
| 4012 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4013 | self.waitUntilSettled() |
| 4014 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4015 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4016 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4017 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4018 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4019 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4020 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4021 | self.launch_server.hold_jobs_in_build = False |
| 4022 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4023 | self.waitUntilSettled() |
| 4024 | |
| 4025 | self.assertEqual(A.data['status'], 'MERGED') |
| 4026 | self.assertEqual(B.data['status'], 'MERGED') |
| 4027 | self.assertEqual(C.data['status'], 'MERGED') |
| 4028 | self.assertEqual(A.reported, 2) |
| 4029 | self.assertEqual(B.reported, 2) |
| 4030 | self.assertEqual(C.reported, 2) |
| 4031 | |
| 4032 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4033 | '2,1 3,1 1,1') |
| 4034 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4035 | @skip("Disabled for early v3 development") |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4036 | def test_crd_multiline(self): |
| 4037 | "Test multiple depends-on lines in commit" |
| 4038 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4039 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4040 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4041 | A.addApproval('code-review', 2) |
| 4042 | B.addApproval('code-review', 2) |
| 4043 | C.addApproval('code-review', 2) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4044 | |
| 4045 | # A Depends-On: B+C |
| 4046 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\nDepends-On: %s\n' % ( |
| 4047 | A.subject, B.data['id'], C.data['id']) |
| 4048 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4049 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4050 | B.addApproval('approved', 1) |
| 4051 | C.addApproval('approved', 1) |
| 4052 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4053 | self.waitUntilSettled() |
| 4054 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4055 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4056 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4057 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4058 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4059 | self.launch_server.release('.*-merge') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4060 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4061 | self.launch_server.hold_jobs_in_build = False |
| 4062 | self.launch_server.release() |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4063 | self.waitUntilSettled() |
| 4064 | |
| 4065 | self.assertEqual(A.data['status'], 'MERGED') |
| 4066 | self.assertEqual(B.data['status'], 'MERGED') |
| 4067 | self.assertEqual(C.data['status'], 'MERGED') |
| 4068 | self.assertEqual(A.reported, 2) |
| 4069 | self.assertEqual(B.reported, 2) |
| 4070 | self.assertEqual(C.reported, 2) |
| 4071 | |
| 4072 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4073 | '2,1 3,1 1,1') |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4074 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4075 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4076 | def test_crd_unshared_gate(self): |
| 4077 | "Test cross-repo dependencies in unshared gate queues" |
| 4078 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4079 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4080 | A.addApproval('code-review', 2) |
| 4081 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4082 | |
| 4083 | # A Depends-On: B |
| 4084 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4085 | A.subject, B.data['id']) |
| 4086 | |
| 4087 | # A and B do not share a queue, make sure that A is unable to |
| 4088 | # enqueue B (and therefore, A is unable to be enqueued). |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4089 | B.addApproval('approved', 1) |
| 4090 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4091 | self.waitUntilSettled() |
| 4092 | |
| 4093 | self.assertEqual(A.data['status'], 'NEW') |
| 4094 | self.assertEqual(B.data['status'], 'NEW') |
| 4095 | self.assertEqual(A.reported, 0) |
| 4096 | self.assertEqual(B.reported, 0) |
| 4097 | self.assertEqual(len(self.history), 0) |
| 4098 | |
| 4099 | # Enqueue and merge B alone. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4100 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4101 | self.waitUntilSettled() |
| 4102 | |
| 4103 | self.assertEqual(B.data['status'], 'MERGED') |
| 4104 | self.assertEqual(B.reported, 2) |
| 4105 | |
| 4106 | # Now that B is merged, A should be able to be enqueued and |
| 4107 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4108 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4109 | self.waitUntilSettled() |
| 4110 | |
| 4111 | self.assertEqual(A.data['status'], 'MERGED') |
| 4112 | self.assertEqual(A.reported, 2) |
| 4113 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4114 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4115 | def test_crd_gate_reverse(self): |
| 4116 | "Test reverse cross-repo dependencies" |
| 4117 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4118 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4119 | A.addApproval('code-review', 2) |
| 4120 | B.addApproval('code-review', 2) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4121 | |
| 4122 | # A Depends-On: B |
| 4123 | |
| 4124 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4125 | A.subject, B.data['id']) |
| 4126 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4127 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4128 | self.waitUntilSettled() |
| 4129 | |
| 4130 | self.assertEqual(A.data['status'], 'NEW') |
| 4131 | self.assertEqual(B.data['status'], 'NEW') |
| 4132 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4133 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4134 | A.addApproval('approved', 1) |
| 4135 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4136 | self.waitUntilSettled() |
| 4137 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4138 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4139 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4140 | self.launch_server.release('.*-merge') |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4141 | self.waitUntilSettled() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4142 | self.launch_server.hold_jobs_in_build = False |
| 4143 | self.launch_server.release() |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4144 | self.waitUntilSettled() |
| 4145 | |
| 4146 | self.assertEqual(A.data['status'], 'MERGED') |
| 4147 | self.assertEqual(B.data['status'], 'MERGED') |
| 4148 | self.assertEqual(A.reported, 2) |
| 4149 | self.assertEqual(B.reported, 2) |
| 4150 | |
| 4151 | self.assertEqual(self.getJobFromHistory('project1-merge').changes, |
| 4152 | '2,1 1,1') |
| 4153 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4154 | @skip("Disabled for early v3 development") |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4155 | def test_crd_cycle(self): |
| 4156 | "Test cross-repo dependency cycles" |
| 4157 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4158 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4159 | A.addApproval('code-review', 2) |
| 4160 | B.addApproval('code-review', 2) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4161 | |
| 4162 | # A -> B -> A (via commit-depends) |
| 4163 | |
| 4164 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4165 | A.subject, B.data['id']) |
| 4166 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4167 | B.subject, A.data['id']) |
| 4168 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4169 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
James E. Blair | 5ee2425 | 2014-12-30 10:12:29 -0800 | [diff] [blame] | 4170 | self.waitUntilSettled() |
| 4171 | |
| 4172 | self.assertEqual(A.reported, 0) |
| 4173 | self.assertEqual(B.reported, 0) |
| 4174 | self.assertEqual(A.data['status'], 'NEW') |
| 4175 | self.assertEqual(B.data['status'], 'NEW') |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4176 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4177 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4178 | def test_crd_gate_unknown(self): |
| 4179 | "Test unknown projects in dependent pipeline" |
| 4180 | self.init_repo("org/unknown") |
| 4181 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4182 | B = self.fake_gerrit.addFakeChange('org/unknown', 'master', 'B') |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4183 | A.addApproval('code-review', 2) |
| 4184 | B.addApproval('code-review', 2) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4185 | |
| 4186 | # A Depends-On: B |
| 4187 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4188 | A.subject, B.data['id']) |
| 4189 | |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4190 | B.addApproval('approved', 1) |
| 4191 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4192 | self.waitUntilSettled() |
| 4193 | |
| 4194 | # Unknown projects cannot share a queue with any other |
| 4195 | # since they don't have common jobs with any other (they have no jobs). |
| 4196 | # Changes which depend on unknown project changes |
| 4197 | # should not be processed in dependent pipeline |
| 4198 | self.assertEqual(A.data['status'], 'NEW') |
| 4199 | self.assertEqual(B.data['status'], 'NEW') |
| 4200 | self.assertEqual(A.reported, 0) |
| 4201 | self.assertEqual(B.reported, 0) |
| 4202 | self.assertEqual(len(self.history), 0) |
| 4203 | |
| 4204 | # Simulate change B being gated outside this layout |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4205 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4206 | B.setMerged() |
| 4207 | self.waitUntilSettled() |
| 4208 | self.assertEqual(len(self.history), 0) |
| 4209 | |
| 4210 | # Now that B is merged, A should be able to be enqueued and |
| 4211 | # merged. |
James E. Blair | 8b5408c | 2016-08-08 15:37:46 -0700 | [diff] [blame] | 4212 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4213 | self.waitUntilSettled() |
| 4214 | |
| 4215 | self.assertEqual(A.data['status'], 'MERGED') |
| 4216 | self.assertEqual(A.reported, 2) |
| 4217 | self.assertEqual(B.data['status'], 'MERGED') |
| 4218 | self.assertEqual(B.reported, 0) |
| 4219 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4220 | @skip("Disabled for early v3 development") |
James E. Blair | bfb8e04 | 2014-12-30 17:01:44 -0800 | [diff] [blame] | 4221 | def test_crd_check(self): |
| 4222 | "Test cross-repo dependencies in independent pipelines" |
| 4223 | |
| 4224 | self.gearman_server.hold_jobs_in_queue = True |
| 4225 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4226 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4227 | |
| 4228 | # A Depends-On: B |
| 4229 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4230 | A.subject, B.data['id']) |
| 4231 | |
| 4232 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4233 | self.waitUntilSettled() |
| 4234 | |
| 4235 | queue = self.gearman_server.getQueue() |
| 4236 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 4237 | self.gearman_server.hold_jobs_in_queue = False |
| 4238 | self.gearman_server.release() |
| 4239 | self.waitUntilSettled() |
| 4240 | |
| 4241 | path = os.path.join(self.git_root, "org/project1") |
| 4242 | repo = git.Repo(path) |
| 4243 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4244 | repo_messages.reverse() |
| 4245 | correct_messages = ['initial commit', 'A-1'] |
| 4246 | self.assertEqual(repo_messages, correct_messages) |
| 4247 | |
| 4248 | path = os.path.join(self.git_root, "org/project2") |
| 4249 | repo = git.Repo(path) |
| 4250 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 4251 | repo_messages.reverse() |
| 4252 | correct_messages = ['initial commit', 'B-1'] |
| 4253 | self.assertEqual(repo_messages, correct_messages) |
| 4254 | |
| 4255 | self.assertEqual(A.data['status'], 'NEW') |
| 4256 | self.assertEqual(B.data['status'], 'NEW') |
| 4257 | self.assertEqual(A.reported, 1) |
| 4258 | self.assertEqual(B.reported, 0) |
| 4259 | |
| 4260 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 4261 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4262 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4263 | @skip("Disabled for early v3 development") |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4264 | def test_crd_check_git_depends(self): |
| 4265 | "Test single-repo dependencies in independent pipelines" |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4266 | self.gearman_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4267 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4268 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4269 | |
| 4270 | # Add two git-dependent changes and make sure they both report |
| 4271 | # success. |
| 4272 | B.setDependsOn(A, 1) |
| 4273 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4274 | self.waitUntilSettled() |
| 4275 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4276 | self.waitUntilSettled() |
| 4277 | |
James E. Blair | b8c1647 | 2015-05-05 14:55:26 -0700 | [diff] [blame] | 4278 | self.orderedRelease() |
| 4279 | self.gearman_server.hold_jobs_in_build = False |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4280 | self.waitUntilSettled() |
| 4281 | |
| 4282 | self.assertEqual(A.data['status'], 'NEW') |
| 4283 | self.assertEqual(B.data['status'], 'NEW') |
| 4284 | self.assertEqual(A.reported, 1) |
| 4285 | self.assertEqual(B.reported, 1) |
| 4286 | |
| 4287 | self.assertEqual(self.history[0].changes, '1,1') |
| 4288 | self.assertEqual(self.history[-1].changes, '1,1 2,1') |
| 4289 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 4290 | |
| 4291 | self.assertIn('Build succeeded', A.messages[0]) |
| 4292 | self.assertIn('Build succeeded', B.messages[0]) |
| 4293 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4294 | @skip("Disabled for early v3 development") |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4295 | def test_crd_check_duplicate(self): |
| 4296 | "Test duplicate check in independent pipelines" |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4297 | self.launch_server.hold_jobs_in_build = True |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4298 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4299 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4300 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4301 | |
| 4302 | # Add two git-dependent changes... |
| 4303 | B.setDependsOn(A, 1) |
| 4304 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4305 | self.waitUntilSettled() |
| 4306 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4307 | |
| 4308 | # ...make sure the live one is not duplicated... |
| 4309 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4310 | self.waitUntilSettled() |
| 4311 | self.assertEqual(len(check_pipeline.getAllItems()), 2) |
| 4312 | |
| 4313 | # ...but the non-live one is able to be. |
| 4314 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4315 | self.waitUntilSettled() |
| 4316 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4317 | |
Clark Boylan | dd84982 | 2015-03-02 12:38:14 -0800 | [diff] [blame] | 4318 | # Release jobs in order to avoid races with change A jobs |
| 4319 | # finishing before change B jobs. |
James E. Blair | d765085 | 2015-05-07 15:47:37 -0700 | [diff] [blame] | 4320 | self.orderedRelease() |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4321 | self.launch_server.hold_jobs_in_build = False |
| 4322 | self.launch_server.release() |
James E. Blair | dbfe1cd | 2015-02-07 11:41:19 -0800 | [diff] [blame] | 4323 | self.waitUntilSettled() |
| 4324 | |
| 4325 | self.assertEqual(A.data['status'], 'NEW') |
| 4326 | self.assertEqual(B.data['status'], 'NEW') |
| 4327 | self.assertEqual(A.reported, 1) |
| 4328 | self.assertEqual(B.reported, 1) |
| 4329 | |
| 4330 | self.assertEqual(self.history[0].changes, '1,1 2,1') |
| 4331 | self.assertEqual(self.history[1].changes, '1,1') |
| 4332 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
| 4333 | |
| 4334 | self.assertIn('Build succeeded', A.messages[0]) |
| 4335 | self.assertIn('Build succeeded', B.messages[0]) |
| 4336 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4337 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4338 | def _test_crd_check_reconfiguration(self, project1, project2): |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4339 | "Test cross-repo dependencies re-enqueued in independent pipelines" |
| 4340 | |
| 4341 | self.gearman_server.hold_jobs_in_queue = True |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4342 | A = self.fake_gerrit.addFakeChange(project1, 'master', 'A') |
| 4343 | B = self.fake_gerrit.addFakeChange(project2, 'master', 'B') |
James E. Blair | 8f78d88 | 2015-02-05 08:51:37 -0800 | [diff] [blame] | 4344 | |
| 4345 | # A Depends-On: B |
| 4346 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4347 | A.subject, B.data['id']) |
| 4348 | |
| 4349 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4350 | self.waitUntilSettled() |
| 4351 | |
| 4352 | self.sched.reconfigure(self.config) |
| 4353 | |
| 4354 | # Make sure the items still share a change queue, and the |
| 4355 | # first one is not live. |
| 4356 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 1) |
| 4357 | queue = self.sched.layout.pipelines['check'].queues[0] |
| 4358 | first_item = queue.queue[0] |
| 4359 | for item in queue.queue: |
| 4360 | self.assertEqual(item.queue, first_item.queue) |
| 4361 | self.assertFalse(first_item.live) |
| 4362 | self.assertTrue(queue.queue[1].live) |
| 4363 | |
| 4364 | self.gearman_server.hold_jobs_in_queue = False |
| 4365 | self.gearman_server.release() |
| 4366 | self.waitUntilSettled() |
| 4367 | |
| 4368 | self.assertEqual(A.data['status'], 'NEW') |
| 4369 | self.assertEqual(B.data['status'], 'NEW') |
| 4370 | self.assertEqual(A.reported, 1) |
| 4371 | self.assertEqual(B.reported, 0) |
| 4372 | |
| 4373 | self.assertEqual(self.history[0].changes, '2,1 1,1') |
| 4374 | self.assertEqual(len(self.sched.layout.pipelines['check'].queues), 0) |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4375 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4376 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4377 | def test_crd_check_reconfiguration(self): |
| 4378 | self._test_crd_check_reconfiguration('org/project1', 'org/project2') |
| 4379 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4380 | @skip("Disabled for early v3 development") |
Evgeny Antyshev | 0deaaad | 2015-08-03 20:22:56 +0000 | [diff] [blame] | 4381 | def test_crd_undefined_project(self): |
| 4382 | """Test that undefined projects in dependencies are handled for |
| 4383 | independent pipelines""" |
| 4384 | # It's a hack for fake gerrit, |
| 4385 | # as it implies repo creation upon the creation of any change |
| 4386 | self.init_repo("org/unknown") |
| 4387 | self._test_crd_check_reconfiguration('org/project1', 'org/unknown') |
| 4388 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4389 | @skip("Disabled for early v3 development") |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4390 | def test_crd_check_ignore_dependencies(self): |
| 4391 | "Test cross-repo dependencies can be ignored" |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4392 | self.updateConfigLayout( |
| 4393 | 'tests/fixtures/layout-ignore-dependencies.yaml') |
James E. Blair | 17dd677 | 2015-02-09 14:45:18 -0800 | [diff] [blame] | 4394 | self.sched.reconfigure(self.config) |
| 4395 | self.registerJobs() |
| 4396 | |
| 4397 | self.gearman_server.hold_jobs_in_queue = True |
| 4398 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4399 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4400 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 4401 | |
| 4402 | # A Depends-On: B |
| 4403 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4404 | A.subject, B.data['id']) |
| 4405 | # C git-depends on B |
| 4406 | C.setDependsOn(B, 1) |
| 4407 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4408 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4409 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4410 | self.waitUntilSettled() |
| 4411 | |
| 4412 | # Make sure none of the items share a change queue, and all |
| 4413 | # are live. |
| 4414 | check_pipeline = self.sched.layout.pipelines['check'] |
| 4415 | self.assertEqual(len(check_pipeline.queues), 3) |
| 4416 | self.assertEqual(len(check_pipeline.getAllItems()), 3) |
| 4417 | for item in check_pipeline.getAllItems(): |
| 4418 | self.assertTrue(item.live) |
| 4419 | |
| 4420 | self.gearman_server.hold_jobs_in_queue = False |
| 4421 | self.gearman_server.release() |
| 4422 | self.waitUntilSettled() |
| 4423 | |
| 4424 | self.assertEqual(A.data['status'], 'NEW') |
| 4425 | self.assertEqual(B.data['status'], 'NEW') |
| 4426 | self.assertEqual(C.data['status'], 'NEW') |
| 4427 | self.assertEqual(A.reported, 1) |
| 4428 | self.assertEqual(B.reported, 1) |
| 4429 | self.assertEqual(C.reported, 1) |
| 4430 | |
| 4431 | # Each job should have tested exactly one change |
| 4432 | for job in self.history: |
| 4433 | self.assertEqual(len(job.changes.split()), 1) |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4434 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4435 | @skip("Disabled for early v3 development") |
James E. Blair | 96698e2 | 2015-04-02 07:48:21 -0700 | [diff] [blame] | 4436 | def test_crd_check_transitive(self): |
| 4437 | "Test transitive cross-repo dependencies" |
| 4438 | # Specifically, if A -> B -> C, and C gets a new patchset and |
| 4439 | # A gets a new patchset, ensure the test of A,2 includes B,1 |
| 4440 | # and C,2 (not C,1 which would indicate stale data in the |
| 4441 | # cache for B). |
| 4442 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 4443 | B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') |
| 4444 | C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C') |
| 4445 | |
| 4446 | # A Depends-On: B |
| 4447 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4448 | A.subject, B.data['id']) |
| 4449 | |
| 4450 | # B Depends-On: C |
| 4451 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4452 | B.subject, C.data['id']) |
| 4453 | |
| 4454 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4455 | self.waitUntilSettled() |
| 4456 | self.assertEqual(self.history[-1].changes, '3,1 2,1 1,1') |
| 4457 | |
| 4458 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4459 | self.waitUntilSettled() |
| 4460 | self.assertEqual(self.history[-1].changes, '3,1 2,1') |
| 4461 | |
| 4462 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4463 | self.waitUntilSettled() |
| 4464 | self.assertEqual(self.history[-1].changes, '3,1') |
| 4465 | |
| 4466 | C.addPatchset() |
| 4467 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(2)) |
| 4468 | self.waitUntilSettled() |
| 4469 | self.assertEqual(self.history[-1].changes, '3,2') |
| 4470 | |
| 4471 | A.addPatchset() |
| 4472 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 4473 | self.waitUntilSettled() |
| 4474 | self.assertEqual(self.history[-1].changes, '3,2 2,1 1,2') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4475 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4476 | @skip("Disabled for early v3 development") |
James E. Blair | 92464a2 | 2016-04-05 10:21:26 -0700 | [diff] [blame] | 4477 | def test_crd_cycle_join(self): |
| 4478 | "Test an updated change creates a cycle" |
| 4479 | A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') |
| 4480 | |
| 4481 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4482 | self.waitUntilSettled() |
| 4483 | |
| 4484 | # Create B->A |
| 4485 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 4486 | B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4487 | B.subject, A.data['id']) |
| 4488 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4489 | self.waitUntilSettled() |
| 4490 | |
| 4491 | # Update A to add A->B (a cycle). |
| 4492 | A.addPatchset() |
| 4493 | A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( |
| 4494 | A.subject, B.data['id']) |
| 4495 | # Normally we would submit the patchset-created event for |
| 4496 | # processing here, however, we have no way of noting whether |
| 4497 | # the dependency cycle detection correctly raised an |
| 4498 | # exception, so instead, we reach into the source driver and |
| 4499 | # call the method that would ultimately be called by the event |
| 4500 | # processing. |
| 4501 | |
| 4502 | source = self.sched.layout.pipelines['gate'].source |
| 4503 | with testtools.ExpectedException( |
| 4504 | Exception, "Dependency cycle detected"): |
| 4505 | source._getChange(u'1', u'2', True) |
| 4506 | self.log.debug("Got expected dependency cycle exception") |
| 4507 | |
| 4508 | # Now if we update B to remove the depends-on, everything |
| 4509 | # should be okay. B; A->B |
| 4510 | |
| 4511 | B.addPatchset() |
| 4512 | B.data['commitMessage'] = '%s\n' % (B.subject,) |
| 4513 | source._getChange(u'1', u'2', True) |
| 4514 | source._getChange(u'2', u'2', True) |
| 4515 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4516 | @skip("Disabled for early v3 development") |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4517 | def test_disable_at(self): |
| 4518 | "Test a pipeline will only report to the disabled trigger when failing" |
| 4519 | |
James E. Blair | f84026c | 2015-12-08 16:11:46 -0800 | [diff] [blame] | 4520 | self.updateConfigLayout( |
| 4521 | 'tests/fixtures/layout-disable-at.yaml') |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4522 | self.sched.reconfigure(self.config) |
| 4523 | |
| 4524 | self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at) |
| 4525 | self.assertEqual( |
| 4526 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4527 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4528 | |
| 4529 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 4530 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 4531 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 4532 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 4533 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 4534 | F = self.fake_gerrit.addFakeChange('org/project', 'master', 'F') |
| 4535 | G = self.fake_gerrit.addFakeChange('org/project', 'master', 'G') |
| 4536 | H = self.fake_gerrit.addFakeChange('org/project', 'master', 'H') |
| 4537 | I = self.fake_gerrit.addFakeChange('org/project', 'master', 'I') |
| 4538 | J = self.fake_gerrit.addFakeChange('org/project', 'master', 'J') |
| 4539 | K = self.fake_gerrit.addFakeChange('org/project', 'master', 'K') |
| 4540 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4541 | self.launch_server.failJob('project-test1', A) |
| 4542 | self.launch_server.failJob('project-test1', B) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4543 | # Let C pass, resetting the counter |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4544 | self.launch_server.failJob('project-test1', D) |
| 4545 | self.launch_server.failJob('project-test1', E) |
| 4546 | self.launch_server.failJob('project-test1', F) |
| 4547 | self.launch_server.failJob('project-test1', G) |
| 4548 | self.launch_server.failJob('project-test1', H) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4549 | # I also passes but should only report to the disabled reporters |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4550 | self.launch_server.failJob('project-test1', J) |
| 4551 | self.launch_server.failJob('project-test1', K) |
Joshua Hesketh | 89e829d | 2015-02-10 16:29:45 +1100 | [diff] [blame] | 4552 | |
| 4553 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4554 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 4555 | self.waitUntilSettled() |
| 4556 | |
| 4557 | self.assertEqual( |
| 4558 | 2, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4559 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4560 | |
| 4561 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 4562 | self.waitUntilSettled() |
| 4563 | |
| 4564 | self.assertEqual( |
| 4565 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4566 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4567 | |
| 4568 | self.fake_gerrit.addEvent(D.getPatchsetCreatedEvent(1)) |
| 4569 | self.fake_gerrit.addEvent(E.getPatchsetCreatedEvent(1)) |
| 4570 | self.fake_gerrit.addEvent(F.getPatchsetCreatedEvent(1)) |
| 4571 | self.waitUntilSettled() |
| 4572 | |
| 4573 | # We should be disabled now |
| 4574 | self.assertEqual( |
| 4575 | 3, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4576 | self.assertTrue(self.sched.layout.pipelines['check']._disabled) |
| 4577 | |
| 4578 | # We need to wait between each of these patches to make sure the |
| 4579 | # smtp messages come back in an expected order |
| 4580 | self.fake_gerrit.addEvent(G.getPatchsetCreatedEvent(1)) |
| 4581 | self.waitUntilSettled() |
| 4582 | self.fake_gerrit.addEvent(H.getPatchsetCreatedEvent(1)) |
| 4583 | self.waitUntilSettled() |
| 4584 | self.fake_gerrit.addEvent(I.getPatchsetCreatedEvent(1)) |
| 4585 | self.waitUntilSettled() |
| 4586 | |
| 4587 | # The first 6 (ABCDEF) jobs should have reported back to gerrt thus |
| 4588 | # leaving a message on each change |
| 4589 | self.assertEqual(1, len(A.messages)) |
| 4590 | self.assertIn('Build failed.', A.messages[0]) |
| 4591 | self.assertEqual(1, len(B.messages)) |
| 4592 | self.assertIn('Build failed.', B.messages[0]) |
| 4593 | self.assertEqual(1, len(C.messages)) |
| 4594 | self.assertIn('Build succeeded.', C.messages[0]) |
| 4595 | self.assertEqual(1, len(D.messages)) |
| 4596 | self.assertIn('Build failed.', D.messages[0]) |
| 4597 | self.assertEqual(1, len(E.messages)) |
| 4598 | self.assertIn('Build failed.', E.messages[0]) |
| 4599 | self.assertEqual(1, len(F.messages)) |
| 4600 | self.assertIn('Build failed.', F.messages[0]) |
| 4601 | |
| 4602 | # The last 3 (GHI) would have only reported via smtp. |
| 4603 | self.assertEqual(3, len(self.smtp_messages)) |
| 4604 | self.assertEqual(0, len(G.messages)) |
| 4605 | self.assertIn('Build failed.', self.smtp_messages[0]['body']) |
| 4606 | self.assertIn('/7/1/check', self.smtp_messages[0]['body']) |
| 4607 | self.assertEqual(0, len(H.messages)) |
| 4608 | self.assertIn('Build failed.', self.smtp_messages[1]['body']) |
| 4609 | self.assertIn('/8/1/check', self.smtp_messages[1]['body']) |
| 4610 | self.assertEqual(0, len(I.messages)) |
| 4611 | self.assertIn('Build succeeded.', self.smtp_messages[2]['body']) |
| 4612 | self.assertIn('/9/1/check', self.smtp_messages[2]['body']) |
| 4613 | |
| 4614 | # Now reload the configuration (simulate a HUP) to check the pipeline |
| 4615 | # comes out of disabled |
| 4616 | self.sched.reconfigure(self.config) |
| 4617 | |
| 4618 | self.assertEqual(3, self.sched.layout.pipelines['check'].disable_at) |
| 4619 | self.assertEqual( |
| 4620 | 0, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4621 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4622 | |
| 4623 | self.fake_gerrit.addEvent(J.getPatchsetCreatedEvent(1)) |
| 4624 | self.fake_gerrit.addEvent(K.getPatchsetCreatedEvent(1)) |
| 4625 | self.waitUntilSettled() |
| 4626 | |
| 4627 | self.assertEqual( |
| 4628 | 2, self.sched.layout.pipelines['check']._consecutive_failures) |
| 4629 | self.assertFalse(self.sched.layout.pipelines['check']._disabled) |
| 4630 | |
| 4631 | # J and K went back to gerrit |
| 4632 | self.assertEqual(1, len(J.messages)) |
| 4633 | self.assertIn('Build failed.', J.messages[0]) |
| 4634 | self.assertEqual(1, len(K.messages)) |
| 4635 | self.assertIn('Build failed.', K.messages[0]) |
| 4636 | # No more messages reported via smtp |
| 4637 | self.assertEqual(3, len(self.smtp_messages)) |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4638 | |
James E. Blair | ec05649 | 2016-07-22 09:45:56 -0700 | [diff] [blame] | 4639 | @skip("Disabled for early v3 development") |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4640 | def test_success_pattern(self): |
| 4641 | "Ensure bad build params are ignored" |
| 4642 | |
| 4643 | # Use SMTP reporter to grab the result message easier |
| 4644 | self.init_repo("org/docs") |
| 4645 | self.config.set('zuul', 'layout_config', |
| 4646 | 'tests/fixtures/layout-success-pattern.yaml') |
| 4647 | self.sched.reconfigure(self.config) |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4648 | self.launch_server.hold_jobs_in_build = True |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4649 | self.registerJobs() |
| 4650 | |
| 4651 | A = self.fake_gerrit.addFakeChange('org/docs', 'master', 'A') |
| 4652 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 4653 | self.waitUntilSettled() |
| 4654 | |
| 4655 | # Grab build id |
| 4656 | self.assertEqual(len(self.builds), 1) |
| 4657 | uuid = self.builds[0].unique[:7] |
| 4658 | |
James E. Blair | 08d1999 | 2016-08-10 15:25:31 -0700 | [diff] [blame] | 4659 | self.launch_server.hold_jobs_in_build = False |
| 4660 | self.launch_server.release() |
Joshua Hesketh | d6dbd68 | 2015-12-22 10:06:54 +1100 | [diff] [blame] | 4661 | self.waitUntilSettled() |
| 4662 | |
| 4663 | self.assertEqual(len(self.smtp_messages), 1) |
| 4664 | body = self.smtp_messages[0]['body'].splitlines() |
| 4665 | self.assertEqual('Build succeeded.', body[0]) |
| 4666 | |
| 4667 | self.assertIn( |
| 4668 | '- docs-draft-test http://docs-draft.example.org/1/1/1/check/' |
| 4669 | 'docs-draft-test/%s/publish-docs/' % uuid, |
| 4670 | body[2]) |
| 4671 | self.assertIn( |
| 4672 | '- docs-draft-test2 https://server/job/docs-draft-test2/1/', |
| 4673 | body[3]) |