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 ConfigParser |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 18 | from cStringIO import StringIO |
Clark Boylan | 4ba48d9 | 2013-11-11 18:03:53 -0800 | [diff] [blame] | 19 | import gc |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 20 | import hashlib |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 21 | import json |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 22 | import logging |
| 23 | import os |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 24 | import pprint |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 25 | import Queue |
| 26 | import random |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 27 | import re |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 28 | import select |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 29 | import shutil |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 30 | import socket |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 31 | import string |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 32 | import subprocess |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 33 | import threading |
| 34 | import time |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 35 | import urllib |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 36 | import urllib2 |
| 37 | import urlparse |
| 38 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 39 | import git |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 40 | import gear |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 41 | import fixtures |
| 42 | import statsd |
| 43 | import testtools |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 44 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 45 | import zuul.scheduler |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 46 | import zuul.webapp |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 47 | import zuul.rpclistener |
| 48 | import zuul.rpcclient |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 49 | import zuul.launcher.gearman |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 50 | import zuul.merger.server |
| 51 | import zuul.merger.client |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 52 | import zuul.reporter.gerrit |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 53 | import zuul.reporter.smtp |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 54 | import zuul.trigger.gerrit |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 55 | import zuul.trigger.timer |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 56 | |
| 57 | FIXTURE_DIR = os.path.join(os.path.dirname(__file__), |
| 58 | 'fixtures') |
| 59 | CONFIG = ConfigParser.ConfigParser() |
| 60 | CONFIG.read(os.path.join(FIXTURE_DIR, "zuul.conf")) |
| 61 | |
| 62 | CONFIG.set('zuul', 'layout_config', |
| 63 | os.path.join(FIXTURE_DIR, "layout.yaml")) |
| 64 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 65 | logging.basicConfig(level=logging.DEBUG, |
| 66 | format='%(asctime)s %(name)-32s ' |
| 67 | '%(levelname)-8s %(message)s') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 68 | |
| 69 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 70 | def repack_repo(path): |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 71 | cmd = ['git', '--git-dir=%s/.git' % path, 'repack', '-afd'] |
| 72 | output = subprocess.Popen(cmd, close_fds=True, |
| 73 | stdout=subprocess.PIPE, |
| 74 | stderr=subprocess.PIPE) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 75 | out = output.communicate() |
| 76 | if output.returncode: |
| 77 | raise Exception("git repack returned %d" % output.returncode) |
| 78 | return out |
| 79 | |
| 80 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 81 | def random_sha1(): |
| 82 | return hashlib.sha1(str(random.random())).hexdigest() |
| 83 | |
| 84 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 85 | class ChangeReference(git.Reference): |
| 86 | _common_path_default = "refs/changes" |
| 87 | _points_to_commits_only = True |
| 88 | |
| 89 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 90 | class FakeChange(object): |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 91 | categories = {'APRV': ('Approved', -1, 1), |
| 92 | 'CRVW': ('Code-Review', -2, 2), |
| 93 | 'VRFY': ('Verified', -2, 2)} |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 94 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 95 | def __init__(self, gerrit, number, project, branch, subject, |
| 96 | status='NEW', upstream_root=None): |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 97 | self.gerrit = gerrit |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 98 | self.reported = 0 |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 99 | self.queried = 0 |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 100 | self.patchsets = [] |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 101 | self.number = number |
| 102 | self.project = project |
| 103 | self.branch = branch |
| 104 | self.subject = subject |
| 105 | self.latest_patchset = 0 |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 106 | self.depends_on_change = None |
| 107 | self.needed_by_changes = [] |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 108 | self.fail_merge = False |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 109 | self.messages = [] |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 110 | self.data = { |
| 111 | 'branch': branch, |
| 112 | 'comments': [], |
| 113 | 'commitMessage': subject, |
| 114 | 'createdOn': time.time(), |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 115 | 'id': 'I' + random_sha1(), |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 116 | 'lastUpdated': time.time(), |
| 117 | 'number': str(number), |
| 118 | 'open': True, |
| 119 | 'owner': {'email': 'user@example.com', |
| 120 | 'name': 'User Name', |
| 121 | 'username': 'username'}, |
| 122 | 'patchSets': self.patchsets, |
| 123 | 'project': project, |
| 124 | 'status': status, |
| 125 | 'subject': subject, |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 126 | 'submitRecords': [], |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 127 | 'url': 'https://hostname/%s' % number} |
| 128 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 129 | self.upstream_root = upstream_root |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 130 | self.addPatchset() |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 131 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 132 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 133 | def add_fake_change_to_repo(self, msg, fn, large): |
| 134 | path = os.path.join(self.upstream_root, self.project) |
| 135 | repo = git.Repo(path) |
| 136 | ref = ChangeReference.create(repo, '1/%s/%s' % (self.number, |
| 137 | self.latest_patchset), |
| 138 | 'refs/tags/init') |
| 139 | repo.head.reference = ref |
| 140 | repo.head.reset(index=True, working_tree=True) |
| 141 | repo.git.clean('-x', '-f', '-d') |
| 142 | |
| 143 | path = os.path.join(self.upstream_root, self.project) |
| 144 | if not large: |
| 145 | fn = os.path.join(path, fn) |
| 146 | f = open(fn, 'w') |
| 147 | f.write("test %s %s %s\n" % |
| 148 | (self.branch, self.number, self.latest_patchset)) |
| 149 | f.close() |
| 150 | repo.index.add([fn]) |
| 151 | else: |
| 152 | for fni in range(100): |
| 153 | fn = os.path.join(path, str(fni)) |
| 154 | f = open(fn, 'w') |
| 155 | for ci in range(4096): |
| 156 | f.write(random.choice(string.printable)) |
| 157 | f.close() |
| 158 | repo.index.add([fn]) |
| 159 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 160 | r = repo.index.commit(msg) |
| 161 | repo.head.reference = 'master' |
| 162 | repo.head.reset(index=True, working_tree=True) |
| 163 | repo.git.clean('-x', '-f', '-d') |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 164 | repo.heads['master'].checkout() |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 165 | return r |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 166 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 167 | def addPatchset(self, files=[], large=False): |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 168 | self.latest_patchset += 1 |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 169 | if files: |
| 170 | fn = files[0] |
| 171 | else: |
| 172 | fn = '%s-%s' % (self.branch, self.number) |
| 173 | msg = self.subject + '-' + str(self.latest_patchset) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 174 | c = self.add_fake_change_to_repo(msg, fn, large) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 175 | ps_files = [{'file': '/COMMIT_MSG', |
| 176 | 'type': 'ADDED'}, |
| 177 | {'file': 'README', |
| 178 | 'type': 'MODIFIED'}] |
| 179 | for f in files: |
| 180 | ps_files.append({'file': f, 'type': 'ADDED'}) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 181 | d = {'approvals': [], |
| 182 | 'createdOn': time.time(), |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 183 | 'files': ps_files, |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 184 | 'number': str(self.latest_patchset), |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 185 | 'ref': 'refs/changes/1/%s/%s' % (self.number, |
| 186 | self.latest_patchset), |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 187 | 'revision': c.hexsha, |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 188 | 'uploader': {'email': 'user@example.com', |
| 189 | 'name': 'User name', |
| 190 | 'username': 'user'}} |
| 191 | self.data['currentPatchSet'] = d |
| 192 | self.patchsets.append(d) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 193 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 194 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 195 | def getPatchsetCreatedEvent(self, patchset): |
| 196 | event = {"type": "patchset-created", |
| 197 | "change": {"project": self.project, |
Zhongyue Luo | aa85ebf | 2012-09-21 16:38:33 +0800 | [diff] [blame] | 198 | "branch": self.branch, |
| 199 | "id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af", |
| 200 | "number": str(self.number), |
| 201 | "subject": self.subject, |
| 202 | "owner": {"name": "User Name"}, |
| 203 | "url": "https://hostname/3"}, |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 204 | "patchSet": self.patchsets[patchset - 1], |
| 205 | "uploader": {"name": "User Name"}} |
| 206 | return event |
| 207 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 208 | def getChangeRestoredEvent(self): |
| 209 | event = {"type": "change-restored", |
| 210 | "change": {"project": self.project, |
| 211 | "branch": self.branch, |
| 212 | "id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af", |
| 213 | "number": str(self.number), |
| 214 | "subject": self.subject, |
| 215 | "owner": {"name": "User Name"}, |
| 216 | "url": "https://hostname/3"}, |
| 217 | "restorer": {"name": "User Name"}, |
| 218 | "reason": ""} |
| 219 | return event |
| 220 | |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 221 | def addApproval(self, category, value, username='jenkins', |
| 222 | granted_on=None): |
| 223 | if not granted_on: |
| 224 | granted_on = time.time() |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 225 | approval = {'description': self.categories[category][0], |
| 226 | 'type': category, |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 227 | 'value': str(value), |
James E. Blair | 64ff4ef | 2014-01-24 13:50:23 -0800 | [diff] [blame] | 228 | 'by': { |
| 229 | 'username': username, |
| 230 | 'email': username + '@example.com', |
| 231 | }, |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 232 | 'grantedOn': int(granted_on)} |
| 233 | for i, x in enumerate(self.patchsets[-1]['approvals'][:]): |
James E. Blair | 64ff4ef | 2014-01-24 13:50:23 -0800 | [diff] [blame] | 234 | if x['by']['username'] == username and x['type'] == category: |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 235 | del self.patchsets[-1]['approvals'][i] |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 236 | self.patchsets[-1]['approvals'].append(approval) |
| 237 | event = {'approvals': [approval], |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 238 | 'author': {'email': 'user@example.com', |
| 239 | 'name': 'User Name', |
| 240 | 'username': 'username'}, |
| 241 | 'change': {'branch': self.branch, |
| 242 | 'id': 'Iaa69c46accf97d0598111724a38250ae76a22c87', |
| 243 | 'number': str(self.number), |
| 244 | 'owner': {'email': 'user@example.com', |
| 245 | 'name': 'User Name', |
| 246 | 'username': 'username'}, |
| 247 | 'project': self.project, |
| 248 | 'subject': self.subject, |
| 249 | 'topic': 'master', |
| 250 | 'url': 'https://hostname/459'}, |
| 251 | 'comment': '', |
| 252 | 'patchSet': self.patchsets[-1], |
| 253 | 'type': 'comment-added'} |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 254 | self.data['submitRecords'] = self.getSubmitRecords() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 255 | return json.loads(json.dumps(event)) |
| 256 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 257 | def getSubmitRecords(self): |
| 258 | status = {} |
| 259 | for cat in self.categories.keys(): |
| 260 | status[cat] = 0 |
| 261 | |
| 262 | for a in self.patchsets[-1]['approvals']: |
| 263 | cur = status[a['type']] |
| 264 | cat_min, cat_max = self.categories[a['type']][1:] |
| 265 | new = int(a['value']) |
| 266 | if new == cat_min: |
| 267 | cur = new |
| 268 | elif abs(new) > abs(cur): |
| 269 | cur = new |
| 270 | status[a['type']] = cur |
| 271 | |
| 272 | labels = [] |
| 273 | ok = True |
| 274 | for typ, cat in self.categories.items(): |
| 275 | cur = status[typ] |
| 276 | cat_min, cat_max = cat[1:] |
| 277 | if cur == cat_min: |
| 278 | value = 'REJECT' |
| 279 | ok = False |
| 280 | elif cur == cat_max: |
| 281 | value = 'OK' |
| 282 | else: |
| 283 | value = 'NEED' |
| 284 | ok = False |
| 285 | labels.append({'label': cat[0], 'status': value}) |
| 286 | if ok: |
| 287 | return [{'status': 'OK'}] |
| 288 | return [{'status': 'NOT_READY', |
| 289 | 'labels': labels}] |
| 290 | |
| 291 | def setDependsOn(self, other, patchset): |
| 292 | self.depends_on_change = other |
| 293 | d = {'id': other.data['id'], |
| 294 | 'number': other.data['number'], |
| 295 | 'ref': other.patchsets[patchset - 1]['ref'] |
| 296 | } |
| 297 | self.data['dependsOn'] = [d] |
| 298 | |
| 299 | other.needed_by_changes.append(self) |
| 300 | needed = other.data.get('neededBy', []) |
| 301 | d = {'id': self.data['id'], |
| 302 | 'number': self.data['number'], |
| 303 | 'ref': self.patchsets[patchset - 1]['ref'], |
| 304 | 'revision': self.patchsets[patchset - 1]['revision'] |
| 305 | } |
| 306 | needed.append(d) |
| 307 | other.data['neededBy'] = needed |
| 308 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 309 | def query(self): |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 310 | self.queried += 1 |
| 311 | d = self.data.get('dependsOn') |
| 312 | if d: |
| 313 | d = d[0] |
| 314 | if (self.depends_on_change.patchsets[-1]['ref'] == d['ref']): |
| 315 | d['isCurrentPatchSet'] = True |
| 316 | else: |
| 317 | d['isCurrentPatchSet'] = False |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 318 | return json.loads(json.dumps(self.data)) |
| 319 | |
| 320 | def setMerged(self): |
Zhongyue Luo | aa85ebf | 2012-09-21 16:38:33 +0800 | [diff] [blame] | 321 | if (self.depends_on_change and |
| 322 | self.depends_on_change.data['status'] != 'MERGED'): |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 323 | return |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 324 | if self.fail_merge: |
| 325 | return |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 326 | self.data['status'] = 'MERGED' |
| 327 | self.open = False |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 328 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 329 | path = os.path.join(self.upstream_root, self.project) |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 330 | repo = git.Repo(path) |
| 331 | repo.heads[self.branch].commit = \ |
| 332 | repo.commit(self.patchsets[-1]['revision']) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 333 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 334 | def setReported(self): |
| 335 | self.reported += 1 |
| 336 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 337 | |
| 338 | class FakeGerrit(object): |
| 339 | def __init__(self, *args, **kw): |
| 340 | self.event_queue = Queue.Queue() |
| 341 | self.fixture_dir = os.path.join(FIXTURE_DIR, 'gerrit') |
| 342 | self.change_number = 0 |
| 343 | self.changes = {} |
| 344 | |
| 345 | def addFakeChange(self, project, branch, subject): |
| 346 | self.change_number += 1 |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 347 | c = FakeChange(self, self.change_number, project, branch, subject, |
| 348 | upstream_root=self.upstream_root) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 349 | self.changes[self.change_number] = c |
| 350 | return c |
| 351 | |
| 352 | def addEvent(self, data): |
| 353 | return self.event_queue.put(data) |
| 354 | |
| 355 | def getEvent(self): |
| 356 | return self.event_queue.get() |
| 357 | |
| 358 | def eventDone(self): |
| 359 | self.event_queue.task_done() |
| 360 | |
| 361 | def review(self, project, changeid, message, action): |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 362 | number, ps = changeid.split(',') |
| 363 | change = self.changes[int(number)] |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 364 | change.messages.append(message) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 365 | if 'submit' in action: |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 366 | change.setMerged() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 367 | if message: |
| 368 | change.setReported() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 369 | |
| 370 | def query(self, number): |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 371 | change = self.changes.get(int(number)) |
| 372 | if change: |
| 373 | return change.query() |
| 374 | return {} |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 375 | |
| 376 | def startWatching(self, *args, **kw): |
| 377 | pass |
| 378 | |
| 379 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 380 | class BuildHistory(object): |
| 381 | def __init__(self, **kw): |
| 382 | self.__dict__.update(kw) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 383 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 384 | def __repr__(self): |
| 385 | return ("<Completed build, result: %s name: %s #%s changes: %s>" % |
| 386 | (self.result, self.name, self.number, self.changes)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 387 | |
| 388 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 389 | class FakeURLOpener(object): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 390 | def __init__(self, upstream_root, fake_gerrit, url): |
| 391 | self.upstream_root = upstream_root |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 392 | self.fake_gerrit = fake_gerrit |
| 393 | self.url = url |
| 394 | |
| 395 | def read(self): |
| 396 | res = urlparse.urlparse(self.url) |
| 397 | path = res.path |
| 398 | project = '/'.join(path.split('/')[2:-2]) |
James E. Blair | 35956c5 | 2012-09-17 22:13:36 +0200 | [diff] [blame] | 399 | ret = '001e# service=git-upload-pack\n' |
| 400 | ret += ('000000a31270149696713ba7e06f1beb760f20d359c4abed HEAD\x00' |
| 401 | 'multi_ack thin-pack side-band side-band-64k ofs-delta ' |
| 402 | 'shallow no-progress include-tag multi_ack_detailed no-done\n') |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 403 | path = os.path.join(self.upstream_root, project) |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 404 | repo = git.Repo(path) |
| 405 | for ref in repo.refs: |
James E. Blair | 35956c5 | 2012-09-17 22:13:36 +0200 | [diff] [blame] | 406 | r = ref.object.hexsha + ' ' + ref.path + '\n' |
| 407 | ret += '%04x%s' % (len(r) + 4, r) |
| 408 | ret += '0000' |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 409 | return ret |
| 410 | |
| 411 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 412 | class FakeGerritTrigger(zuul.trigger.gerrit.Gerrit): |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 413 | name = 'gerrit' |
| 414 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 415 | def __init__(self, upstream_root, *args): |
| 416 | super(FakeGerritTrigger, self).__init__(*args) |
| 417 | self.upstream_root = upstream_root |
| 418 | |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 419 | def getGitUrl(self, project): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 420 | return os.path.join(self.upstream_root, project.name) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 421 | |
| 422 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 423 | class FakeStatsd(threading.Thread): |
| 424 | def __init__(self): |
| 425 | threading.Thread.__init__(self) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 426 | self.daemon = True |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 427 | self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 428 | self.sock.bind(('', 0)) |
| 429 | self.port = self.sock.getsockname()[1] |
| 430 | self.wake_read, self.wake_write = os.pipe() |
| 431 | self.stats = [] |
| 432 | |
| 433 | def run(self): |
| 434 | while True: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 435 | poll = select.poll() |
| 436 | poll.register(self.sock, select.POLLIN) |
| 437 | poll.register(self.wake_read, select.POLLIN) |
| 438 | ret = poll.poll() |
| 439 | for (fd, event) in ret: |
| 440 | if fd == self.sock.fileno(): |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 441 | data = self.sock.recvfrom(1024) |
| 442 | if not data: |
| 443 | return |
| 444 | self.stats.append(data[0]) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 445 | if fd == self.wake_read: |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 446 | return |
| 447 | |
| 448 | def stop(self): |
| 449 | os.write(self.wake_write, '1\n') |
| 450 | |
| 451 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 452 | class FakeBuild(threading.Thread): |
| 453 | log = logging.getLogger("zuul.test") |
| 454 | |
| 455 | def __init__(self, worker, job, number, node): |
| 456 | threading.Thread.__init__(self) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 457 | self.daemon = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 458 | self.worker = worker |
| 459 | self.job = job |
| 460 | self.name = job.name.split(':')[1] |
| 461 | self.number = number |
| 462 | self.node = node |
| 463 | self.parameters = json.loads(job.arguments) |
| 464 | self.unique = self.parameters['ZUUL_UUID'] |
| 465 | self.wait_condition = threading.Condition() |
| 466 | self.waiting = False |
| 467 | self.aborted = False |
| 468 | self.created = time.time() |
| 469 | self.description = '' |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 470 | self.run_error = False |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 471 | |
| 472 | def release(self): |
| 473 | self.wait_condition.acquire() |
| 474 | self.wait_condition.notify() |
| 475 | self.waiting = False |
| 476 | self.log.debug("Build %s released" % self.unique) |
| 477 | self.wait_condition.release() |
| 478 | |
| 479 | def isWaiting(self): |
| 480 | self.wait_condition.acquire() |
| 481 | if self.waiting: |
| 482 | ret = True |
| 483 | else: |
| 484 | ret = False |
| 485 | self.wait_condition.release() |
| 486 | return ret |
| 487 | |
| 488 | def _wait(self): |
| 489 | self.wait_condition.acquire() |
| 490 | self.waiting = True |
| 491 | self.log.debug("Build %s waiting" % self.unique) |
| 492 | self.wait_condition.wait() |
| 493 | self.wait_condition.release() |
| 494 | |
| 495 | def run(self): |
| 496 | data = { |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 497 | 'url': 'https://server/job/%s/%s/' % (self.name, self.number), |
| 498 | 'name': self.name, |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 499 | 'number': self.number, |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 500 | 'manager': self.worker.worker_id, |
Paul Belanger | ec49b4c | 2013-07-20 20:32:20 -0400 | [diff] [blame] | 501 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 502 | |
| 503 | self.job.sendWorkData(json.dumps(data)) |
| 504 | self.job.sendWorkStatus(0, 100) |
| 505 | |
| 506 | if self.worker.hold_jobs_in_build: |
| 507 | self._wait() |
| 508 | self.log.debug("Build %s continuing" % self.unique) |
| 509 | |
| 510 | self.worker.lock.acquire() |
| 511 | |
| 512 | result = 'SUCCESS' |
| 513 | if (('ZUUL_REF' in self.parameters) and |
| 514 | self.worker.shouldFailTest(self.name, |
| 515 | self.parameters['ZUUL_REF'])): |
| 516 | result = 'FAILURE' |
| 517 | if self.aborted: |
| 518 | result = 'ABORTED' |
| 519 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 520 | if self.run_error: |
| 521 | work_fail = True |
| 522 | result = 'RUN_ERROR' |
| 523 | else: |
| 524 | data['result'] = result |
| 525 | work_fail = False |
| 526 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 527 | changes = None |
| 528 | if 'ZUUL_CHANGE_IDS' in self.parameters: |
| 529 | changes = self.parameters['ZUUL_CHANGE_IDS'] |
| 530 | |
| 531 | self.worker.build_history.append( |
| 532 | BuildHistory(name=self.name, number=self.number, |
| 533 | result=result, changes=changes, node=self.node, |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 534 | uuid=self.unique, description=self.description, |
| 535 | pipeline=self.parameters['ZUUL_PIPELINE']) |
Paul Belanger | ec49b4c | 2013-07-20 20:32:20 -0400 | [diff] [blame] | 536 | ) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 537 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 538 | self.job.sendWorkData(json.dumps(data)) |
| 539 | if work_fail: |
| 540 | self.job.sendWorkFail() |
| 541 | else: |
| 542 | self.job.sendWorkComplete(json.dumps(data)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 543 | del self.worker.gearman_jobs[self.job.unique] |
| 544 | self.worker.running_builds.remove(self) |
| 545 | self.worker.lock.release() |
| 546 | |
| 547 | |
| 548 | class FakeWorker(gear.Worker): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 549 | def __init__(self, worker_id, test): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 550 | super(FakeWorker, self).__init__(worker_id) |
| 551 | self.gearman_jobs = {} |
| 552 | self.build_history = [] |
| 553 | self.running_builds = [] |
| 554 | self.build_counter = 0 |
| 555 | self.fail_tests = {} |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 556 | self.test = test |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 557 | |
| 558 | self.hold_jobs_in_build = False |
| 559 | self.lock = threading.Lock() |
| 560 | self.__work_thread = threading.Thread(target=self.work) |
James E. Blair | 8a6f0c2 | 2013-07-01 12:31:34 -0400 | [diff] [blame] | 561 | self.__work_thread.daemon = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 562 | self.__work_thread.start() |
| 563 | |
| 564 | def handleJob(self, job): |
| 565 | parts = job.name.split(":") |
| 566 | cmd = parts[0] |
| 567 | name = parts[1] |
| 568 | if len(parts) > 2: |
| 569 | node = parts[2] |
| 570 | else: |
| 571 | node = None |
| 572 | if cmd == 'build': |
| 573 | self.handleBuild(job, name, node) |
| 574 | elif cmd == 'stop': |
| 575 | self.handleStop(job, name) |
| 576 | elif cmd == 'set_description': |
| 577 | self.handleSetDescription(job, name) |
| 578 | |
| 579 | def handleBuild(self, job, name, node): |
| 580 | build = FakeBuild(self, job, self.build_counter, node) |
| 581 | job.build = build |
| 582 | self.gearman_jobs[job.unique] = job |
| 583 | self.build_counter += 1 |
| 584 | |
| 585 | self.running_builds.append(build) |
| 586 | build.start() |
| 587 | |
| 588 | def handleStop(self, job, name): |
| 589 | self.log.debug("handle stop") |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 590 | parameters = json.loads(job.arguments) |
| 591 | name = parameters['name'] |
| 592 | number = parameters['number'] |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 593 | for build in self.running_builds: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 594 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 595 | build.aborted = True |
| 596 | build.release() |
| 597 | job.sendWorkComplete() |
| 598 | return |
| 599 | job.sendWorkFail() |
| 600 | |
| 601 | def handleSetDescription(self, job, name): |
| 602 | self.log.debug("handle set description") |
| 603 | parameters = json.loads(job.arguments) |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 604 | name = parameters['name'] |
| 605 | number = parameters['number'] |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 606 | descr = parameters['html_description'] |
| 607 | for build in self.running_builds: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 608 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 609 | build.description = descr |
| 610 | job.sendWorkComplete() |
| 611 | return |
| 612 | for build in self.build_history: |
James E. Blair | 3c483cf | 2013-06-04 16:30:43 -0700 | [diff] [blame] | 613 | if build.name == name and build.number == number: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 614 | build.description = descr |
| 615 | job.sendWorkComplete() |
| 616 | return |
| 617 | job.sendWorkFail() |
| 618 | |
| 619 | def work(self): |
| 620 | while self.running: |
| 621 | try: |
| 622 | job = self.getJob() |
| 623 | except gear.InterruptedError: |
| 624 | continue |
| 625 | try: |
| 626 | self.handleJob(job) |
| 627 | except: |
| 628 | self.log.exception("Worker exception:") |
| 629 | |
| 630 | def addFailTest(self, name, change): |
| 631 | l = self.fail_tests.get(name, []) |
| 632 | l.append(change) |
| 633 | self.fail_tests[name] = l |
| 634 | |
| 635 | def shouldFailTest(self, name, ref): |
| 636 | l = self.fail_tests.get(name, []) |
| 637 | for change in l: |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 638 | if self.test.ref_has_change(ref, change): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 639 | return True |
| 640 | return False |
| 641 | |
| 642 | def release(self, regex=None): |
| 643 | builds = self.running_builds[:] |
| 644 | self.log.debug("releasing build %s (%s)" % (regex, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 645 | len(self.running_builds))) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 646 | for build in builds: |
| 647 | if not regex or re.match(regex, build.name): |
| 648 | self.log.debug("releasing build %s" % |
| 649 | (build.parameters['ZUUL_UUID'])) |
| 650 | build.release() |
| 651 | else: |
| 652 | self.log.debug("not releasing build %s" % |
| 653 | (build.parameters['ZUUL_UUID'])) |
| 654 | self.log.debug("done releasing builds %s (%s)" % |
| 655 | (regex, len(self.running_builds))) |
| 656 | |
| 657 | |
| 658 | class FakeGearmanServer(gear.Server): |
| 659 | def __init__(self): |
| 660 | self.hold_jobs_in_queue = False |
| 661 | super(FakeGearmanServer, self).__init__(0) |
| 662 | |
| 663 | def getJobForConnection(self, connection, peek=False): |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 664 | for queue in [self.high_queue, self.normal_queue, self.low_queue]: |
| 665 | for job in queue: |
| 666 | if not hasattr(job, 'waiting'): |
| 667 | if job.name.startswith('build:'): |
| 668 | job.waiting = self.hold_jobs_in_queue |
| 669 | else: |
| 670 | job.waiting = False |
| 671 | if job.waiting: |
| 672 | continue |
| 673 | if job.name in connection.functions: |
| 674 | if not peek: |
| 675 | queue.remove(job) |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 676 | connection.related_jobs[job.handle] = job |
| 677 | job.worker_connection = connection |
| 678 | job.running = True |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 679 | return job |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 680 | return None |
| 681 | |
| 682 | def release(self, regex=None): |
| 683 | released = False |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 684 | qlen = (len(self.high_queue) + len(self.normal_queue) + |
| 685 | len(self.low_queue)) |
| 686 | self.log.debug("releasing queued job %s (%s)" % (regex, qlen)) |
James E. Blair | dda6c91 | 2013-07-29 14:12:12 -0700 | [diff] [blame] | 687 | for job in self.getQueue(): |
| 688 | cmd, name = job.name.split(':') |
| 689 | if cmd != 'build': |
| 690 | continue |
| 691 | if not regex or re.match(regex, name): |
| 692 | self.log.debug("releasing queued job %s" % |
| 693 | job.unique) |
| 694 | job.waiting = False |
| 695 | released = True |
| 696 | else: |
| 697 | self.log.debug("not releasing queued job %s" % |
| 698 | job.unique) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 699 | if released: |
| 700 | self.wakeConnections() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 701 | qlen = (len(self.high_queue) + len(self.normal_queue) + |
| 702 | len(self.low_queue)) |
| 703 | self.log.debug("done releasing queued jobs %s (%s)" % (regex, qlen)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 704 | |
| 705 | |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 706 | class FakeSMTP(object): |
| 707 | log = logging.getLogger('zuul.FakeSMTP') |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 708 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 709 | def __init__(self, messages, server, port): |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 710 | self.server = server |
| 711 | self.port = port |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 712 | self.messages = messages |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 713 | |
| 714 | def sendmail(self, from_email, to_email, msg): |
| 715 | self.log.info("Sending email from %s, to %s, with msg %s" % ( |
| 716 | from_email, to_email, msg)) |
| 717 | |
| 718 | headers = msg.split('\n\n', 1)[0] |
| 719 | body = msg.split('\n\n', 1)[1] |
| 720 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 721 | self.messages.append(dict( |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 722 | from_email=from_email, |
| 723 | to_email=to_email, |
| 724 | msg=msg, |
| 725 | headers=headers, |
| 726 | body=body, |
| 727 | )) |
| 728 | |
| 729 | return True |
| 730 | |
| 731 | def quit(self): |
| 732 | return True |
| 733 | |
| 734 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 735 | class TestScheduler(testtools.TestCase): |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 736 | log = logging.getLogger("zuul.test") |
| 737 | |
| 738 | def setUp(self): |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 739 | super(TestScheduler, self).setUp() |
| 740 | test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) |
| 741 | try: |
| 742 | test_timeout = int(test_timeout) |
| 743 | except ValueError: |
| 744 | # If timeout value is invalid do not set a timeout. |
| 745 | test_timeout = 0 |
| 746 | if test_timeout > 0: |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 747 | self.useFixture(fixtures.Timeout(test_timeout, gentle=False)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 748 | |
| 749 | if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or |
| 750 | os.environ.get('OS_STDOUT_CAPTURE') == '1'): |
| 751 | stdout = self.useFixture(fixtures.StringStream('stdout')).stream |
| 752 | self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) |
| 753 | if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or |
| 754 | os.environ.get('OS_STDERR_CAPTURE') == '1'): |
| 755 | stderr = self.useFixture(fixtures.StringStream('stderr')).stream |
| 756 | self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) |
Monty Taylor | e6a6c40 | 2013-07-02 09:25:55 -0700 | [diff] [blame] | 757 | if (os.environ.get('OS_LOG_CAPTURE') == 'True' or |
| 758 | os.environ.get('OS_LOG_CAPTURE') == '1'): |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 759 | self.useFixture(fixtures.FakeLogger( |
| 760 | level=logging.DEBUG, |
| 761 | format='%(asctime)s %(name)-32s ' |
| 762 | '%(levelname)-8s %(message)s')) |
Monty Taylor | 5a5a95c | 2013-07-03 13:39:14 -0700 | [diff] [blame] | 763 | tmp_root = self.useFixture(fixtures.TempDir( |
| 764 | rootdir=os.environ.get("ZUUL_TEST_ROOT"))).path |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 765 | self.test_root = os.path.join(tmp_root, "zuul-test") |
| 766 | self.upstream_root = os.path.join(self.test_root, "upstream") |
| 767 | self.git_root = os.path.join(self.test_root, "git") |
| 768 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 769 | CONFIG.set('merger', 'git_dir', self.git_root) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 770 | if os.path.exists(self.test_root): |
| 771 | shutil.rmtree(self.test_root) |
| 772 | os.makedirs(self.test_root) |
| 773 | os.makedirs(self.upstream_root) |
| 774 | os.makedirs(self.git_root) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 775 | |
| 776 | # For each project in config: |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 777 | self.init_repo("org/project") |
| 778 | self.init_repo("org/project1") |
| 779 | self.init_repo("org/project2") |
| 780 | self.init_repo("org/project3") |
| 781 | self.init_repo("org/one-job-project") |
| 782 | self.init_repo("org/nonvoting-project") |
| 783 | self.init_repo("org/templated-project") |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 784 | self.init_repo("org/layered-project") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 785 | self.init_repo("org/node-project") |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 786 | self.init_repo("org/conflict-project") |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 787 | |
| 788 | self.statsd = FakeStatsd() |
| 789 | os.environ['STATSD_HOST'] = 'localhost' |
| 790 | os.environ['STATSD_PORT'] = str(self.statsd.port) |
| 791 | self.statsd.start() |
| 792 | # the statsd client object is configured in the statsd module import |
| 793 | reload(statsd) |
| 794 | reload(zuul.scheduler) |
| 795 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 796 | self.gearman_server = FakeGearmanServer() |
| 797 | |
| 798 | self.config = ConfigParser.ConfigParser() |
| 799 | cfg = StringIO() |
| 800 | CONFIG.write(cfg) |
| 801 | cfg.seek(0) |
| 802 | self.config.readfp(cfg) |
| 803 | self.config.set('gearman', 'port', str(self.gearman_server.port)) |
| 804 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 805 | self.worker = FakeWorker('fake_worker', self) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 806 | self.worker.addServer('127.0.0.1', self.gearman_server.port) |
| 807 | self.gearman_server.worker = self.worker |
| 808 | |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 809 | self.merge_server = zuul.merger.server.MergeServer(self.config) |
| 810 | self.merge_server.start() |
| 811 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 812 | self.sched = zuul.scheduler.Scheduler() |
| 813 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 814 | def URLOpenerFactory(*args, **kw): |
| 815 | args = [self.fake_gerrit] + list(args) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 816 | return FakeURLOpener(self.upstream_root, *args, **kw) |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 817 | |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 818 | urllib2.urlopen = URLOpenerFactory |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 819 | self.launcher = zuul.launcher.gearman.Gearman(self.config, self.sched) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 820 | self.merge_client = zuul.merger.client.MergeClient( |
| 821 | self.config, self.sched) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 822 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 823 | self.smtp_messages = [] |
| 824 | |
| 825 | def FakeSMTPFactory(*args, **kw): |
| 826 | args = [self.smtp_messages] + list(args) |
| 827 | return FakeSMTP(*args, **kw) |
| 828 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 829 | zuul.lib.gerrit.Gerrit = FakeGerrit |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 830 | self.useFixture(fixtures.MonkeyPatch('smtplib.SMTP', FakeSMTPFactory)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 831 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 832 | self.gerrit = FakeGerritTrigger( |
| 833 | self.upstream_root, self.config, self.sched) |
James E. Blair | 8cc15a8 | 2012-08-01 11:17:57 -0700 | [diff] [blame] | 834 | self.gerrit.replication_timeout = 1.5 |
| 835 | self.gerrit.replication_retry_interval = 0.5 |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 836 | self.fake_gerrit = self.gerrit.gerrit |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 837 | self.fake_gerrit.upstream_root = self.upstream_root |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 838 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 839 | self.webapp = zuul.webapp.WebApp(self.sched, port=0) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 840 | self.rpc = zuul.rpclistener.RPCListener(self.config, self.sched) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 841 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 842 | self.sched.setLauncher(self.launcher) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 843 | self.sched.setMerger(self.merge_client) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 844 | self.sched.registerTrigger(self.gerrit) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 845 | self.timer = zuul.trigger.timer.Timer(self.config, self.sched) |
| 846 | self.sched.registerTrigger(self.timer) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 847 | |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 848 | self.sched.registerReporter( |
| 849 | zuul.reporter.gerrit.Reporter(self.gerrit)) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 850 | self.smtp_reporter = zuul.reporter.smtp.Reporter( |
| 851 | self.config.get('smtp', 'default_from'), |
| 852 | self.config.get('smtp', 'default_to'), |
| 853 | self.config.get('smtp', 'server')) |
| 854 | self.sched.registerReporter(self.smtp_reporter) |
Joshua Hesketh | 1879cf7 | 2013-08-19 14:13:15 +1000 | [diff] [blame] | 855 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 856 | self.sched.start() |
| 857 | self.sched.reconfigure(self.config) |
| 858 | self.sched.resume() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 859 | self.webapp.start() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 860 | self.rpc.start() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 861 | self.launcher.gearman.waitForServer() |
| 862 | self.registerJobs() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 863 | self.builds = self.worker.running_builds |
| 864 | self.history = self.worker.build_history |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 865 | |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 866 | self.addCleanup(self.assertFinalState) |
| 867 | self.addCleanup(self.shutdown) |
| 868 | |
| 869 | def assertFinalState(self): |
| 870 | # Make sure that the change cache is cleared |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 871 | self.assertEqual(len(self.gerrit._change_cache.keys()), 0) |
Clark Boylan | 4ba48d9 | 2013-11-11 18:03:53 -0800 | [diff] [blame] | 872 | # Make sure that git.Repo objects have been garbage collected. |
| 873 | repos = [] |
| 874 | gc.collect() |
| 875 | for obj in gc.get_objects(): |
| 876 | if isinstance(obj, git.Repo): |
| 877 | repos.append(obj) |
| 878 | self.assertEqual(len(repos), 0) |
James E. Blair | fee8d65 | 2013-06-07 08:57:52 -0700 | [diff] [blame] | 879 | self.assertEmptyQueues() |
| 880 | |
| 881 | def shutdown(self): |
| 882 | self.log.debug("Shutting down after tests") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 883 | self.launcher.stop() |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 884 | self.merge_server.stop() |
| 885 | self.merge_server.join() |
| 886 | self.merge_client.stop() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 887 | self.worker.shutdown() |
| 888 | self.gearman_server.shutdown() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 889 | self.gerrit.stop() |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 890 | self.timer.stop() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 891 | self.sched.stop() |
| 892 | self.sched.join() |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 893 | self.statsd.stop() |
| 894 | self.statsd.join() |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 895 | self.webapp.stop() |
| 896 | self.webapp.join() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 897 | self.rpc.stop() |
| 898 | self.rpc.join() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 899 | threads = threading.enumerate() |
| 900 | if len(threads) > 1: |
| 901 | self.log.error("More than one thread is running: %s" % threads) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 902 | super(TestScheduler, self).tearDown() |
| 903 | |
| 904 | def init_repo(self, project): |
| 905 | parts = project.split('/') |
| 906 | path = os.path.join(self.upstream_root, *parts[:-1]) |
| 907 | if not os.path.exists(path): |
| 908 | os.makedirs(path) |
| 909 | path = os.path.join(self.upstream_root, project) |
| 910 | repo = git.Repo.init(path) |
| 911 | |
| 912 | repo.config_writer().set_value('user', 'email', 'user@example.com') |
| 913 | repo.config_writer().set_value('user', 'name', 'User Name') |
| 914 | repo.config_writer().write() |
| 915 | |
| 916 | fn = os.path.join(path, 'README') |
| 917 | f = open(fn, 'w') |
| 918 | f.write("test\n") |
| 919 | f.close() |
| 920 | repo.index.add([fn]) |
| 921 | repo.index.commit('initial commit') |
| 922 | master = repo.create_head('master') |
| 923 | repo.create_tag('init') |
| 924 | |
| 925 | mp = repo.create_head('mp') |
| 926 | repo.head.reference = mp |
| 927 | f = open(fn, 'a') |
| 928 | f.write("test mp\n") |
| 929 | f.close() |
| 930 | repo.index.add([fn]) |
| 931 | repo.index.commit('mp commit') |
| 932 | |
| 933 | repo.head.reference = master |
| 934 | repo.head.reset(index=True, working_tree=True) |
| 935 | repo.git.clean('-x', '-f', '-d') |
| 936 | |
| 937 | def ref_has_change(self, ref, change): |
| 938 | path = os.path.join(self.git_root, change.project) |
| 939 | repo = git.Repo(path) |
| 940 | for commit in repo.iter_commits(ref): |
| 941 | if commit.message.strip() == ('%s-1' % change.subject): |
| 942 | return True |
| 943 | return False |
| 944 | |
| 945 | def job_has_changes(self, *args): |
| 946 | job = args[0] |
| 947 | commits = args[1:] |
| 948 | if isinstance(job, FakeBuild): |
| 949 | parameters = job.parameters |
| 950 | else: |
| 951 | parameters = json.loads(job.arguments) |
| 952 | project = parameters['ZUUL_PROJECT'] |
| 953 | path = os.path.join(self.git_root, project) |
| 954 | repo = git.Repo(path) |
| 955 | ref = parameters['ZUUL_REF'] |
| 956 | sha = parameters['ZUUL_COMMIT'] |
| 957 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 958 | repo_shas = [c.hexsha for c in repo.iter_commits(ref)] |
| 959 | commit_messages = ['%s-1' % commit.subject for commit in commits] |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 960 | self.log.debug("Checking if job %s has changes; commit_messages %s;" |
| 961 | " repo_messages %s; sha %s" % (job, commit_messages, |
| 962 | repo_messages, sha)) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 963 | for msg in commit_messages: |
| 964 | if msg not in repo_messages: |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 965 | self.log.debug(" messages do not match") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 966 | return False |
| 967 | if repo_shas[0] != sha: |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 968 | self.log.debug(" sha does not match") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 969 | return False |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 970 | self.log.debug(" OK") |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 971 | return True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 972 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 973 | def registerJobs(self): |
| 974 | count = 0 |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 975 | for job in self.sched.layout.jobs.keys(): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 976 | self.worker.registerFunction('build:' + job) |
| 977 | count += 1 |
| 978 | self.worker.registerFunction('stop:' + self.worker.worker_id) |
| 979 | count += 1 |
| 980 | |
| 981 | while len(self.gearman_server.functions) < count: |
| 982 | time.sleep(0) |
| 983 | |
| 984 | def release(self, job): |
| 985 | if isinstance(job, FakeBuild): |
| 986 | job.release() |
| 987 | else: |
| 988 | job.waiting = False |
| 989 | self.log.debug("Queued job %s released" % job.unique) |
| 990 | self.gearman_server.wakeConnections() |
| 991 | |
| 992 | def getParameter(self, job, name): |
| 993 | if isinstance(job, FakeBuild): |
| 994 | return job.parameters[name] |
| 995 | else: |
| 996 | parameters = json.loads(job.arguments) |
| 997 | return parameters[name] |
| 998 | |
| 999 | def resetGearmanServer(self): |
| 1000 | self.worker.setFunctions([]) |
| 1001 | while True: |
| 1002 | done = True |
| 1003 | for connection in self.gearman_server.active_connections: |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1004 | if (connection.functions and |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 1005 | connection.client_id not in ['Zuul RPC Listener', |
| 1006 | 'Zuul Merger']): |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1007 | done = False |
| 1008 | if done: |
| 1009 | break |
| 1010 | time.sleep(0) |
| 1011 | self.gearman_server.functions = set() |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 1012 | self.rpc.register() |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 1013 | self.merge_server.register() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1014 | |
| 1015 | def haveAllBuildsReported(self): |
| 1016 | # See if Zuul is waiting on a meta job to complete |
| 1017 | if self.launcher.meta_jobs: |
| 1018 | return False |
| 1019 | # Find out if every build that the worker has completed has been |
| 1020 | # reported back to Zuul. If it hasn't then that means a Gearman |
| 1021 | # event is still in transit and the system is not stable. |
| 1022 | for build in self.worker.build_history: |
| 1023 | zbuild = self.launcher.builds.get(build.uuid) |
| 1024 | if not zbuild: |
| 1025 | # It has already been reported |
| 1026 | continue |
| 1027 | # It hasn't been reported yet. |
| 1028 | return False |
| 1029 | # Make sure that none of the worker connections are in GRAB_WAIT |
| 1030 | for connection in self.worker.active_connections: |
| 1031 | if connection.state == 'GRAB_WAIT': |
| 1032 | return False |
| 1033 | return True |
| 1034 | |
| 1035 | def areAllBuildsWaiting(self): |
| 1036 | ret = True |
| 1037 | |
| 1038 | builds = self.launcher.builds.values() |
| 1039 | for build in builds: |
| 1040 | client_job = None |
| 1041 | for conn in self.launcher.gearman.active_connections: |
| 1042 | for j in conn.related_jobs.values(): |
| 1043 | if j.unique == build.uuid: |
| 1044 | client_job = j |
| 1045 | break |
| 1046 | if not client_job: |
| 1047 | self.log.debug("%s is not known to the gearman client" % |
| 1048 | build) |
| 1049 | ret = False |
| 1050 | continue |
| 1051 | if not client_job.handle: |
| 1052 | self.log.debug("%s has no handle" % client_job) |
| 1053 | ret = False |
| 1054 | continue |
| 1055 | server_job = self.gearman_server.jobs.get(client_job.handle) |
| 1056 | if not server_job: |
| 1057 | self.log.debug("%s is not known to the gearman server" % |
| 1058 | client_job) |
| 1059 | ret = False |
| 1060 | continue |
| 1061 | if not hasattr(server_job, 'waiting'): |
| 1062 | self.log.debug("%s is being enqueued" % server_job) |
| 1063 | ret = False |
| 1064 | continue |
| 1065 | if server_job.waiting: |
| 1066 | continue |
| 1067 | worker_job = self.worker.gearman_jobs.get(server_job.unique) |
| 1068 | if worker_job: |
| 1069 | if worker_job.build.isWaiting(): |
| 1070 | continue |
| 1071 | else: |
| 1072 | self.log.debug("%s is running" % worker_job) |
| 1073 | ret = False |
| 1074 | else: |
| 1075 | self.log.debug("%s is unassigned" % server_job) |
| 1076 | ret = False |
| 1077 | return ret |
| 1078 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1079 | def waitUntilSettled(self): |
| 1080 | self.log.debug("Waiting until settled...") |
| 1081 | start = time.time() |
| 1082 | while True: |
| 1083 | if time.time() - start > 10: |
| 1084 | print 'queue status:', |
| 1085 | print self.sched.trigger_event_queue.empty(), |
| 1086 | print self.sched.result_event_queue.empty(), |
| 1087 | print self.fake_gerrit.event_queue.empty(), |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1088 | print self.areAllBuildsWaiting() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1089 | raise Exception("Timeout waiting for Zuul to settle") |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1090 | # Make sure no new events show up while we're checking |
| 1091 | self.worker.lock.acquire() |
| 1092 | # have all build states propogated to zuul? |
| 1093 | if self.haveAllBuildsReported(): |
| 1094 | # Join ensures that the queue is empty _and_ events have been |
| 1095 | # processed |
| 1096 | self.fake_gerrit.event_queue.join() |
| 1097 | self.sched.trigger_event_queue.join() |
| 1098 | self.sched.result_event_queue.join() |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1099 | self.sched.run_handler_lock.acquire() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1100 | if (self.sched.trigger_event_queue.empty() and |
| 1101 | self.sched.result_event_queue.empty() and |
| 1102 | self.fake_gerrit.event_queue.empty() and |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 1103 | not self.merge_client.build_sets and |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1104 | self.areAllBuildsWaiting()): |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1105 | self.sched.run_handler_lock.release() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1106 | self.worker.lock.release() |
| 1107 | self.log.debug("...settled.") |
| 1108 | return |
James E. Blair | a84f0e4 | 2014-02-06 07:09:22 -0800 | [diff] [blame] | 1109 | self.sched.run_handler_lock.release() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1110 | self.worker.lock.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1111 | self.sched.wake_event.wait(0.1) |
| 1112 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1113 | def countJobResults(self, jobs, result): |
James E. Blair | 0018a6c | 2013-02-27 14:11:45 -0800 | [diff] [blame] | 1114 | jobs = filter(lambda x: x.result == result, jobs) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1115 | return len(jobs) |
| 1116 | |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 1117 | def getJobFromHistory(self, name): |
| 1118 | history = self.worker.build_history |
| 1119 | for job in history: |
| 1120 | if job.name == name: |
| 1121 | return job |
| 1122 | raise Exception("Unable to find job %s in history" % name) |
| 1123 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1124 | def assertEmptyQueues(self): |
| 1125 | # Make sure there are no orphaned jobs |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1126 | for pipeline in self.sched.layout.pipelines.values(): |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1127 | for queue in pipeline.queues: |
| 1128 | if len(queue.queue) != 0: |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 1129 | print 'pipeline %s queue %s contents %s' % ( |
| 1130 | pipeline.name, queue.name, queue.queue) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1131 | self.assertEqual(len(queue.queue), 0) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 1132 | |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1133 | def assertReportedStat(self, key, value=None, kind=None): |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1134 | start = time.time() |
| 1135 | while time.time() < (start + 5): |
| 1136 | for stat in self.statsd.stats: |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1137 | pprint.pprint(self.statsd.stats) |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1138 | k, v = stat.split(':') |
| 1139 | if key == k: |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1140 | if value is None and kind is None: |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1141 | return |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1142 | elif value: |
| 1143 | if value == v: |
| 1144 | return |
| 1145 | elif kind: |
| 1146 | if v.endswith('|' + kind): |
| 1147 | return |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1148 | time.sleep(0.1) |
| 1149 | |
| 1150 | pprint.pprint(self.statsd.stats) |
| 1151 | raise Exception("Key %s not found in reported stats" % key) |
| 1152 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1153 | def test_jobs_launched(self): |
| 1154 | "Test that jobs are launched and a change is merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1155 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1156 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1157 | A.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1158 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1159 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1160 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 1161 | 'SUCCESS') |
| 1162 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 1163 | 'SUCCESS') |
| 1164 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 1165 | 'SUCCESS') |
| 1166 | self.assertEqual(A.data['status'], 'MERGED') |
| 1167 | self.assertEqual(A.reported, 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1168 | |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1169 | self.assertReportedStat('gerrit.event.comment-added', value='1|c') |
| 1170 | self.assertReportedStat('zuul.pipeline.gate.current_changes', |
| 1171 | value='1|g') |
| 1172 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 1173 | kind='ms') |
| 1174 | self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', |
| 1175 | value='1|c') |
| 1176 | self.assertReportedStat('zuul.pipeline.gate.resident_time', kind='ms') |
| 1177 | self.assertReportedStat('zuul.pipeline.gate.total_changes', |
| 1178 | value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1179 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1180 | 'zuul.pipeline.gate.org.project.resident_time', kind='ms') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1181 | self.assertReportedStat( |
James E. Blair | 66eeebf | 2013-07-27 17:44:32 -0700 | [diff] [blame] | 1182 | 'zuul.pipeline.gate.org.project.total_changes', value='1|c') |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 1183 | |
James E. Blair | 3cb1070 | 2013-08-24 08:56:03 -0700 | [diff] [blame] | 1184 | def test_initial_pipeline_gauges(self): |
| 1185 | "Test that each pipeline reported its length on start" |
| 1186 | pipeline_names = self.sched.layout.pipelines.keys() |
| 1187 | self.assertNotEqual(len(pipeline_names), 0) |
| 1188 | for name in pipeline_names: |
| 1189 | self.assertReportedStat('zuul.pipeline.%s.current_changes' % name, |
| 1190 | value='0|g') |
| 1191 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1192 | def test_duplicate_pipelines(self): |
| 1193 | "Test that a change matching multiple pipelines works" |
James E. Blair | 1b4d972 | 2013-05-21 10:32:04 -0700 | [diff] [blame] | 1194 | |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1195 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1196 | self.fake_gerrit.addEvent(A.getChangeRestoredEvent()) |
| 1197 | self.waitUntilSettled() |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1198 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1199 | self.assertEqual(len(self.history), 2) |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1200 | self.history[0].name == 'project-test1' |
| 1201 | self.history[1].name == 'project-test1' |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1202 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1203 | self.assertEqual(len(A.messages), 2) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1204 | if 'dup1/project-test1' in A.messages[0]: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1205 | self.assertIn('dup1/project-test1', A.messages[0]) |
| 1206 | self.assertNotIn('dup2/project-test1', A.messages[0]) |
| 1207 | self.assertNotIn('dup1/project-test1', A.messages[1]) |
| 1208 | self.assertIn('dup2/project-test1', A.messages[1]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1209 | else: |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1210 | self.assertIn('dup1/project-test1', A.messages[1]) |
| 1211 | self.assertNotIn('dup2/project-test1', A.messages[1]) |
| 1212 | self.assertNotIn('dup1/project-test1', A.messages[0]) |
| 1213 | self.assertIn('dup2/project-test1', A.messages[0]) |
James E. Blair | 42f7482 | 2013-05-14 15:18:03 -0700 | [diff] [blame] | 1214 | |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1215 | def test_parallel_changes(self): |
| 1216 | "Test that changes are tested in parallel and merged in series" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1217 | |
| 1218 | self.worker.hold_jobs_in_build = True |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1219 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1220 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1221 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1222 | A.addApproval('CRVW', 2) |
| 1223 | B.addApproval('CRVW', 2) |
| 1224 | C.addApproval('CRVW', 2) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1225 | |
| 1226 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1227 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1228 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1229 | |
| 1230 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1231 | self.assertEqual(len(self.builds), 1) |
| 1232 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1233 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1234 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1235 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1236 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1237 | self.assertEqual(len(self.builds), 3) |
| 1238 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1239 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1240 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1241 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 1242 | self.assertEqual(self.builds[2].name, 'project-merge') |
| 1243 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1244 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1245 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1246 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1247 | self.assertEqual(len(self.builds), 5) |
| 1248 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1249 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1250 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1251 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1252 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1253 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1254 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 1255 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1256 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1257 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1258 | self.assertEqual(self.builds[4].name, 'project-merge') |
| 1259 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1260 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1261 | self.worker.release('.*-merge') |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1262 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1263 | self.assertEqual(len(self.builds), 6) |
| 1264 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1265 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1266 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1267 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1268 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1269 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1270 | self.assertTrue(self.job_has_changes(self.builds[2], A, B)) |
| 1271 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1272 | self.assertTrue(self.job_has_changes(self.builds[3], A, B)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1273 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1274 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1275 | self.assertTrue(self.job_has_changes(self.builds[4], A, B, C)) |
| 1276 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1277 | self.assertTrue(self.job_has_changes(self.builds[5], A, B, C)) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1278 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1279 | self.worker.hold_jobs_in_build = False |
| 1280 | self.worker.release() |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1281 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1282 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b0fcae4 | 2012-07-17 11:12:10 -0700 | [diff] [blame] | 1283 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1284 | self.assertEqual(len(self.history), 9) |
| 1285 | self.assertEqual(A.data['status'], 'MERGED') |
| 1286 | self.assertEqual(B.data['status'], 'MERGED') |
| 1287 | self.assertEqual(C.data['status'], 'MERGED') |
| 1288 | self.assertEqual(A.reported, 2) |
| 1289 | self.assertEqual(B.reported, 2) |
| 1290 | self.assertEqual(C.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1291 | |
| 1292 | def test_failed_changes(self): |
| 1293 | "Test that a change behind a failed change is retested" |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1294 | self.worker.hold_jobs_in_build = True |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1295 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1296 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1297 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1298 | A.addApproval('CRVW', 2) |
| 1299 | B.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1300 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1301 | self.worker.addFailTest('project-test1', A) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1302 | |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1303 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1304 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1305 | self.waitUntilSettled() |
James E. Blair | e281901 | 2013-06-28 17:17:26 -0400 | [diff] [blame] | 1306 | |
| 1307 | self.worker.release('.*-merge') |
| 1308 | self.waitUntilSettled() |
| 1309 | |
| 1310 | self.worker.hold_jobs_in_build = False |
| 1311 | self.worker.release() |
| 1312 | |
| 1313 | self.waitUntilSettled() |
| 1314 | # It's certain that the merge job for change 2 will run, but |
| 1315 | # the test1 and test2 jobs may or may not run. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1316 | self.assertTrue(len(self.history) > 6) |
| 1317 | self.assertEqual(A.data['status'], 'NEW') |
| 1318 | self.assertEqual(B.data['status'], 'MERGED') |
| 1319 | self.assertEqual(A.reported, 2) |
| 1320 | self.assertEqual(B.reported, 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1321 | |
| 1322 | def test_independent_queues(self): |
| 1323 | "Test that changes end up in the right queues" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1324 | |
| 1325 | self.worker.hold_jobs_in_build = True |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1326 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1327 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 1328 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1329 | A.addApproval('CRVW', 2) |
| 1330 | B.addApproval('CRVW', 2) |
| 1331 | C.addApproval('CRVW', 2) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1332 | |
| 1333 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1334 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1335 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1336 | |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1337 | self.waitUntilSettled() |
| 1338 | |
| 1339 | # There should be one merge job at the head of each queue running |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1340 | self.assertEqual(len(self.builds), 2) |
| 1341 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1342 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1343 | self.assertEqual(self.builds[1].name, 'project1-merge') |
| 1344 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1345 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1346 | # Release the current merge builds |
| 1347 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1348 | self.waitUntilSettled() |
| 1349 | # Release the merge job for project2 which is behind project1 |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1350 | self.worker.release('.*-merge') |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1351 | self.waitUntilSettled() |
| 1352 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1353 | # All the test builds should be running: |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1354 | # project1 (3) + project2 (3) + project (2) = 8 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1355 | self.assertEqual(len(self.builds), 8) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1356 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1357 | self.worker.release() |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1358 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1359 | self.assertEqual(len(self.builds), 0) |
James E. Blair | b02a3bb | 2012-07-30 17:49:55 -0700 | [diff] [blame] | 1360 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1361 | self.assertEqual(len(self.history), 11) |
| 1362 | self.assertEqual(A.data['status'], 'MERGED') |
| 1363 | self.assertEqual(B.data['status'], 'MERGED') |
| 1364 | self.assertEqual(C.data['status'], 'MERGED') |
| 1365 | self.assertEqual(A.reported, 2) |
| 1366 | self.assertEqual(B.reported, 2) |
| 1367 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1368 | |
| 1369 | def test_failed_change_at_head(self): |
| 1370 | "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] | 1371 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1372 | self.worker.hold_jobs_in_build = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1373 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1374 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1375 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1376 | A.addApproval('CRVW', 2) |
| 1377 | B.addApproval('CRVW', 2) |
| 1378 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1379 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1380 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1381 | |
| 1382 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1383 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1384 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1385 | |
| 1386 | self.waitUntilSettled() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1387 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1388 | self.assertEqual(len(self.builds), 1) |
| 1389 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 1390 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1391 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1392 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1393 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1394 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1395 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1396 | self.worker.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1397 | self.waitUntilSettled() |
| 1398 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1399 | self.assertEqual(len(self.builds), 6) |
| 1400 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1401 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1402 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1403 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1404 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1405 | self.assertEqual(self.builds[5].name, 'project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1406 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1407 | self.release(self.builds[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1408 | self.waitUntilSettled() |
| 1409 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1410 | # project-test2, project-merge for B |
| 1411 | self.assertEqual(len(self.builds), 2) |
| 1412 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 4) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1413 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1414 | self.worker.hold_jobs_in_build = False |
| 1415 | self.worker.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1416 | self.waitUntilSettled() |
| 1417 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1418 | self.assertEqual(len(self.builds), 0) |
| 1419 | self.assertEqual(len(self.history), 15) |
| 1420 | self.assertEqual(A.data['status'], 'NEW') |
| 1421 | self.assertEqual(B.data['status'], 'MERGED') |
| 1422 | self.assertEqual(C.data['status'], 'MERGED') |
| 1423 | self.assertEqual(A.reported, 2) |
| 1424 | self.assertEqual(B.reported, 2) |
| 1425 | self.assertEqual(C.reported, 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1426 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1427 | def test_failed_change_in_middle(self): |
| 1428 | "Test a failed change in the middle of the queue" |
| 1429 | |
| 1430 | self.worker.hold_jobs_in_build = True |
| 1431 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1432 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1433 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1434 | A.addApproval('CRVW', 2) |
| 1435 | B.addApproval('CRVW', 2) |
| 1436 | C.addApproval('CRVW', 2) |
| 1437 | |
| 1438 | self.worker.addFailTest('project-test1', B) |
| 1439 | |
| 1440 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1441 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1442 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1443 | |
| 1444 | self.waitUntilSettled() |
| 1445 | |
| 1446 | self.worker.release('.*-merge') |
| 1447 | self.waitUntilSettled() |
| 1448 | self.worker.release('.*-merge') |
| 1449 | self.waitUntilSettled() |
| 1450 | self.worker.release('.*-merge') |
| 1451 | self.waitUntilSettled() |
| 1452 | |
| 1453 | self.assertEqual(len(self.builds), 6) |
| 1454 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1455 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1456 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1457 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1458 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1459 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1460 | |
| 1461 | self.release(self.builds[2]) |
| 1462 | self.waitUntilSettled() |
| 1463 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1464 | # project-test1 and project-test2 for A |
| 1465 | # project-test2 for B |
| 1466 | # project-merge for C (without B) |
| 1467 | self.assertEqual(len(self.builds), 4) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1468 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 2) |
| 1469 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1470 | self.worker.release('.*-merge') |
| 1471 | self.waitUntilSettled() |
| 1472 | |
| 1473 | # project-test1 and project-test2 for A |
| 1474 | # project-test2 for B |
| 1475 | # project-test1 and project-test2 for C |
| 1476 | self.assertEqual(len(self.builds), 5) |
| 1477 | |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1478 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 1479 | builds = items[0].current_build_set.getBuilds() |
| 1480 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 1481 | self.assertEqual(self.countJobResults(builds, None), 2) |
| 1482 | builds = items[1].current_build_set.getBuilds() |
| 1483 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
| 1484 | self.assertEqual(self.countJobResults(builds, 'FAILURE'), 1) |
| 1485 | self.assertEqual(self.countJobResults(builds, None), 1) |
| 1486 | builds = items[2].current_build_set.getBuilds() |
| 1487 | self.assertEqual(self.countJobResults(builds, 'SUCCESS'), 1) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1488 | self.assertEqual(self.countJobResults(builds, None), 2) |
James E. Blair | 0aac487 | 2013-08-23 14:02:38 -0700 | [diff] [blame] | 1489 | |
| 1490 | self.worker.hold_jobs_in_build = False |
| 1491 | self.worker.release() |
| 1492 | self.waitUntilSettled() |
| 1493 | |
| 1494 | self.assertEqual(len(self.builds), 0) |
| 1495 | self.assertEqual(len(self.history), 12) |
| 1496 | self.assertEqual(A.data['status'], 'MERGED') |
| 1497 | self.assertEqual(B.data['status'], 'NEW') |
| 1498 | self.assertEqual(C.data['status'], 'MERGED') |
| 1499 | self.assertEqual(A.reported, 2) |
| 1500 | self.assertEqual(B.reported, 2) |
| 1501 | self.assertEqual(C.reported, 2) |
| 1502 | |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1503 | def test_failed_change_at_head_with_queue(self): |
| 1504 | "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] | 1505 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1506 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1507 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1508 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1509 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1510 | A.addApproval('CRVW', 2) |
| 1511 | B.addApproval('CRVW', 2) |
| 1512 | C.addApproval('CRVW', 2) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1513 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1514 | self.worker.addFailTest('project-test1', A) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1515 | |
| 1516 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1517 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1518 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1519 | |
| 1520 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1521 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1522 | self.assertEqual(len(self.builds), 0) |
| 1523 | self.assertEqual(len(queue), 1) |
| 1524 | self.assertEqual(queue[0].name, 'build:project-merge') |
| 1525 | self.assertTrue(self.job_has_changes(queue[0], A)) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1526 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1527 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1528 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1529 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1530 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1531 | self.gearman_server.release('.*-merge') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1532 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1533 | queue = self.gearman_server.getQueue() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1534 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1535 | self.assertEqual(len(self.builds), 0) |
| 1536 | self.assertEqual(len(queue), 6) |
| 1537 | self.assertEqual(queue[0].name, 'build:project-test1') |
| 1538 | self.assertEqual(queue[1].name, 'build:project-test2') |
| 1539 | self.assertEqual(queue[2].name, 'build:project-test1') |
| 1540 | self.assertEqual(queue[3].name, 'build:project-test2') |
| 1541 | self.assertEqual(queue[4].name, 'build:project-test1') |
| 1542 | self.assertEqual(queue[5].name, 'build:project-test2') |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1543 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1544 | self.release(queue[0]) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1545 | self.waitUntilSettled() |
| 1546 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1547 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1548 | queue = self.gearman_server.getQueue() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1549 | self.assertEqual(len(queue), 2) # project-test2, project-merge for B |
| 1550 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 0) |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1551 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1552 | self.gearman_server.hold_jobs_in_queue = False |
| 1553 | self.gearman_server.release() |
James E. Blair | d466dc4 | 2012-07-31 10:42:56 -0700 | [diff] [blame] | 1554 | self.waitUntilSettled() |
| 1555 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1556 | self.assertEqual(len(self.builds), 0) |
| 1557 | self.assertEqual(len(self.history), 11) |
| 1558 | self.assertEqual(A.data['status'], 'NEW') |
| 1559 | self.assertEqual(B.data['status'], 'MERGED') |
| 1560 | self.assertEqual(C.data['status'], 'MERGED') |
| 1561 | self.assertEqual(A.reported, 2) |
| 1562 | self.assertEqual(B.reported, 2) |
| 1563 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1564 | |
James E. Blair | fef7163 | 2013-09-23 11:15:47 -0700 | [diff] [blame] | 1565 | def test_two_failed_changes_at_head(self): |
| 1566 | "Test that changes are reparented correctly if 2 fail at head" |
| 1567 | |
| 1568 | self.worker.hold_jobs_in_build = True |
| 1569 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1570 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1571 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1572 | A.addApproval('CRVW', 2) |
| 1573 | B.addApproval('CRVW', 2) |
| 1574 | C.addApproval('CRVW', 2) |
| 1575 | |
| 1576 | self.worker.addFailTest('project-test1', A) |
| 1577 | self.worker.addFailTest('project-test1', B) |
| 1578 | |
| 1579 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1580 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1581 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1582 | self.waitUntilSettled() |
| 1583 | |
| 1584 | self.worker.release('.*-merge') |
| 1585 | self.waitUntilSettled() |
| 1586 | self.worker.release('.*-merge') |
| 1587 | self.waitUntilSettled() |
| 1588 | self.worker.release('.*-merge') |
| 1589 | self.waitUntilSettled() |
| 1590 | |
| 1591 | self.assertEqual(len(self.builds), 6) |
| 1592 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1593 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1594 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 1595 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 1596 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 1597 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 1598 | |
| 1599 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
| 1600 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 1601 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1602 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 1603 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 1604 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 1605 | |
| 1606 | # Fail change B first |
| 1607 | self.release(self.builds[2]) |
| 1608 | self.waitUntilSettled() |
| 1609 | |
| 1610 | # restart of C after B failure |
| 1611 | self.worker.release('.*-merge') |
| 1612 | self.waitUntilSettled() |
| 1613 | |
| 1614 | self.assertEqual(len(self.builds), 5) |
| 1615 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 1616 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 1617 | self.assertEqual(self.builds[2].name, 'project-test2') |
| 1618 | self.assertEqual(self.builds[3].name, 'project-test1') |
| 1619 | self.assertEqual(self.builds[4].name, 'project-test2') |
| 1620 | |
| 1621 | self.assertTrue(self.job_has_changes(self.builds[1], A)) |
| 1622 | self.assertTrue(self.job_has_changes(self.builds[2], A)) |
| 1623 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1624 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 1625 | self.assertFalse(self.job_has_changes(self.builds[4], B)) |
| 1626 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 1627 | |
| 1628 | # Finish running all passing jobs for change A |
| 1629 | self.release(self.builds[1]) |
| 1630 | self.waitUntilSettled() |
| 1631 | # Fail and report change A |
| 1632 | self.release(self.builds[0]) |
| 1633 | self.waitUntilSettled() |
| 1634 | |
| 1635 | # restart of B,C after A failure |
| 1636 | self.worker.release('.*-merge') |
| 1637 | self.waitUntilSettled() |
| 1638 | self.worker.release('.*-merge') |
| 1639 | self.waitUntilSettled() |
| 1640 | |
| 1641 | self.assertEqual(len(self.builds), 4) |
| 1642 | self.assertEqual(self.builds[0].name, 'project-test1') # B |
| 1643 | self.assertEqual(self.builds[1].name, 'project-test2') # B |
| 1644 | self.assertEqual(self.builds[2].name, 'project-test1') # C |
| 1645 | self.assertEqual(self.builds[3].name, 'project-test2') # C |
| 1646 | |
| 1647 | self.assertFalse(self.job_has_changes(self.builds[1], A)) |
| 1648 | self.assertTrue(self.job_has_changes(self.builds[1], B)) |
| 1649 | self.assertFalse(self.job_has_changes(self.builds[1], C)) |
| 1650 | |
| 1651 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 1652 | # After A failed and B and C restarted, B should be back in |
| 1653 | # C's tests because it has not failed yet. |
| 1654 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 1655 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 1656 | |
| 1657 | self.worker.hold_jobs_in_build = False |
| 1658 | self.worker.release() |
| 1659 | self.waitUntilSettled() |
| 1660 | |
| 1661 | self.assertEqual(len(self.builds), 0) |
| 1662 | self.assertEqual(len(self.history), 21) |
| 1663 | self.assertEqual(A.data['status'], 'NEW') |
| 1664 | self.assertEqual(B.data['status'], 'NEW') |
| 1665 | self.assertEqual(C.data['status'], 'MERGED') |
| 1666 | self.assertEqual(A.reported, 2) |
| 1667 | self.assertEqual(B.reported, 2) |
| 1668 | self.assertEqual(C.reported, 2) |
| 1669 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1670 | def test_patch_order(self): |
| 1671 | "Test that dependent patches are tested in the right order" |
| 1672 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1673 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1674 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1675 | A.addApproval('CRVW', 2) |
| 1676 | B.addApproval('CRVW', 2) |
| 1677 | C.addApproval('CRVW', 2) |
| 1678 | |
| 1679 | M2 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M2') |
| 1680 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1681 | M2.setMerged() |
| 1682 | M1.setMerged() |
| 1683 | |
| 1684 | # C -> B -> A -> M1 -> M2 |
| 1685 | # M2 is here to make sure it is never queried. If it is, it |
| 1686 | # means zuul is walking down the entire history of merged |
| 1687 | # changes. |
| 1688 | |
| 1689 | C.setDependsOn(B, 1) |
| 1690 | B.setDependsOn(A, 1) |
| 1691 | A.setDependsOn(M1, 1) |
| 1692 | M1.setDependsOn(M2, 1) |
| 1693 | |
| 1694 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1695 | |
| 1696 | self.waitUntilSettled() |
| 1697 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1698 | self.assertEqual(A.data['status'], 'NEW') |
| 1699 | self.assertEqual(B.data['status'], 'NEW') |
| 1700 | self.assertEqual(C.data['status'], 'NEW') |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1701 | |
| 1702 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1703 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1704 | |
| 1705 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1706 | self.assertEqual(M2.queried, 0) |
| 1707 | self.assertEqual(A.data['status'], 'MERGED') |
| 1708 | self.assertEqual(B.data['status'], 'MERGED') |
| 1709 | self.assertEqual(C.data['status'], 'MERGED') |
| 1710 | self.assertEqual(A.reported, 2) |
| 1711 | self.assertEqual(B.reported, 2) |
| 1712 | self.assertEqual(C.reported, 2) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1713 | |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1714 | def test_trigger_cache(self): |
| 1715 | "Test that the trigger cache operates correctly" |
| 1716 | self.worker.hold_jobs_in_build = True |
| 1717 | |
| 1718 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1719 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1720 | X = self.fake_gerrit.addFakeChange('org/project', 'master', 'X') |
| 1721 | A.addApproval('CRVW', 2) |
| 1722 | B.addApproval('CRVW', 2) |
| 1723 | |
| 1724 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 1725 | M1.setMerged() |
| 1726 | |
| 1727 | B.setDependsOn(A, 1) |
| 1728 | A.setDependsOn(M1, 1) |
| 1729 | |
| 1730 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1731 | self.fake_gerrit.addEvent(X.getPatchsetCreatedEvent(1)) |
| 1732 | |
| 1733 | self.waitUntilSettled() |
| 1734 | |
| 1735 | for build in self.builds: |
| 1736 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 1737 | build.release() |
| 1738 | self.waitUntilSettled() |
| 1739 | for build in self.builds: |
| 1740 | if build.parameters['ZUUL_PIPELINE'] == 'check': |
| 1741 | build.release() |
| 1742 | self.waitUntilSettled() |
| 1743 | |
| 1744 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1745 | self.waitUntilSettled() |
| 1746 | |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1747 | self.log.debug("len %s " % self.gerrit._change_cache.keys()) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1748 | # there should still be changes in the cache |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1749 | self.assertNotEqual(len(self.gerrit._change_cache.keys()), 0) |
James E. Blair | 0e933c5 | 2013-07-11 10:18:52 -0700 | [diff] [blame] | 1750 | |
| 1751 | self.worker.hold_jobs_in_build = False |
| 1752 | self.worker.release() |
| 1753 | self.waitUntilSettled() |
| 1754 | |
| 1755 | self.assertEqual(A.data['status'], 'MERGED') |
| 1756 | self.assertEqual(B.data['status'], 'MERGED') |
| 1757 | self.assertEqual(A.queried, 2) # Initial and isMerged |
| 1758 | self.assertEqual(B.queried, 3) # Initial A, refresh from B, isMerged |
| 1759 | |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1760 | def test_can_merge(self): |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1761 | "Test whether a change is ready to merge" |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1762 | # TODO: move to test_gerrit (this is a unit test!) |
| 1763 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1764 | trigger = self.sched.layout.pipelines['gate'].trigger |
| 1765 | a = self.sched.triggers['gerrit'].getChange(1, 2) |
James E. Blair | eff8816 | 2013-07-01 12:44:14 -0400 | [diff] [blame] | 1766 | mgr = self.sched.layout.pipelines['gate'].manager |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1767 | self.assertFalse(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1768 | |
| 1769 | A.addApproval('CRVW', 2) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1770 | a = trigger.getChange(1, 2, refresh=True) |
| 1771 | self.assertFalse(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
James E. Blair | 8c803f8 | 2012-07-31 16:25:42 -0700 | [diff] [blame] | 1772 | |
| 1773 | A.addApproval('APRV', 1) |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 1774 | a = trigger.getChange(1, 2, refresh=True) |
| 1775 | self.assertTrue(trigger.canMerge(a, mgr.getSubmitAllowNeeds())) |
| 1776 | trigger.maintainCache([]) |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1777 | |
| 1778 | def test_build_configuration(self): |
| 1779 | "Test that zuul merges the right commits for testing" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1780 | |
| 1781 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1782 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1783 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 1784 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1785 | A.addApproval('CRVW', 2) |
| 1786 | B.addApproval('CRVW', 2) |
| 1787 | C.addApproval('CRVW', 2) |
| 1788 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1789 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1790 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1791 | self.waitUntilSettled() |
| 1792 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1793 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1794 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1795 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1796 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1797 | self.gearman_server.release('.*-merge') |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1798 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1799 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1800 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1801 | self.gearman_server.hold_jobs_in_queue = False |
| 1802 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1803 | self.waitUntilSettled() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1804 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1805 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1806 | repo = git.Repo(path) |
| 1807 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1808 | repo_messages.reverse() |
James E. Blair | 4886cc1 | 2012-07-18 15:39:41 -0700 | [diff] [blame] | 1809 | correct_messages = ['initial commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1810 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1811 | |
| 1812 | def test_build_configuration_conflict(self): |
| 1813 | "Test that merge conflicts are handled" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1814 | |
| 1815 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1816 | A = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1817 | 'master', 'A') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1818 | A.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1819 | B = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1820 | 'master', 'B') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1821 | B.addPatchset(['conflict']) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1822 | C = self.fake_gerrit.addFakeChange('org/conflict-project', |
| 1823 | 'master', 'C') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1824 | A.addApproval('CRVW', 2) |
| 1825 | B.addApproval('CRVW', 2) |
| 1826 | C.addApproval('CRVW', 2) |
| 1827 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1828 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1829 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1830 | self.waitUntilSettled() |
| 1831 | |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1832 | self.assertEqual(A.reported, 1) |
| 1833 | self.assertEqual(B.reported, 1) |
| 1834 | self.assertEqual(C.reported, 1) |
| 1835 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1836 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1837 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1838 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1839 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1840 | self.gearman_server.release('.*-merge') |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1841 | self.waitUntilSettled() |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1842 | |
| 1843 | self.assertEqual(len(self.history), 2) # A and C merge jobs |
| 1844 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1845 | self.gearman_server.hold_jobs_in_queue = False |
| 1846 | self.gearman_server.release() |
James E. Blair | 973721f | 2012-08-15 10:19:43 -0700 | [diff] [blame] | 1847 | self.waitUntilSettled() |
| 1848 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1849 | self.assertEqual(A.data['status'], 'MERGED') |
| 1850 | self.assertEqual(B.data['status'], 'NEW') |
| 1851 | self.assertEqual(C.data['status'], 'MERGED') |
| 1852 | self.assertEqual(A.reported, 2) |
| 1853 | self.assertEqual(B.reported, 2) |
| 1854 | self.assertEqual(C.reported, 2) |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 1855 | self.assertEqual(len(self.history), 6) |
James E. Blair | 6736beb | 2013-07-11 15:18:15 -0700 | [diff] [blame] | 1856 | |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1857 | def test_post(self): |
| 1858 | "Test that post jobs run" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1859 | |
Zhongyue Luo | 5d55607 | 2012-09-21 02:00:47 +0900 | [diff] [blame] | 1860 | e = { |
| 1861 | "type": "ref-updated", |
| 1862 | "submitter": { |
| 1863 | "name": "User Name", |
| 1864 | }, |
| 1865 | "refUpdate": { |
| 1866 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 1867 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 1868 | "refName": "master", |
| 1869 | "project": "org/project", |
| 1870 | } |
| 1871 | } |
James E. Blair | daabed2 | 2012-08-15 15:38:57 -0700 | [diff] [blame] | 1872 | self.fake_gerrit.addEvent(e) |
| 1873 | self.waitUntilSettled() |
| 1874 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 1875 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1876 | self.assertEqual(len(self.history), 1) |
| 1877 | self.assertIn('project-post', job_names) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1878 | |
| 1879 | def test_build_configuration_branch(self): |
| 1880 | "Test that the right commits are on alternate branches" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1881 | |
| 1882 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1883 | A = self.fake_gerrit.addFakeChange('org/project', 'mp', 'A') |
| 1884 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1885 | C = self.fake_gerrit.addFakeChange('org/project', 'mp', 'C') |
| 1886 | A.addApproval('CRVW', 2) |
| 1887 | B.addApproval('CRVW', 2) |
| 1888 | C.addApproval('CRVW', 2) |
| 1889 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1890 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1891 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1892 | self.waitUntilSettled() |
| 1893 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1894 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1895 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1896 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1897 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1898 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1899 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1900 | queue = self.gearman_server.getQueue() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1901 | ref = self.getParameter(queue[-1], 'ZUUL_REF') |
| 1902 | self.gearman_server.hold_jobs_in_queue = False |
| 1903 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1904 | self.waitUntilSettled() |
| 1905 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1906 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1907 | repo = git.Repo(path) |
| 1908 | repo_messages = [c.message.strip() for c in repo.iter_commits(ref)] |
| 1909 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1910 | correct_messages = ['initial commit', 'mp commit', 'A-1', 'B-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1911 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1912 | |
| 1913 | def test_build_configuration_branch_interaction(self): |
| 1914 | "Test that switching between branches works" |
| 1915 | self.test_build_configuration() |
| 1916 | self.test_build_configuration_branch() |
| 1917 | # C has been merged, undo that |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1918 | path = os.path.join(self.upstream_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1919 | repo = git.Repo(path) |
| 1920 | repo.heads.master.commit = repo.commit('init') |
| 1921 | self.test_build_configuration() |
| 1922 | |
| 1923 | def test_build_configuration_multi_branch(self): |
| 1924 | "Test that dependent changes on multiple branches are merged" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1925 | |
| 1926 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1927 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 1928 | B = self.fake_gerrit.addFakeChange('org/project', 'mp', 'B') |
| 1929 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 1930 | A.addApproval('CRVW', 2) |
| 1931 | B.addApproval('CRVW', 2) |
| 1932 | C.addApproval('CRVW', 2) |
| 1933 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1934 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1935 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 1936 | self.waitUntilSettled() |
| 1937 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1938 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1939 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1940 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1941 | job_B = None |
| 1942 | for job in queue: |
| 1943 | if 'project-merge' in job.name: |
| 1944 | job_B = job |
| 1945 | ref_B = self.getParameter(job_B, 'ZUUL_REF') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1946 | self.log.debug("Got Zuul ref for change B: %s" % ref_B) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1947 | self.gearman_server.release('.*-merge') |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1948 | self.waitUntilSettled() |
James E. Blair | 701c5b4 | 2013-06-06 09:34:59 -0700 | [diff] [blame] | 1949 | queue = self.gearman_server.getQueue() |
James E. Blair | d320d7e | 2013-07-30 16:36:20 -0700 | [diff] [blame] | 1950 | for job in queue: |
| 1951 | if 'project-merge' in job.name: |
| 1952 | job_C = job |
| 1953 | ref_C = self.getParameter(job_C, 'ZUUL_REF') |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1954 | self.log.debug("Got Zuul ref for change C: %s" % ref_C) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1955 | self.gearman_server.hold_jobs_in_queue = False |
| 1956 | self.gearman_server.release() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1957 | self.waitUntilSettled() |
| 1958 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 1959 | path = os.path.join(self.git_root, "org/project") |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1960 | repo = git.Repo(path) |
| 1961 | |
| 1962 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1963 | for c in repo.iter_commits(ref_C)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1964 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1965 | correct_messages = ['initial commit', 'A-1', 'C-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1966 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1967 | |
| 1968 | repo_messages = [c.message.strip() |
James E. Blair | f750aa0 | 2013-07-15 14:11:24 -0700 | [diff] [blame] | 1969 | for c in repo.iter_commits(ref_B)] |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1970 | repo_messages.reverse() |
James E. Blair | c6294a5 | 2012-08-17 10:19:48 -0700 | [diff] [blame] | 1971 | correct_messages = ['initial commit', 'mp commit', 'B-1'] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1972 | self.assertEqual(repo_messages, correct_messages) |
James E. Blair | 7f71c80 | 2012-08-22 13:04:32 -0700 | [diff] [blame] | 1973 | |
| 1974 | def test_one_job_project(self): |
| 1975 | "Test that queueing works with one job" |
| 1976 | A = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1977 | 'master', 'A') |
| 1978 | B = self.fake_gerrit.addFakeChange('org/one-job-project', |
| 1979 | 'master', 'B') |
| 1980 | A.addApproval('CRVW', 2) |
| 1981 | B.addApproval('CRVW', 2) |
| 1982 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 1983 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 1984 | self.waitUntilSettled() |
| 1985 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1986 | self.assertEqual(A.data['status'], 'MERGED') |
| 1987 | self.assertEqual(A.reported, 2) |
| 1988 | self.assertEqual(B.data['status'], 'MERGED') |
| 1989 | self.assertEqual(B.reported, 2) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 1990 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1991 | def test_job_from_templates_launched(self): |
| 1992 | "Test whether a job generated via a template can be launched" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 1993 | |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1994 | A = self.fake_gerrit.addFakeChange( |
| 1995 | 'org/templated-project', 'master', 'A') |
| 1996 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 1997 | self.waitUntilSettled() |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 1998 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 1999 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2000 | 'SUCCESS') |
| 2001 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2002 | 'SUCCESS') |
Antoine Musso | 80edd5a | 2013-02-13 15:37:53 +0100 | [diff] [blame] | 2003 | |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 2004 | def test_layered_templates(self): |
| 2005 | "Test whether a job generated via a template can be launched" |
| 2006 | |
| 2007 | A = self.fake_gerrit.addFakeChange( |
| 2008 | 'org/layered-project', 'master', 'A') |
| 2009 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2010 | self.waitUntilSettled() |
| 2011 | |
| 2012 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2013 | 'SUCCESS') |
| 2014 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2015 | 'SUCCESS') |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 2016 | self.assertEqual(self.getJobFromHistory('layered-project-test3' |
| 2017 | ).result, 'SUCCESS') |
| 2018 | self.assertEqual(self.getJobFromHistory('layered-project-test4' |
| 2019 | ).result, 'SUCCESS') |
| 2020 | # test5 should run twice because two templates define it |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 2021 | test5_count = 0 |
| 2022 | for job in self.worker.build_history: |
James E. Blair | aea6cf6 | 2013-12-16 15:38:12 -0800 | [diff] [blame] | 2023 | if job.name == 'layered-project-foo-test5': |
James E. Blair | 3e98c02 | 2013-12-16 15:25:38 -0800 | [diff] [blame] | 2024 | test5_count += 1 |
| 2025 | self.assertEqual(job.result, 'SUCCESS') |
| 2026 | self.assertEqual(test5_count, 2) |
| 2027 | self.assertEqual(self.getJobFromHistory('project-test6').result, |
| 2028 | 'SUCCESS') |
| 2029 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2030 | def test_dependent_changes_dequeue(self): |
| 2031 | "Test that dependent patches are not needlessly tested" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2032 | |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2033 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2034 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2035 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2036 | A.addApproval('CRVW', 2) |
| 2037 | B.addApproval('CRVW', 2) |
| 2038 | C.addApproval('CRVW', 2) |
| 2039 | |
| 2040 | M1 = self.fake_gerrit.addFakeChange('org/project', 'master', 'M1') |
| 2041 | M1.setMerged() |
| 2042 | |
| 2043 | # C -> B -> A -> M1 |
| 2044 | |
| 2045 | C.setDependsOn(B, 1) |
| 2046 | B.setDependsOn(A, 1) |
| 2047 | A.setDependsOn(M1, 1) |
| 2048 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2049 | self.worker.addFailTest('project-merge', A) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2050 | |
| 2051 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2052 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2053 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2054 | |
| 2055 | self.waitUntilSettled() |
| 2056 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2057 | self.assertEqual(A.data['status'], 'NEW') |
| 2058 | self.assertEqual(A.reported, 2) |
| 2059 | self.assertEqual(B.data['status'], 'NEW') |
| 2060 | self.assertEqual(B.reported, 2) |
| 2061 | self.assertEqual(C.data['status'], 'NEW') |
| 2062 | self.assertEqual(C.reported, 2) |
| 2063 | self.assertEqual(len(self.history), 1) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2064 | |
James E. Blair | 972e3c7 | 2013-08-29 12:04:55 -0700 | [diff] [blame] | 2065 | def test_failing_dependent_changes(self): |
| 2066 | "Test that failing dependent patches are taken out of stream" |
| 2067 | self.worker.hold_jobs_in_build = True |
| 2068 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2069 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2070 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2071 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2072 | E = self.fake_gerrit.addFakeChange('org/project', 'master', 'E') |
| 2073 | A.addApproval('CRVW', 2) |
| 2074 | B.addApproval('CRVW', 2) |
| 2075 | C.addApproval('CRVW', 2) |
| 2076 | D.addApproval('CRVW', 2) |
| 2077 | E.addApproval('CRVW', 2) |
| 2078 | |
| 2079 | # E, D -> C -> B, A |
| 2080 | |
| 2081 | D.setDependsOn(C, 1) |
| 2082 | C.setDependsOn(B, 1) |
| 2083 | |
| 2084 | self.worker.addFailTest('project-test1', B) |
| 2085 | |
| 2086 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2087 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2088 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2089 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2090 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 2091 | |
| 2092 | self.waitUntilSettled() |
| 2093 | self.worker.release('.*-merge') |
| 2094 | self.waitUntilSettled() |
| 2095 | self.worker.release('.*-merge') |
| 2096 | self.waitUntilSettled() |
| 2097 | self.worker.release('.*-merge') |
| 2098 | self.waitUntilSettled() |
| 2099 | self.worker.release('.*-merge') |
| 2100 | self.waitUntilSettled() |
| 2101 | self.worker.release('.*-merge') |
| 2102 | self.waitUntilSettled() |
| 2103 | |
| 2104 | self.worker.hold_jobs_in_build = False |
| 2105 | for build in self.builds: |
| 2106 | if build.parameters['ZUUL_CHANGE'] != '1': |
| 2107 | build.release() |
| 2108 | self.waitUntilSettled() |
| 2109 | |
| 2110 | self.worker.release() |
| 2111 | self.waitUntilSettled() |
| 2112 | |
| 2113 | self.assertEqual(A.data['status'], 'MERGED') |
| 2114 | self.assertEqual(A.reported, 2) |
| 2115 | self.assertEqual(B.data['status'], 'NEW') |
| 2116 | self.assertEqual(B.reported, 2) |
| 2117 | self.assertEqual(C.data['status'], 'NEW') |
| 2118 | self.assertEqual(C.reported, 2) |
| 2119 | self.assertEqual(D.data['status'], 'NEW') |
| 2120 | self.assertEqual(D.reported, 2) |
| 2121 | self.assertEqual(E.data['status'], 'MERGED') |
| 2122 | self.assertEqual(E.reported, 2) |
| 2123 | self.assertEqual(len(self.history), 18) |
| 2124 | |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2125 | def test_head_is_dequeued_once(self): |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2126 | "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] | 2127 | # If it's dequeued more than once, we should see extra |
| 2128 | # aborted jobs. |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2129 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2130 | self.worker.hold_jobs_in_build = True |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2131 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2132 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2133 | C = self.fake_gerrit.addFakeChange('org/project1', 'master', 'C') |
| 2134 | A.addApproval('CRVW', 2) |
| 2135 | B.addApproval('CRVW', 2) |
| 2136 | C.addApproval('CRVW', 2) |
| 2137 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2138 | self.worker.addFailTest('project1-test1', A) |
| 2139 | self.worker.addFailTest('project1-test2', A) |
| 2140 | self.worker.addFailTest('project1-project2-integration', A) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2141 | |
| 2142 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2143 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2144 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2145 | |
| 2146 | self.waitUntilSettled() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2147 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2148 | self.assertEqual(len(self.builds), 1) |
| 2149 | self.assertEqual(self.builds[0].name, 'project1-merge') |
| 2150 | self.assertTrue(self.job_has_changes(self.builds[0], A)) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2151 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2152 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2153 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2154 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2155 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2156 | self.worker.release('.*-merge') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2157 | self.waitUntilSettled() |
| 2158 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2159 | self.assertEqual(len(self.builds), 9) |
| 2160 | self.assertEqual(self.builds[0].name, 'project1-test1') |
| 2161 | self.assertEqual(self.builds[1].name, 'project1-test2') |
| 2162 | self.assertEqual(self.builds[2].name, 'project1-project2-integration') |
| 2163 | self.assertEqual(self.builds[3].name, 'project1-test1') |
| 2164 | self.assertEqual(self.builds[4].name, 'project1-test2') |
| 2165 | self.assertEqual(self.builds[5].name, 'project1-project2-integration') |
| 2166 | self.assertEqual(self.builds[6].name, 'project1-test1') |
| 2167 | self.assertEqual(self.builds[7].name, 'project1-test2') |
| 2168 | self.assertEqual(self.builds[8].name, 'project1-project2-integration') |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2169 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2170 | self.release(self.builds[0]) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2171 | self.waitUntilSettled() |
| 2172 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2173 | self.assertEqual(len(self.builds), 3) # test2,integration, merge for B |
| 2174 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 6) |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2175 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2176 | self.worker.hold_jobs_in_build = False |
| 2177 | self.worker.release() |
James E. Blair | ec59012 | 2012-08-22 15:19:31 -0700 | [diff] [blame] | 2178 | self.waitUntilSettled() |
| 2179 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2180 | self.assertEqual(len(self.builds), 0) |
| 2181 | self.assertEqual(len(self.history), 20) |
James E. Blair | caec0c5 | 2012-08-22 14:52:22 -0700 | [diff] [blame] | 2182 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2183 | self.assertEqual(A.data['status'], 'NEW') |
| 2184 | self.assertEqual(B.data['status'], 'MERGED') |
| 2185 | self.assertEqual(C.data['status'], 'MERGED') |
| 2186 | self.assertEqual(A.reported, 2) |
| 2187 | self.assertEqual(B.reported, 2) |
| 2188 | self.assertEqual(C.reported, 2) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2189 | |
| 2190 | def test_nonvoting_job(self): |
| 2191 | "Test that non-voting jobs don't vote." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2192 | |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2193 | A = self.fake_gerrit.addFakeChange('org/nonvoting-project', |
| 2194 | 'master', 'A') |
| 2195 | A.addApproval('CRVW', 2) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2196 | self.worker.addFailTest('nonvoting-project-test2', A) |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2197 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2198 | |
| 2199 | self.waitUntilSettled() |
James E. Blair | 4ec821f | 2012-08-23 15:28:28 -0700 | [diff] [blame] | 2200 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2201 | self.assertEqual(A.data['status'], 'MERGED') |
| 2202 | self.assertEqual(A.reported, 2) |
| 2203 | self.assertEqual( |
| 2204 | self.getJobFromHistory('nonvoting-project-merge').result, |
| 2205 | 'SUCCESS') |
| 2206 | self.assertEqual( |
| 2207 | self.getJobFromHistory('nonvoting-project-test1').result, |
| 2208 | 'SUCCESS') |
| 2209 | self.assertEqual( |
| 2210 | self.getJobFromHistory('nonvoting-project-test2').result, |
| 2211 | 'FAILURE') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2212 | |
| 2213 | def test_check_queue_success(self): |
| 2214 | "Test successful check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2215 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2216 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2217 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2218 | |
| 2219 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2220 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2221 | self.assertEqual(A.data['status'], 'NEW') |
| 2222 | self.assertEqual(A.reported, 1) |
| 2223 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2224 | 'SUCCESS') |
| 2225 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2226 | 'SUCCESS') |
| 2227 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2228 | 'SUCCESS') |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2229 | |
| 2230 | def test_check_queue_failure(self): |
| 2231 | "Test failed check queue jobs." |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2232 | |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2233 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2234 | self.worker.addFailTest('project-test2', A) |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2235 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2236 | |
| 2237 | self.waitUntilSettled() |
James E. Blair | e048707 | 2012-08-29 17:38:31 -0700 | [diff] [blame] | 2238 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2239 | self.assertEqual(A.data['status'], 'NEW') |
| 2240 | self.assertEqual(A.reported, 1) |
| 2241 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
James E. Blair | 78e31b3 | 2013-07-09 09:11:34 -0700 | [diff] [blame] | 2242 | 'SUCCESS') |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2243 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2244 | 'SUCCESS') |
| 2245 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2246 | 'FAILURE') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2247 | |
| 2248 | def test_dependent_behind_dequeue(self): |
| 2249 | "test that dependent changes behind dequeued changes work" |
| 2250 | # This complicated test is a reproduction of a real life bug |
| 2251 | self.sched.reconfigure(self.config) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2252 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2253 | self.worker.hold_jobs_in_build = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2254 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2255 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2256 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2257 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 2258 | E = self.fake_gerrit.addFakeChange('org/project2', 'master', 'E') |
| 2259 | F = self.fake_gerrit.addFakeChange('org/project3', 'master', 'F') |
| 2260 | D.setDependsOn(C, 1) |
| 2261 | E.setDependsOn(D, 1) |
| 2262 | A.addApproval('CRVW', 2) |
| 2263 | B.addApproval('CRVW', 2) |
| 2264 | C.addApproval('CRVW', 2) |
| 2265 | D.addApproval('CRVW', 2) |
| 2266 | E.addApproval('CRVW', 2) |
| 2267 | F.addApproval('CRVW', 2) |
| 2268 | |
| 2269 | A.fail_merge = True |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2270 | |
| 2271 | # Change object re-use in the gerrit trigger is hidden if |
| 2272 | # changes are added in quick succession; waiting makes it more |
| 2273 | # like real life. |
| 2274 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2275 | self.waitUntilSettled() |
| 2276 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2277 | self.waitUntilSettled() |
| 2278 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2279 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2280 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2281 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2282 | self.waitUntilSettled() |
| 2283 | |
| 2284 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2285 | self.waitUntilSettled() |
| 2286 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2287 | self.waitUntilSettled() |
| 2288 | self.fake_gerrit.addEvent(E.addApproval('APRV', 1)) |
| 2289 | self.waitUntilSettled() |
| 2290 | self.fake_gerrit.addEvent(F.addApproval('APRV', 1)) |
| 2291 | self.waitUntilSettled() |
| 2292 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2293 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2294 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2295 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2296 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2297 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2298 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2299 | self.worker.release('.*-merge') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2300 | self.waitUntilSettled() |
| 2301 | |
| 2302 | # all jobs running |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 2303 | |
| 2304 | # Grab pointers to the jobs we want to release before |
| 2305 | # releasing any, because list indexes may change as |
| 2306 | # the jobs complete. |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2307 | a, b, c = self.builds[:3] |
James E. Blair | e955e06 | 2012-10-08 09:49:03 -0700 | [diff] [blame] | 2308 | a.release() |
| 2309 | b.release() |
| 2310 | c.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2311 | self.waitUntilSettled() |
| 2312 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2313 | self.worker.hold_jobs_in_build = False |
| 2314 | self.worker.release() |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2315 | self.waitUntilSettled() |
| 2316 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2317 | self.assertEqual(A.data['status'], 'NEW') |
| 2318 | self.assertEqual(B.data['status'], 'MERGED') |
| 2319 | self.assertEqual(C.data['status'], 'MERGED') |
| 2320 | self.assertEqual(D.data['status'], 'MERGED') |
| 2321 | self.assertEqual(E.data['status'], 'MERGED') |
| 2322 | self.assertEqual(F.data['status'], 'MERGED') |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2323 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2324 | self.assertEqual(A.reported, 2) |
| 2325 | self.assertEqual(B.reported, 2) |
| 2326 | self.assertEqual(C.reported, 2) |
| 2327 | self.assertEqual(D.reported, 2) |
| 2328 | self.assertEqual(E.reported, 2) |
| 2329 | self.assertEqual(F.reported, 2) |
James E. Blair | 127bc18 | 2012-08-28 15:55:15 -0700 | [diff] [blame] | 2330 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2331 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 15) |
| 2332 | self.assertEqual(len(self.history), 44) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2333 | |
| 2334 | def test_merger_repack(self): |
| 2335 | "Test that the merger works after a repack" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2336 | |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2337 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2338 | A.addApproval('CRVW', 2) |
| 2339 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2340 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2341 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2342 | 'SUCCESS') |
| 2343 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2344 | 'SUCCESS') |
| 2345 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2346 | 'SUCCESS') |
| 2347 | self.assertEqual(A.data['status'], 'MERGED') |
| 2348 | self.assertEqual(A.reported, 2) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2349 | self.assertEmptyQueues() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2350 | self.worker.build_history = [] |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2351 | |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 2352 | path = os.path.join(self.git_root, "org/project") |
| 2353 | print repack_repo(path) |
James E. Blair | 05fed60 | 2012-09-07 12:45:24 -0700 | [diff] [blame] | 2354 | |
| 2355 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2356 | A.addApproval('CRVW', 2) |
| 2357 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2358 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2359 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2360 | 'SUCCESS') |
| 2361 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2362 | 'SUCCESS') |
| 2363 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2364 | 'SUCCESS') |
| 2365 | self.assertEqual(A.data['status'], 'MERGED') |
| 2366 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2367 | |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2368 | def test_merger_repack_large_change(self): |
| 2369 | "Test that the merger works with large changes after a repack" |
| 2370 | # https://bugs.launchpad.net/zuul/+bug/1078946 |
James E. Blair | ac2c324 | 2014-01-24 13:38:51 -0800 | [diff] [blame] | 2371 | # This test assumes the repo is already cloned; make sure it is |
| 2372 | url = self.sched.triggers['gerrit'].getGitUrl( |
| 2373 | self.sched.layout.projects['org/project1']) |
James E. Blair | 4076e2b | 2014-01-28 12:42:20 -0800 | [diff] [blame^] | 2374 | self.merge_server.merger.addProject('org/project1', url) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2375 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2376 | A.addPatchset(large=True) |
Monty Taylor | bc75883 | 2013-06-17 17:22:42 -0400 | [diff] [blame] | 2377 | path = os.path.join(self.upstream_root, "org/project1") |
| 2378 | print repack_repo(path) |
| 2379 | path = os.path.join(self.git_root, "org/project1") |
| 2380 | print repack_repo(path) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2381 | |
| 2382 | A.addApproval('CRVW', 2) |
| 2383 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2384 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2385 | self.assertEqual(self.getJobFromHistory('project1-merge').result, |
| 2386 | 'SUCCESS') |
| 2387 | self.assertEqual(self.getJobFromHistory('project1-test1').result, |
| 2388 | 'SUCCESS') |
| 2389 | self.assertEqual(self.getJobFromHistory('project1-test2').result, |
| 2390 | 'SUCCESS') |
| 2391 | self.assertEqual(A.data['status'], 'MERGED') |
| 2392 | self.assertEqual(A.reported, 2) |
James E. Blair | 4886f28 | 2012-11-15 09:27:33 -0800 | [diff] [blame] | 2393 | |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2394 | def test_nonexistent_job(self): |
| 2395 | "Test launching a job that doesn't exist" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2396 | # Set to the state immediately after a restart |
| 2397 | self.resetGearmanServer() |
| 2398 | self.launcher.negative_function_cache_ttl = 0 |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2399 | |
| 2400 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2401 | A.addApproval('CRVW', 2) |
| 2402 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2403 | # There may be a thread about to report a lost change |
| 2404 | while A.reported < 2: |
| 2405 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2406 | job_names = [x.name for x in self.history] |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2407 | self.assertFalse(job_names) |
| 2408 | self.assertEqual(A.data['status'], 'NEW') |
| 2409 | self.assertEqual(A.reported, 2) |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2410 | self.assertEmptyQueues() |
| 2411 | |
| 2412 | # Make sure things still work: |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2413 | self.registerJobs() |
James E. Blair | 7ee88a2 | 2012-09-12 18:59:31 +0200 | [diff] [blame] | 2414 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2415 | A.addApproval('CRVW', 2) |
| 2416 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2417 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2418 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2419 | 'SUCCESS') |
| 2420 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2421 | 'SUCCESS') |
| 2422 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2423 | 'SUCCESS') |
| 2424 | self.assertEqual(A.data['status'], 'MERGED') |
| 2425 | self.assertEqual(A.reported, 2) |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2426 | |
| 2427 | def test_single_nonexistent_post_job(self): |
| 2428 | "Test launching a single post job that doesn't exist" |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2429 | e = { |
| 2430 | "type": "ref-updated", |
| 2431 | "submitter": { |
| 2432 | "name": "User Name", |
| 2433 | }, |
| 2434 | "refUpdate": { |
| 2435 | "oldRev": "90f173846e3af9154517b88543ffbd1691f31366", |
| 2436 | "newRev": "d479a0bfcb34da57a31adb2a595c0cf687812543", |
| 2437 | "refName": "master", |
| 2438 | "project": "org/project", |
| 2439 | } |
| 2440 | } |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2441 | # Set to the state immediately after a restart |
| 2442 | self.resetGearmanServer() |
| 2443 | self.launcher.negative_function_cache_ttl = 0 |
| 2444 | |
James E. Blair | f62d428 | 2012-12-31 17:01:50 -0800 | [diff] [blame] | 2445 | self.fake_gerrit.addEvent(e) |
| 2446 | self.waitUntilSettled() |
| 2447 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2448 | self.assertEqual(len(self.history), 0) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2449 | |
| 2450 | def test_new_patchset_dequeues_old(self): |
| 2451 | "Test that a new patchset causes the old to be dequeued" |
| 2452 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2453 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2454 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2455 | M.setMerged() |
| 2456 | |
| 2457 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2458 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2459 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2460 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2461 | A.addApproval('CRVW', 2) |
| 2462 | B.addApproval('CRVW', 2) |
| 2463 | C.addApproval('CRVW', 2) |
| 2464 | D.addApproval('CRVW', 2) |
| 2465 | |
| 2466 | C.setDependsOn(B, 1) |
| 2467 | B.setDependsOn(A, 1) |
| 2468 | A.setDependsOn(M, 1) |
| 2469 | |
| 2470 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2471 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2472 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2473 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2474 | self.waitUntilSettled() |
| 2475 | |
| 2476 | B.addPatchset() |
| 2477 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2478 | self.waitUntilSettled() |
| 2479 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2480 | self.worker.hold_jobs_in_build = False |
| 2481 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2482 | self.waitUntilSettled() |
| 2483 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2484 | self.assertEqual(A.data['status'], 'MERGED') |
| 2485 | self.assertEqual(A.reported, 2) |
| 2486 | self.assertEqual(B.data['status'], 'NEW') |
| 2487 | self.assertEqual(B.reported, 2) |
| 2488 | self.assertEqual(C.data['status'], 'NEW') |
| 2489 | self.assertEqual(C.reported, 2) |
| 2490 | self.assertEqual(D.data['status'], 'MERGED') |
| 2491 | self.assertEqual(D.reported, 2) |
| 2492 | 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] | 2493 | |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2494 | def test_zuul_url_return(self): |
| 2495 | "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^] | 2496 | self.assertTrue(self.sched.config.has_option('merger', 'zuul_url')) |
Arx Cruz | b1b010d | 2013-10-28 19:49:59 -0200 | [diff] [blame] | 2497 | self.worker.hold_jobs_in_build = True |
| 2498 | |
| 2499 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2500 | A.addApproval('CRVW', 2) |
| 2501 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2502 | self.waitUntilSettled() |
| 2503 | |
| 2504 | self.assertEqual(len(self.builds), 1) |
| 2505 | for build in self.builds: |
| 2506 | self.assertTrue('ZUUL_URL' in build.parameters) |
| 2507 | |
| 2508 | self.worker.hold_jobs_in_build = False |
| 2509 | self.worker.release() |
| 2510 | self.waitUntilSettled() |
| 2511 | |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2512 | def test_new_patchset_dequeues_old_on_head(self): |
| 2513 | "Test that a new patchset causes the old to be dequeued (at head)" |
| 2514 | # D -> C (depends on B) -> B (depends on A) -> A -> M |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2515 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2516 | M = self.fake_gerrit.addFakeChange('org/project', 'master', 'M') |
| 2517 | M.setMerged() |
| 2518 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2519 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2520 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2521 | D = self.fake_gerrit.addFakeChange('org/project', 'master', 'D') |
| 2522 | A.addApproval('CRVW', 2) |
| 2523 | B.addApproval('CRVW', 2) |
| 2524 | C.addApproval('CRVW', 2) |
| 2525 | D.addApproval('CRVW', 2) |
| 2526 | |
| 2527 | C.setDependsOn(B, 1) |
| 2528 | B.setDependsOn(A, 1) |
| 2529 | A.setDependsOn(M, 1) |
| 2530 | |
| 2531 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2532 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2533 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2534 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2535 | self.waitUntilSettled() |
| 2536 | |
| 2537 | A.addPatchset() |
| 2538 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(2)) |
| 2539 | self.waitUntilSettled() |
| 2540 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2541 | self.worker.hold_jobs_in_build = False |
| 2542 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2543 | self.waitUntilSettled() |
| 2544 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2545 | self.assertEqual(A.data['status'], 'NEW') |
| 2546 | self.assertEqual(A.reported, 2) |
| 2547 | self.assertEqual(B.data['status'], 'NEW') |
| 2548 | self.assertEqual(B.reported, 2) |
| 2549 | self.assertEqual(C.data['status'], 'NEW') |
| 2550 | self.assertEqual(C.reported, 2) |
| 2551 | self.assertEqual(D.data['status'], 'MERGED') |
| 2552 | self.assertEqual(D.reported, 2) |
| 2553 | self.assertEqual(len(self.history), 7) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2554 | |
| 2555 | def test_new_patchset_dequeues_old_without_dependents(self): |
| 2556 | "Test that a new patchset causes only the old to be dequeued" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2557 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2558 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2559 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2560 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2561 | A.addApproval('CRVW', 2) |
| 2562 | B.addApproval('CRVW', 2) |
| 2563 | C.addApproval('CRVW', 2) |
| 2564 | |
| 2565 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2566 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2567 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2568 | self.waitUntilSettled() |
| 2569 | |
| 2570 | B.addPatchset() |
| 2571 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2572 | self.waitUntilSettled() |
| 2573 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2574 | self.worker.hold_jobs_in_build = False |
| 2575 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2576 | self.waitUntilSettled() |
| 2577 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2578 | self.assertEqual(A.data['status'], 'MERGED') |
| 2579 | self.assertEqual(A.reported, 2) |
| 2580 | self.assertEqual(B.data['status'], 'NEW') |
| 2581 | self.assertEqual(B.reported, 2) |
| 2582 | self.assertEqual(C.data['status'], 'MERGED') |
| 2583 | self.assertEqual(C.reported, 2) |
| 2584 | self.assertEqual(len(self.history), 9) |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2585 | |
| 2586 | def test_new_patchset_dequeues_old_independent_queue(self): |
| 2587 | "Test that a new patchset causes the old to be dequeued (independent)" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2588 | self.worker.hold_jobs_in_build = True |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2589 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2590 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2591 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 2592 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2593 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) |
| 2594 | self.fake_gerrit.addEvent(C.getPatchsetCreatedEvent(1)) |
| 2595 | self.waitUntilSettled() |
| 2596 | |
| 2597 | B.addPatchset() |
| 2598 | self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(2)) |
| 2599 | self.waitUntilSettled() |
| 2600 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2601 | self.worker.hold_jobs_in_build = False |
| 2602 | self.worker.release() |
James E. Blair | 2fa5096 | 2013-01-30 21:50:41 -0800 | [diff] [blame] | 2603 | self.waitUntilSettled() |
| 2604 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2605 | self.assertEqual(A.data['status'], 'NEW') |
| 2606 | self.assertEqual(A.reported, 1) |
| 2607 | self.assertEqual(B.data['status'], 'NEW') |
| 2608 | self.assertEqual(B.reported, 1) |
| 2609 | self.assertEqual(C.data['status'], 'NEW') |
| 2610 | self.assertEqual(C.reported, 1) |
| 2611 | self.assertEqual(len(self.history), 10) |
| 2612 | self.assertEqual(self.countJobResults(self.history, 'ABORTED'), 1) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2613 | |
| 2614 | def test_zuul_refs(self): |
| 2615 | "Test that zuul refs exist and have the right changes" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2616 | self.worker.hold_jobs_in_build = True |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2617 | M1 = self.fake_gerrit.addFakeChange('org/project1', 'master', 'M1') |
| 2618 | M1.setMerged() |
| 2619 | M2 = self.fake_gerrit.addFakeChange('org/project2', 'master', 'M2') |
| 2620 | M2.setMerged() |
| 2621 | |
| 2622 | A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') |
| 2623 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 2624 | C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C') |
| 2625 | D = self.fake_gerrit.addFakeChange('org/project2', 'master', 'D') |
| 2626 | A.addApproval('CRVW', 2) |
| 2627 | B.addApproval('CRVW', 2) |
| 2628 | C.addApproval('CRVW', 2) |
| 2629 | D.addApproval('CRVW', 2) |
| 2630 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2631 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2632 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 2633 | self.fake_gerrit.addEvent(D.addApproval('APRV', 1)) |
| 2634 | |
| 2635 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2636 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2637 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2638 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2639 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2640 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2641 | self.waitUntilSettled() |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2642 | self.worker.release('.*-merge') |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2643 | self.waitUntilSettled() |
| 2644 | |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2645 | a_zref = b_zref = c_zref = d_zref = None |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2646 | for x in self.builds: |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2647 | if x.parameters['ZUUL_CHANGE'] == '3': |
| 2648 | a_zref = x.parameters['ZUUL_REF'] |
| 2649 | if x.parameters['ZUUL_CHANGE'] == '4': |
| 2650 | b_zref = x.parameters['ZUUL_REF'] |
| 2651 | if x.parameters['ZUUL_CHANGE'] == '5': |
| 2652 | c_zref = x.parameters['ZUUL_REF'] |
| 2653 | if x.parameters['ZUUL_CHANGE'] == '6': |
| 2654 | d_zref = x.parameters['ZUUL_REF'] |
| 2655 | |
| 2656 | # There are... four... refs. |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2657 | self.assertIsNotNone(a_zref) |
| 2658 | self.assertIsNotNone(b_zref) |
| 2659 | self.assertIsNotNone(c_zref) |
| 2660 | self.assertIsNotNone(d_zref) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2661 | |
| 2662 | # And they should all be different |
| 2663 | refs = set([a_zref, b_zref, c_zref, d_zref]) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2664 | self.assertEqual(len(refs), 4) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2665 | |
| 2666 | # 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] | 2667 | self.assertTrue(self.ref_has_change(a_zref, A)) |
| 2668 | self.assertFalse(self.ref_has_change(a_zref, B)) |
| 2669 | self.assertFalse(self.ref_has_change(a_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2670 | |
| 2671 | # 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] | 2672 | self.assertTrue(self.ref_has_change(b_zref, A)) |
| 2673 | self.assertTrue(self.ref_has_change(b_zref, B)) |
| 2674 | self.assertFalse(self.ref_has_change(b_zref, M2)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2675 | |
| 2676 | # c ref should have a and b in 1, c in 2 |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2677 | self.assertTrue(self.ref_has_change(c_zref, A)) |
| 2678 | self.assertTrue(self.ref_has_change(c_zref, B)) |
| 2679 | self.assertTrue(self.ref_has_change(c_zref, C)) |
| 2680 | self.assertFalse(self.ref_has_change(c_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2681 | |
| 2682 | # 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] | 2683 | self.assertTrue(self.ref_has_change(d_zref, A)) |
| 2684 | self.assertTrue(self.ref_has_change(d_zref, B)) |
| 2685 | self.assertTrue(self.ref_has_change(d_zref, C)) |
| 2686 | self.assertTrue(self.ref_has_change(d_zref, D)) |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2687 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2688 | self.worker.hold_jobs_in_build = False |
| 2689 | self.worker.release() |
James E. Blair | 7d0dedc | 2013-02-21 17:26:09 -0800 | [diff] [blame] | 2690 | self.waitUntilSettled() |
| 2691 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2692 | self.assertEqual(A.data['status'], 'MERGED') |
| 2693 | self.assertEqual(A.reported, 2) |
| 2694 | self.assertEqual(B.data['status'], 'MERGED') |
| 2695 | self.assertEqual(B.reported, 2) |
| 2696 | self.assertEqual(C.data['status'], 'MERGED') |
| 2697 | self.assertEqual(C.reported, 2) |
| 2698 | self.assertEqual(D.data['status'], 'MERGED') |
| 2699 | self.assertEqual(D.reported, 2) |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2700 | |
James E. Blair | c053d02 | 2014-01-22 14:57:33 -0800 | [diff] [blame] | 2701 | def test_required_approval_check_and_gate(self): |
| 2702 | "Test required-approval triggers both check and gate" |
| 2703 | self.config.set('zuul', 'layout_config', |
| 2704 | 'tests/fixtures/layout-require-approval.yaml') |
| 2705 | self.sched.reconfigure(self.config) |
| 2706 | self.registerJobs() |
| 2707 | |
| 2708 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2709 | A.addApproval('CRVW', 2) |
| 2710 | # Add a too-old +1 |
| 2711 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2712 | |
| 2713 | aprv = A.addApproval('APRV', 1) |
| 2714 | self.fake_gerrit.addEvent(aprv) |
| 2715 | self.waitUntilSettled() |
| 2716 | # Should have run a check job |
| 2717 | self.assertEqual(len(self.history), 1) |
| 2718 | self.assertEqual(self.history[0].name, 'project-check') |
| 2719 | |
| 2720 | # Report the result of that check job (overrides previous vrfy) |
| 2721 | # Skynet alert: this should trigger a gate job now that |
| 2722 | # all reqs are met |
| 2723 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1)) |
| 2724 | self.waitUntilSettled() |
| 2725 | self.assertEqual(len(self.history), 2) |
| 2726 | self.assertEqual(self.history[1].name, 'project-gate') |
| 2727 | |
| 2728 | def test_required_approval_newer(self): |
| 2729 | "Test required-approval newer trigger parameter" |
| 2730 | self.config.set('zuul', 'layout_config', |
| 2731 | 'tests/fixtures/layout-require-approval.yaml') |
| 2732 | self.sched.reconfigure(self.config) |
| 2733 | self.registerJobs() |
| 2734 | |
| 2735 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2736 | A.addApproval('CRVW', 2) |
| 2737 | aprv = A.addApproval('APRV', 1) |
| 2738 | self.fake_gerrit.addEvent(aprv) |
| 2739 | self.waitUntilSettled() |
| 2740 | # No +1 from Jenkins so should not be enqueued |
| 2741 | self.assertEqual(len(self.history), 0) |
| 2742 | |
| 2743 | # Add a too-old +1, should trigger check but not gate |
| 2744 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2745 | self.fake_gerrit.addEvent(aprv) |
| 2746 | self.waitUntilSettled() |
| 2747 | self.assertEqual(len(self.history), 1) |
| 2748 | self.assertEqual(self.history[0].name, 'project-check') |
| 2749 | |
| 2750 | # Add a recent +1 |
| 2751 | self.fake_gerrit.addEvent(A.addApproval('VRFY', 1)) |
| 2752 | self.fake_gerrit.addEvent(aprv) |
| 2753 | self.waitUntilSettled() |
| 2754 | self.assertEqual(len(self.history), 2) |
| 2755 | self.assertEqual(self.history[1].name, 'project-gate') |
| 2756 | |
| 2757 | def test_required_approval_older(self): |
| 2758 | "Test required-approval older trigger parameter" |
| 2759 | self.config.set('zuul', 'layout_config', |
| 2760 | 'tests/fixtures/layout-require-approval.yaml') |
| 2761 | self.sched.reconfigure(self.config) |
| 2762 | self.registerJobs() |
| 2763 | |
| 2764 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2765 | crvw = A.addApproval('CRVW', 2) |
| 2766 | self.fake_gerrit.addEvent(crvw) |
| 2767 | self.waitUntilSettled() |
| 2768 | # No +1 from Jenkins so should not be enqueued |
| 2769 | self.assertEqual(len(self.history), 0) |
| 2770 | |
| 2771 | # Add an old +1 and trigger check with a comment |
| 2772 | A.addApproval('VRFY', 1, granted_on=time.time() - 72 * 60 * 60) |
| 2773 | self.fake_gerrit.addEvent(crvw) |
| 2774 | self.waitUntilSettled() |
| 2775 | self.assertEqual(len(self.history), 1) |
| 2776 | self.assertEqual(self.history[0].name, 'project-check') |
| 2777 | |
| 2778 | # Add a recent +1 and make sure nothing changes |
| 2779 | A.addApproval('VRFY', 1) |
| 2780 | self.fake_gerrit.addEvent(crvw) |
| 2781 | self.waitUntilSettled() |
| 2782 | self.assertEqual(len(self.history), 1) |
| 2783 | |
| 2784 | # The last thing we did was query a change then do nothing |
| 2785 | # with a pipeline, so it will be in the cache; clean it up so |
| 2786 | # it does not fail the test. |
| 2787 | for pipeline in self.sched.layout.pipelines.values(): |
| 2788 | pipeline.trigger.maintainCache([]) |
| 2789 | |
James E. Blair | 4a28a88 | 2013-08-23 15:17:33 -0700 | [diff] [blame] | 2790 | def test_rerun_on_error(self): |
| 2791 | "Test that if a worker fails to run a job, it is run again" |
| 2792 | self.worker.hold_jobs_in_build = True |
| 2793 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2794 | A.addApproval('CRVW', 2) |
| 2795 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2796 | self.waitUntilSettled() |
| 2797 | |
| 2798 | self.builds[0].run_error = True |
| 2799 | self.worker.hold_jobs_in_build = False |
| 2800 | self.worker.release() |
| 2801 | self.waitUntilSettled() |
| 2802 | self.assertEqual(self.countJobResults(self.history, 'RUN_ERROR'), 1) |
| 2803 | self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 3) |
| 2804 | |
James E. Blair | 412e558 | 2013-04-22 15:50:12 -0700 | [diff] [blame] | 2805 | def test_statsd(self): |
| 2806 | "Test each of the statsd methods used in the scheduler" |
| 2807 | import extras |
| 2808 | statsd = extras.try_import('statsd.statsd') |
| 2809 | statsd.incr('test-incr') |
| 2810 | statsd.timing('test-timing', 3) |
| 2811 | statsd.gauge('test-guage', 12) |
| 2812 | self.assertReportedStat('test-incr', '1|c') |
| 2813 | self.assertReportedStat('test-timing', '3|ms') |
| 2814 | self.assertReportedStat('test-guage', '12|g') |
| 2815 | |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2816 | def test_file_jobs(self): |
| 2817 | "Test that file jobs run only when appropriate" |
| 2818 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2819 | A.addPatchset(['pip-requires']) |
| 2820 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 2821 | A.addApproval('CRVW', 2) |
| 2822 | B.addApproval('CRVW', 2) |
| 2823 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2824 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2825 | self.waitUntilSettled() |
| 2826 | |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2827 | testfile_jobs = [x for x in self.history |
James E. Blair | 70c7158 | 2013-03-06 08:50:50 -0800 | [diff] [blame] | 2828 | if x.name == 'project-testfile'] |
| 2829 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2830 | self.assertEqual(len(testfile_jobs), 1) |
| 2831 | self.assertEqual(testfile_jobs[0].changes, '1,2') |
| 2832 | self.assertEqual(A.data['status'], 'MERGED') |
| 2833 | self.assertEqual(A.reported, 2) |
| 2834 | self.assertEqual(B.data['status'], 'MERGED') |
| 2835 | self.assertEqual(B.reported, 2) |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2836 | |
| 2837 | def test_test_config(self): |
| 2838 | "Test that we can test the config" |
| 2839 | sched = zuul.scheduler.Scheduler() |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 2840 | sched.registerTrigger(None, 'gerrit') |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 2841 | sched.registerTrigger(None, 'timer') |
James E. Blair | 3c5e5b5 | 2013-04-26 11:17:03 -0700 | [diff] [blame] | 2842 | sched.testConfig(CONFIG.get('zuul', 'layout_config')) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2843 | |
| 2844 | def test_build_description(self): |
| 2845 | "Test that build descriptions update" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2846 | self.worker.registerFunction('set_description:' + |
| 2847 | self.worker.worker_id) |
| 2848 | |
| 2849 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2850 | A.addApproval('CRVW', 2) |
| 2851 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2852 | self.waitUntilSettled() |
Monty Taylor | 6bef8ef | 2013-06-02 08:17:12 -0400 | [diff] [blame] | 2853 | desc = self.history[0].description |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2854 | self.log.debug("Description: %s" % desc) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2855 | self.assertTrue(re.search("Branch.*master", desc)) |
| 2856 | self.assertTrue(re.search("Pipeline.*gate", desc)) |
| 2857 | self.assertTrue(re.search("project-merge.*SUCCESS", desc)) |
| 2858 | self.assertTrue(re.search("project-test1.*SUCCESS", desc)) |
| 2859 | self.assertTrue(re.search("project-test2.*SUCCESS", desc)) |
| 2860 | self.assertTrue(re.search("Reported result.*SUCCESS", desc)) |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2861 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2862 | def test_queue_precedence(self): |
| 2863 | "Test that queue precedence works" |
| 2864 | |
| 2865 | self.gearman_server.hold_jobs_in_queue = True |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2866 | self.worker.hold_jobs_in_build = True |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2867 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2868 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 2869 | A.addApproval('CRVW', 2) |
| 2870 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2871 | |
| 2872 | self.waitUntilSettled() |
| 2873 | self.gearman_server.hold_jobs_in_queue = False |
| 2874 | self.gearman_server.release() |
| 2875 | self.waitUntilSettled() |
| 2876 | |
James E. Blair | 8de58bd | 2013-07-18 16:23:33 -0700 | [diff] [blame] | 2877 | # Run one build at a time to ensure non-race order: |
| 2878 | for x in range(6): |
| 2879 | self.release(self.builds[0]) |
| 2880 | self.waitUntilSettled() |
| 2881 | self.worker.hold_jobs_in_build = False |
| 2882 | self.waitUntilSettled() |
| 2883 | |
James E. Blair | 64ed6f2 | 2013-07-10 14:07:23 -0700 | [diff] [blame] | 2884 | self.log.debug(self.history) |
| 2885 | self.assertEqual(self.history[0].pipeline, 'gate') |
| 2886 | self.assertEqual(self.history[1].pipeline, 'check') |
| 2887 | self.assertEqual(self.history[2].pipeline, 'gate') |
| 2888 | self.assertEqual(self.history[3].pipeline, 'gate') |
| 2889 | self.assertEqual(self.history[4].pipeline, 'check') |
| 2890 | self.assertEqual(self.history[5].pipeline, 'check') |
| 2891 | |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2892 | def test_json_status(self): |
| 2893 | "Test that we can retrieve JSON status info" |
| 2894 | self.worker.hold_jobs_in_build = True |
| 2895 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2896 | A.addApproval('CRVW', 2) |
| 2897 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2898 | self.waitUntilSettled() |
| 2899 | |
| 2900 | port = self.webapp.server.socket.getsockname()[1] |
| 2901 | |
| 2902 | f = urllib.urlopen("http://localhost:%s/status.json" % port) |
| 2903 | data = f.read() |
| 2904 | |
| 2905 | self.worker.hold_jobs_in_build = False |
| 2906 | self.worker.release() |
| 2907 | self.waitUntilSettled() |
| 2908 | |
| 2909 | data = json.loads(data) |
| 2910 | status_jobs = set() |
| 2911 | for p in data['pipelines']: |
| 2912 | for q in p['change_queues']: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2913 | if q['dependent']: |
| 2914 | self.assertEqual(q['window'], 20) |
| 2915 | else: |
| 2916 | self.assertEqual(q['window'], 0) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2917 | for head in q['heads']: |
| 2918 | for change in head: |
Clark Boylan | af2476f | 2014-01-23 14:47:36 -0800 | [diff] [blame] | 2919 | self.assertTrue(change['active']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2920 | self.assertEqual(change['id'], '1,1') |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2921 | for job in change['jobs']: |
| 2922 | status_jobs.add(job['name']) |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2923 | self.assertIn('project-merge', status_jobs) |
| 2924 | self.assertIn('project-test1', status_jobs) |
| 2925 | self.assertIn('project-test2', status_jobs) |
James E. Blair | 1843a55 | 2013-07-03 14:19:52 -0700 | [diff] [blame] | 2926 | |
James E. Blair | c3d428e | 2013-12-03 15:06:48 -0800 | [diff] [blame] | 2927 | def test_merging_queues(self): |
| 2928 | "Test that transitively-connected change queues are merged" |
| 2929 | self.config.set('zuul', 'layout_config', |
| 2930 | 'tests/fixtures/layout-merge-queues.yaml') |
| 2931 | self.sched.reconfigure(self.config) |
| 2932 | self.assertEqual(len(self.sched.layout.pipelines['gate'].queues), 1) |
| 2933 | |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2934 | def test_node_label(self): |
| 2935 | "Test that a job runs on a specific node label" |
James E. Blair | 1f4c2bb | 2013-04-26 08:40:46 -0700 | [diff] [blame] | 2936 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2937 | |
| 2938 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 2939 | A.addApproval('CRVW', 2) |
| 2940 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2941 | self.waitUntilSettled() |
James E. Blair | 4ca985f | 2013-05-30 12:27:43 -0700 | [diff] [blame] | 2942 | |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2943 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2944 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2945 | 'debian') |
| 2946 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
James E. Blair | cdccd97 | 2013-07-01 12:10:22 -0700 | [diff] [blame] | 2947 | |
| 2948 | def test_live_reconfiguration(self): |
| 2949 | "Test that live reconfiguration works" |
| 2950 | self.worker.hold_jobs_in_build = True |
| 2951 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 2952 | A.addApproval('CRVW', 2) |
| 2953 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2954 | self.waitUntilSettled() |
| 2955 | |
| 2956 | self.sched.reconfigure(self.config) |
| 2957 | |
| 2958 | self.worker.hold_jobs_in_build = False |
| 2959 | self.worker.release() |
| 2960 | self.waitUntilSettled() |
Monty Taylor | 98f0f3e | 2013-07-06 16:02:31 -0400 | [diff] [blame] | 2961 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 2962 | 'SUCCESS') |
| 2963 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 2964 | 'SUCCESS') |
| 2965 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 2966 | 'SUCCESS') |
| 2967 | self.assertEqual(A.data['status'], 'MERGED') |
| 2968 | self.assertEqual(A.reported, 2) |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 2969 | |
James E. Blair | e712d9f | 2013-07-31 11:40:11 -0700 | [diff] [blame] | 2970 | def test_live_reconfiguration_functions(self): |
| 2971 | "Test live reconfiguration with a custom function" |
| 2972 | self.worker.registerFunction('build:node-project-test1:debian') |
| 2973 | self.worker.registerFunction('build:node-project-test1:wheezy') |
| 2974 | A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') |
| 2975 | A.addApproval('CRVW', 2) |
| 2976 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 2977 | self.waitUntilSettled() |
| 2978 | |
| 2979 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2980 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2981 | 'debian') |
| 2982 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2983 | |
| 2984 | self.config.set('zuul', 'layout_config', |
| 2985 | 'tests/fixtures/layout-live-' |
| 2986 | 'reconfiguration-functions.yaml') |
| 2987 | self.sched.reconfigure(self.config) |
| 2988 | self.worker.build_history = [] |
| 2989 | |
| 2990 | B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') |
| 2991 | B.addApproval('CRVW', 2) |
| 2992 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 2993 | self.waitUntilSettled() |
| 2994 | |
| 2995 | self.assertIsNone(self.getJobFromHistory('node-project-merge').node) |
| 2996 | self.assertEqual(self.getJobFromHistory('node-project-test1').node, |
| 2997 | 'wheezy') |
| 2998 | self.assertIsNone(self.getJobFromHistory('node-project-test2').node) |
| 2999 | |
James E. Blair | 287c06d | 2013-07-24 10:39:30 -0700 | [diff] [blame] | 3000 | def test_delayed_repo_init(self): |
| 3001 | self.config.set('zuul', 'layout_config', |
| 3002 | 'tests/fixtures/layout-delayed-repo-init.yaml') |
| 3003 | self.sched.reconfigure(self.config) |
| 3004 | |
| 3005 | self.init_repo("org/new-project") |
| 3006 | A = self.fake_gerrit.addFakeChange('org/new-project', 'master', 'A') |
| 3007 | |
| 3008 | A.addApproval('CRVW', 2) |
| 3009 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3010 | self.waitUntilSettled() |
| 3011 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3012 | 'SUCCESS') |
| 3013 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3014 | 'SUCCESS') |
| 3015 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3016 | 'SUCCESS') |
| 3017 | self.assertEqual(A.data['status'], 'MERGED') |
| 3018 | self.assertEqual(A.reported, 2) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3019 | |
Clark Boylan | 6dbbc48 | 2013-10-18 10:57:31 -0700 | [diff] [blame] | 3020 | def test_repo_deleted(self): |
| 3021 | self.config.set('zuul', 'layout_config', |
| 3022 | 'tests/fixtures/layout-repo-deleted.yaml') |
| 3023 | self.sched.reconfigure(self.config) |
| 3024 | |
| 3025 | self.init_repo("org/delete-project") |
| 3026 | A = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'A') |
| 3027 | |
| 3028 | A.addApproval('CRVW', 2) |
| 3029 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3030 | self.waitUntilSettled() |
| 3031 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3032 | 'SUCCESS') |
| 3033 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3034 | 'SUCCESS') |
| 3035 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3036 | 'SUCCESS') |
| 3037 | self.assertEqual(A.data['status'], 'MERGED') |
| 3038 | self.assertEqual(A.reported, 2) |
| 3039 | |
| 3040 | # Delete org/new-project zuul repo. Should be recloned. |
| 3041 | shutil.rmtree(os.path.join(self.git_root, "org/delete-project")) |
| 3042 | |
| 3043 | B = self.fake_gerrit.addFakeChange('org/delete-project', 'master', 'B') |
| 3044 | |
| 3045 | B.addApproval('CRVW', 2) |
| 3046 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3047 | self.waitUntilSettled() |
| 3048 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3049 | 'SUCCESS') |
| 3050 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3051 | 'SUCCESS') |
| 3052 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3053 | 'SUCCESS') |
| 3054 | self.assertEqual(B.data['status'], 'MERGED') |
| 3055 | self.assertEqual(B.reported, 2) |
| 3056 | |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3057 | def test_timer(self): |
| 3058 | "Test that a periodic job is triggered" |
| 3059 | self.worker.hold_jobs_in_build = True |
| 3060 | self.config.set('zuul', 'layout_config', |
| 3061 | 'tests/fixtures/layout-timer.yaml') |
| 3062 | self.sched.reconfigure(self.config) |
| 3063 | self.registerJobs() |
| 3064 | |
| 3065 | start = time.time() |
| 3066 | failed = True |
| 3067 | while ((time.time() - start) < 30): |
| 3068 | if len(self.builds) == 2: |
| 3069 | failed = False |
| 3070 | break |
| 3071 | else: |
| 3072 | time.sleep(1) |
| 3073 | |
| 3074 | if failed: |
| 3075 | raise Exception("Expected jobs never ran") |
| 3076 | |
| 3077 | self.waitUntilSettled() |
| 3078 | port = self.webapp.server.socket.getsockname()[1] |
| 3079 | |
| 3080 | f = urllib.urlopen("http://localhost:%s/status.json" % port) |
| 3081 | data = f.read() |
| 3082 | |
| 3083 | self.worker.hold_jobs_in_build = False |
| 3084 | self.worker.release() |
| 3085 | self.waitUntilSettled() |
| 3086 | |
| 3087 | self.assertEqual(self.getJobFromHistory( |
| 3088 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3089 | self.assertEqual(self.getJobFromHistory( |
| 3090 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3091 | |
| 3092 | data = json.loads(data) |
| 3093 | status_jobs = set() |
| 3094 | for p in data['pipelines']: |
| 3095 | for q in p['change_queues']: |
| 3096 | for head in q['heads']: |
| 3097 | for change in head: |
Alex Gaynor | ddb9ef3 | 2013-09-16 21:04:58 -0700 | [diff] [blame] | 3098 | self.assertEqual(change['id'], None) |
James E. Blair | 63bb0ef | 2013-07-29 17:14:51 -0700 | [diff] [blame] | 3099 | for job in change['jobs']: |
| 3100 | status_jobs.add(job['name']) |
| 3101 | self.assertIn('project-bitrot-stable-old', status_jobs) |
| 3102 | self.assertIn('project-bitrot-stable-older', status_jobs) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3103 | |
| 3104 | def test_check_smtp_pool(self): |
| 3105 | self.config.set('zuul', 'layout_config', |
| 3106 | 'tests/fixtures/layout-smtp.yaml') |
| 3107 | self.sched.reconfigure(self.config) |
| 3108 | |
| 3109 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3110 | self.waitUntilSettled() |
| 3111 | |
| 3112 | self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) |
| 3113 | self.waitUntilSettled() |
| 3114 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3115 | self.assertEqual(len(self.smtp_messages), 2) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3116 | |
| 3117 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3118 | # work on the knowledge of what the first message should be as |
| 3119 | # it is only configured to go to SMTP. |
| 3120 | |
| 3121 | self.assertEqual('zuul@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3122 | self.smtp_messages[0]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3123 | self.assertEqual(['you@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3124 | self.smtp_messages[0]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3125 | self.assertEqual('Starting check jobs.', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3126 | self.smtp_messages[0]['body']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3127 | |
| 3128 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3129 | self.smtp_messages[1]['from_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3130 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3131 | self.smtp_messages[1]['to_email']) |
Joshua Hesketh | 5fea867 | 2013-08-19 17:32:01 +1000 | [diff] [blame] | 3132 | self.assertEqual(A.messages[0], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3133 | self.smtp_messages[1]['body']) |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3134 | |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3135 | def test_timer_smtp(self): |
| 3136 | "Test that a periodic job is triggered" |
| 3137 | self.config.set('zuul', 'layout_config', |
| 3138 | 'tests/fixtures/layout-timer-smtp.yaml') |
| 3139 | self.sched.reconfigure(self.config) |
| 3140 | self.registerJobs() |
| 3141 | |
| 3142 | start = time.time() |
| 3143 | failed = True |
| 3144 | while ((time.time() - start) < 30): |
| 3145 | if len(self.history) == 2: |
| 3146 | failed = False |
| 3147 | break |
| 3148 | else: |
| 3149 | time.sleep(1) |
| 3150 | |
| 3151 | if failed: |
| 3152 | raise Exception("Expected jobs never ran") |
| 3153 | |
| 3154 | self.waitUntilSettled() |
| 3155 | |
| 3156 | self.assertEqual(self.getJobFromHistory( |
| 3157 | 'project-bitrot-stable-old').result, 'SUCCESS') |
| 3158 | self.assertEqual(self.getJobFromHistory( |
| 3159 | 'project-bitrot-stable-older').result, 'SUCCESS') |
| 3160 | |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3161 | self.assertEqual(len(self.smtp_messages), 1) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3162 | |
| 3163 | # A.messages only holds what FakeGerrit places in it. Thus we |
| 3164 | # work on the knowledge of what the first message should be as |
| 3165 | # it is only configured to go to SMTP. |
| 3166 | |
| 3167 | self.assertEqual('zuul_from@example.com', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3168 | self.smtp_messages[0]['from_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3169 | self.assertEqual(['alternative_me@example.com'], |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3170 | self.smtp_messages[0]['to_email']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3171 | self.assertIn('Subject: Periodic check for org/project succeeded', |
James E. Blair | ff80a2f | 2013-12-27 13:24:06 -0800 | [diff] [blame] | 3172 | self.smtp_messages[0]['headers']) |
James E. Blair | e591020 | 2013-12-27 09:50:31 -0800 | [diff] [blame] | 3173 | |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3174 | def test_client_enqueue(self): |
| 3175 | "Test that the RPC client can enqueue a change" |
| 3176 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3177 | A.addApproval('CRVW', 2) |
| 3178 | A.addApproval('APRV', 1) |
| 3179 | |
| 3180 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3181 | self.gearman_server.port) |
| 3182 | r = client.enqueue(pipeline='gate', |
| 3183 | project='org/project', |
| 3184 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3185 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3186 | self.waitUntilSettled() |
| 3187 | self.assertEqual(self.getJobFromHistory('project-merge').result, |
| 3188 | 'SUCCESS') |
| 3189 | self.assertEqual(self.getJobFromHistory('project-test1').result, |
| 3190 | 'SUCCESS') |
| 3191 | self.assertEqual(self.getJobFromHistory('project-test2').result, |
| 3192 | 'SUCCESS') |
| 3193 | self.assertEqual(A.data['status'], 'MERGED') |
| 3194 | self.assertEqual(A.reported, 2) |
| 3195 | self.assertEqual(r, True) |
| 3196 | |
| 3197 | def test_client_enqueue_negative(self): |
| 3198 | "Test that the RPC client returns errors" |
| 3199 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3200 | self.gearman_server.port) |
| 3201 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3202 | "Invalid project"): |
| 3203 | r = client.enqueue(pipeline='gate', |
| 3204 | project='project-does-not-exist', |
| 3205 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3206 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3207 | client.shutdown() |
| 3208 | self.assertEqual(r, False) |
| 3209 | |
| 3210 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3211 | "Invalid pipeline"): |
| 3212 | r = client.enqueue(pipeline='pipeline-does-not-exist', |
| 3213 | project='org/project', |
| 3214 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3215 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3216 | client.shutdown() |
| 3217 | self.assertEqual(r, False) |
| 3218 | |
| 3219 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3220 | "Invalid trigger"): |
| 3221 | r = client.enqueue(pipeline='gate', |
| 3222 | project='org/project', |
| 3223 | trigger='trigger-does-not-exist', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3224 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3225 | client.shutdown() |
| 3226 | self.assertEqual(r, False) |
| 3227 | |
| 3228 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure, |
| 3229 | "Invalid change"): |
| 3230 | r = client.enqueue(pipeline='gate', |
| 3231 | project='org/project', |
| 3232 | trigger='gerrit', |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3233 | change='1,1') |
James E. Blair | ad28e91 | 2013-11-27 10:43:22 -0800 | [diff] [blame] | 3234 | client.shutdown() |
| 3235 | self.assertEqual(r, False) |
| 3236 | |
| 3237 | self.waitUntilSettled() |
| 3238 | self.assertEqual(len(self.history), 0) |
| 3239 | self.assertEqual(len(self.builds), 0) |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3240 | |
| 3241 | def test_client_promote(self): |
| 3242 | "Test that the RPC client can promote a change" |
| 3243 | self.worker.hold_jobs_in_build = True |
| 3244 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3245 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3246 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3247 | A.addApproval('CRVW', 2) |
| 3248 | B.addApproval('CRVW', 2) |
| 3249 | C.addApproval('CRVW', 2) |
| 3250 | |
| 3251 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3252 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3253 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3254 | |
| 3255 | self.waitUntilSettled() |
| 3256 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3257 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3258 | enqueue_times = {} |
| 3259 | for item in items: |
| 3260 | enqueue_times[str(item.change)] = item.enqueue_time |
| 3261 | |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3262 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3263 | self.gearman_server.port) |
| 3264 | r = client.promote(pipeline='gate', |
| 3265 | change_ids=['2,1', '3,1']) |
| 3266 | |
Sean Dague | f39b9ca | 2014-01-10 21:34:35 -0500 | [diff] [blame] | 3267 | # ensure that enqueue times are durable |
| 3268 | items = self.sched.layout.pipelines['gate'].getAllItems() |
| 3269 | for item in items: |
| 3270 | self.assertEqual( |
| 3271 | enqueue_times[str(item.change)], item.enqueue_time) |
| 3272 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3273 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3274 | self.worker.release('.*-merge') |
| 3275 | self.waitUntilSettled() |
| 3276 | self.worker.release('.*-merge') |
| 3277 | self.waitUntilSettled() |
| 3278 | self.worker.release('.*-merge') |
| 3279 | self.waitUntilSettled() |
| 3280 | |
| 3281 | self.assertEqual(len(self.builds), 6) |
| 3282 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3283 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3284 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3285 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3286 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3287 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3288 | |
| 3289 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3290 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3291 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3292 | |
| 3293 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3294 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3295 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3296 | |
| 3297 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3298 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3299 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3300 | |
| 3301 | self.worker.release() |
| 3302 | self.waitUntilSettled() |
| 3303 | |
| 3304 | self.assertEqual(A.data['status'], 'MERGED') |
| 3305 | self.assertEqual(A.reported, 2) |
| 3306 | self.assertEqual(B.data['status'], 'MERGED') |
| 3307 | self.assertEqual(B.reported, 2) |
| 3308 | self.assertEqual(C.data['status'], 'MERGED') |
| 3309 | self.assertEqual(C.reported, 2) |
| 3310 | |
| 3311 | client.shutdown() |
| 3312 | self.assertEqual(r, True) |
| 3313 | |
| 3314 | def test_client_promote_dependent(self): |
| 3315 | "Test that the RPC client can promote a dependent change" |
| 3316 | # C (depends on B) -> B -> A ; then promote C to get: |
| 3317 | # A -> C (depends on B) -> B |
| 3318 | self.worker.hold_jobs_in_build = True |
| 3319 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3320 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3321 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3322 | |
| 3323 | C.setDependsOn(B, 1) |
| 3324 | |
| 3325 | A.addApproval('CRVW', 2) |
| 3326 | B.addApproval('CRVW', 2) |
| 3327 | C.addApproval('CRVW', 2) |
| 3328 | |
| 3329 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3330 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3331 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3332 | |
| 3333 | self.waitUntilSettled() |
| 3334 | |
| 3335 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3336 | self.gearman_server.port) |
| 3337 | r = client.promote(pipeline='gate', |
| 3338 | change_ids=['3,1']) |
| 3339 | |
James E. Blair | 78acec9 | 2014-02-06 07:11:32 -0800 | [diff] [blame] | 3340 | self.waitUntilSettled() |
James E. Blair | 36658cf | 2013-12-06 17:53:48 -0800 | [diff] [blame] | 3341 | self.worker.release('.*-merge') |
| 3342 | self.waitUntilSettled() |
| 3343 | self.worker.release('.*-merge') |
| 3344 | self.waitUntilSettled() |
| 3345 | self.worker.release('.*-merge') |
| 3346 | self.waitUntilSettled() |
| 3347 | |
| 3348 | self.assertEqual(len(self.builds), 6) |
| 3349 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3350 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3351 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3352 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3353 | self.assertEqual(self.builds[4].name, 'project-test1') |
| 3354 | self.assertEqual(self.builds[5].name, 'project-test2') |
| 3355 | |
| 3356 | self.assertTrue(self.job_has_changes(self.builds[0], B)) |
| 3357 | self.assertFalse(self.job_has_changes(self.builds[0], A)) |
| 3358 | self.assertFalse(self.job_has_changes(self.builds[0], C)) |
| 3359 | |
| 3360 | self.assertTrue(self.job_has_changes(self.builds[2], B)) |
| 3361 | self.assertTrue(self.job_has_changes(self.builds[2], C)) |
| 3362 | self.assertFalse(self.job_has_changes(self.builds[2], A)) |
| 3363 | |
| 3364 | self.assertTrue(self.job_has_changes(self.builds[4], B)) |
| 3365 | self.assertTrue(self.job_has_changes(self.builds[4], C)) |
| 3366 | self.assertTrue(self.job_has_changes(self.builds[4], A)) |
| 3367 | |
| 3368 | self.worker.release() |
| 3369 | self.waitUntilSettled() |
| 3370 | |
| 3371 | self.assertEqual(A.data['status'], 'MERGED') |
| 3372 | self.assertEqual(A.reported, 2) |
| 3373 | self.assertEqual(B.data['status'], 'MERGED') |
| 3374 | self.assertEqual(B.reported, 2) |
| 3375 | self.assertEqual(C.data['status'], 'MERGED') |
| 3376 | self.assertEqual(C.reported, 2) |
| 3377 | |
| 3378 | client.shutdown() |
| 3379 | self.assertEqual(r, True) |
| 3380 | |
| 3381 | def test_client_promote_negative(self): |
| 3382 | "Test that the RPC client returns errors for promotion" |
| 3383 | self.worker.hold_jobs_in_build = True |
| 3384 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3385 | A.addApproval('CRVW', 2) |
| 3386 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3387 | self.waitUntilSettled() |
| 3388 | |
| 3389 | client = zuul.rpcclient.RPCClient('127.0.0.1', |
| 3390 | self.gearman_server.port) |
| 3391 | |
| 3392 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3393 | r = client.promote(pipeline='nonexistent', |
| 3394 | change_ids=['2,1', '3,1']) |
| 3395 | client.shutdown() |
| 3396 | self.assertEqual(r, False) |
| 3397 | |
| 3398 | with testtools.ExpectedException(zuul.rpcclient.RPCFailure): |
| 3399 | r = client.promote(pipeline='gate', |
| 3400 | change_ids=['4,1']) |
| 3401 | client.shutdown() |
| 3402 | self.assertEqual(r, False) |
| 3403 | |
| 3404 | self.worker.hold_jobs_in_build = False |
| 3405 | self.worker.release() |
| 3406 | self.waitUntilSettled() |
Clark Boylan | 7603a37 | 2014-01-21 11:43:20 -0800 | [diff] [blame] | 3407 | |
| 3408 | def test_queue_rate_limiting(self): |
| 3409 | "Test that DependentPipelines are rate limited with dep across window" |
| 3410 | self.config.set('zuul', 'layout_config', |
| 3411 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3412 | self.sched.reconfigure(self.config) |
| 3413 | self.worker.hold_jobs_in_build = True |
| 3414 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3415 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3416 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3417 | |
| 3418 | C.setDependsOn(B, 1) |
| 3419 | self.worker.addFailTest('project-test1', A) |
| 3420 | |
| 3421 | A.addApproval('CRVW', 2) |
| 3422 | B.addApproval('CRVW', 2) |
| 3423 | C.addApproval('CRVW', 2) |
| 3424 | |
| 3425 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3426 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3427 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3428 | self.waitUntilSettled() |
| 3429 | |
| 3430 | # Only A and B will have their merge jobs queued because |
| 3431 | # window is 2. |
| 3432 | self.assertEqual(len(self.builds), 2) |
| 3433 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3434 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3435 | |
| 3436 | self.worker.release('.*-merge') |
| 3437 | self.waitUntilSettled() |
| 3438 | self.worker.release('.*-merge') |
| 3439 | self.waitUntilSettled() |
| 3440 | |
| 3441 | # Only A and B will have their test jobs queued because |
| 3442 | # window is 2. |
| 3443 | self.assertEqual(len(self.builds), 4) |
| 3444 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3445 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3446 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3447 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3448 | |
| 3449 | self.worker.release('project-.*') |
| 3450 | self.waitUntilSettled() |
| 3451 | |
| 3452 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3453 | # A failed so window is reduced by 1 to 1. |
| 3454 | self.assertEqual(queue.window, 1) |
| 3455 | self.assertEqual(queue.window_floor, 1) |
| 3456 | self.assertEqual(A.data['status'], 'NEW') |
| 3457 | |
| 3458 | # Gate is reset and only B's merge job is queued because |
| 3459 | # window shrunk to 1. |
| 3460 | self.assertEqual(len(self.builds), 1) |
| 3461 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3462 | |
| 3463 | self.worker.release('.*-merge') |
| 3464 | self.waitUntilSettled() |
| 3465 | |
| 3466 | # Only B's test jobs are queued because window is still 1. |
| 3467 | self.assertEqual(len(self.builds), 2) |
| 3468 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3469 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3470 | |
| 3471 | self.worker.release('project-.*') |
| 3472 | self.waitUntilSettled() |
| 3473 | |
| 3474 | # B was successfully merged so window is increased to 2. |
| 3475 | self.assertEqual(queue.window, 2) |
| 3476 | self.assertEqual(queue.window_floor, 1) |
| 3477 | self.assertEqual(B.data['status'], 'MERGED') |
| 3478 | |
| 3479 | # Only C is left and its merge job is queued. |
| 3480 | self.assertEqual(len(self.builds), 1) |
| 3481 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3482 | |
| 3483 | self.worker.release('.*-merge') |
| 3484 | self.waitUntilSettled() |
| 3485 | |
| 3486 | # After successful merge job the test jobs for C are queued. |
| 3487 | self.assertEqual(len(self.builds), 2) |
| 3488 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3489 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3490 | |
| 3491 | self.worker.release('project-.*') |
| 3492 | self.waitUntilSettled() |
| 3493 | |
| 3494 | # C successfully merged so window is bumped to 3. |
| 3495 | self.assertEqual(queue.window, 3) |
| 3496 | self.assertEqual(queue.window_floor, 1) |
| 3497 | self.assertEqual(C.data['status'], 'MERGED') |
| 3498 | |
| 3499 | def test_queue_rate_limiting_dependent(self): |
| 3500 | "Test that DependentPipelines are rate limited with dep in window" |
| 3501 | self.config.set('zuul', 'layout_config', |
| 3502 | 'tests/fixtures/layout-rate-limit.yaml') |
| 3503 | self.sched.reconfigure(self.config) |
| 3504 | self.worker.hold_jobs_in_build = True |
| 3505 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 3506 | B = self.fake_gerrit.addFakeChange('org/project', 'master', 'B') |
| 3507 | C = self.fake_gerrit.addFakeChange('org/project', 'master', 'C') |
| 3508 | |
| 3509 | B.setDependsOn(A, 1) |
| 3510 | |
| 3511 | self.worker.addFailTest('project-test1', A) |
| 3512 | |
| 3513 | A.addApproval('CRVW', 2) |
| 3514 | B.addApproval('CRVW', 2) |
| 3515 | C.addApproval('CRVW', 2) |
| 3516 | |
| 3517 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 3518 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 3519 | self.fake_gerrit.addEvent(C.addApproval('APRV', 1)) |
| 3520 | self.waitUntilSettled() |
| 3521 | |
| 3522 | # Only A and B will have their merge jobs queued because |
| 3523 | # window is 2. |
| 3524 | self.assertEqual(len(self.builds), 2) |
| 3525 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3526 | self.assertEqual(self.builds[1].name, 'project-merge') |
| 3527 | |
| 3528 | self.worker.release('.*-merge') |
| 3529 | self.waitUntilSettled() |
| 3530 | self.worker.release('.*-merge') |
| 3531 | self.waitUntilSettled() |
| 3532 | |
| 3533 | # Only A and B will have their test jobs queued because |
| 3534 | # window is 2. |
| 3535 | self.assertEqual(len(self.builds), 4) |
| 3536 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3537 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3538 | self.assertEqual(self.builds[2].name, 'project-test1') |
| 3539 | self.assertEqual(self.builds[3].name, 'project-test2') |
| 3540 | |
| 3541 | self.worker.release('project-.*') |
| 3542 | self.waitUntilSettled() |
| 3543 | |
| 3544 | queue = self.sched.layout.pipelines['gate'].queues[0] |
| 3545 | # A failed so window is reduced by 1 to 1. |
| 3546 | self.assertEqual(queue.window, 1) |
| 3547 | self.assertEqual(queue.window_floor, 1) |
| 3548 | self.assertEqual(A.data['status'], 'NEW') |
| 3549 | self.assertEqual(B.data['status'], 'NEW') |
| 3550 | |
| 3551 | # Gate is reset and only C's merge job is queued because |
| 3552 | # window shrunk to 1 and A and B were dequeued. |
| 3553 | self.assertEqual(len(self.builds), 1) |
| 3554 | self.assertEqual(self.builds[0].name, 'project-merge') |
| 3555 | |
| 3556 | self.worker.release('.*-merge') |
| 3557 | self.waitUntilSettled() |
| 3558 | |
| 3559 | # Only C's test jobs are queued because window is still 1. |
| 3560 | self.assertEqual(len(self.builds), 2) |
| 3561 | self.assertEqual(self.builds[0].name, 'project-test1') |
| 3562 | self.assertEqual(self.builds[1].name, 'project-test2') |
| 3563 | |
| 3564 | self.worker.release('project-.*') |
| 3565 | self.waitUntilSettled() |
| 3566 | |
| 3567 | # C was successfully merged so window is increased to 2. |
| 3568 | self.assertEqual(queue.window, 2) |
| 3569 | self.assertEqual(queue.window_floor, 1) |
| 3570 | self.assertEqual(C.data['status'], 'MERGED') |