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