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