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