summaryrefslogtreecommitdiff
path: root/tests/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/base.py')
-rw-r--r--tests/base.py57
1 files changed, 45 insertions, 12 deletions
diff --git a/tests/base.py b/tests/base.py
index 4a4e536a3..a697be384 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -1235,19 +1235,33 @@ class FakePagurePullRequest(object):
return self._getPullRequestEvent(
'pull-request.tag.added', pull_data_field='pull_request')
- def getPullRequestStatusSetEvent(self, status):
+ def getPullRequestStatusSetEvent(self, status, username="zuul"):
self.addFlag(
- status, "https://url", "Build %s" % status)
+ status, "https://url", "Build %s" % status, username)
return self._getPullRequestEvent('pull-request.flag.added')
- def addFlag(self, status, url, comment, username="Pingou"):
+ def insertFlag(self, flag):
+ to_pop = None
+ for i, _flag in enumerate(self.flags):
+ if _flag['uid'] == flag['uid']:
+ to_pop = i
+ if to_pop is not None:
+ self.flags.pop(to_pop)
+ self.flags.insert(0, flag)
+
+ def addFlag(self, status, url, comment, username="zuul"):
+ flag_uid = "%s-%s-%s" % (username, self.number, self.project)
flag = {
- "username": username,
+ "username": "Zuul CI",
+ "user": {
+ "name": username
+ },
+ "uid": flag_uid[:32],
"comment": comment,
"status": status,
"url": url
}
- self.flags.insert(0, flag)
+ self.insertFlag(flag)
self._updateTimeStamp()
def editInitialComment(self, initial_comment):
@@ -1405,13 +1419,18 @@ class FakePagureAPIClient(pagureconnection.PagureAPIClient):
pr.is_merged = True
return {}, 200, "", "POST"
+ match = re.match(r'.+/api/0/-/whoami$', url)
+ if match:
+ return {"username": "zuul"}, 200, "", "POST"
+
if not params:
return self.gen_error("POST")
match = re.match(r'.+/api/0/(.+)/pull-request/(\d+)/flag$', url)
if match:
pr = self._get_pr(match)
- pr.flags.insert(0, params)
+ params['user'] = {"name": "zuul"}
+ pr.insertFlag(params)
match = re.match(r'.+/api/0/(.+)/pull-request/(\d+)/comment$', url)
if match:
@@ -1438,9 +1457,12 @@ class FakePagureConnection(pagureconnection.PagureConnection):
self.cloneurl = self.upstream_root
def get_project_api_client(self, project):
- return FakePagureAPIClient(
+ client = FakePagureAPIClient(
self.baseurl, None, project,
pull_requests_db=self.pull_requests)
+ if not self.username:
+ self.set_my_username(client)
+ return client
def get_project_webhook_token(self, project):
return 'fake_webhook_token-%s' % project
@@ -2663,8 +2685,11 @@ class RecordingExecutorServer(zuul.executor.server.ExecutorServer):
"""
builds = self.running_builds[:]
- self.log.debug("Releasing build %s (%s)" % (regex,
- len(self.running_builds)))
+ if len(builds) == 0:
+ self.log.debug('No running builds to release')
+ return
+
+ self.log.debug("Releasing build %s (%s)" % (regex, len(builds)))
for build in builds:
if not regex or re.match(regex, build.name):
self.log.debug("Releasing build %s" %
@@ -2674,7 +2699,7 @@ class RecordingExecutorServer(zuul.executor.server.ExecutorServer):
self.log.debug("Not releasing build %s" %
(build.parameters['zuul']['build']))
self.log.debug("Done releasing builds %s (%s)" %
- (regex, len(self.running_builds)))
+ (regex, len(builds)))
def executeJob(self, job):
build = FakeBuild(self, job)
@@ -4376,7 +4401,9 @@ class ZuulTestCase(BaseTestCase):
def waitUntilSettled(self, msg="", matcher=None) -> None:
self.log.debug("Waiting until settled... (%s)", msg)
start = time.time()
+ i = 0
while True:
+ i = i + 1
if time.time() - start > self.wait_timeout:
self.log.error("Timeout waiting for Zuul to settle")
self.log.error("Queue status:")
@@ -4393,9 +4420,10 @@ class ZuulTestCase(BaseTestCase):
self.log.error("[Sched: %s] Merge client jobs: %s" %
(app.sched, app.sched.merger.jobs,))
raise Exception("Timeout waiting for Zuul to settle")
- # Make sure no new events show up while we're checking
+ # Make sure no new events show up while we're checking
self.executor_server.lock.acquire()
+
# have all build states propogated to zuul?
if self.__haveAllBuildsReported(matcher):
# Join ensures that the queue is empty _and_ events have been
@@ -4416,7 +4444,8 @@ class ZuulTestCase(BaseTestCase):
self.scheds.execute(
lambda app: app.sched.run_handler_lock.release())
self.executor_server.lock.release()
- self.log.debug("...settled. (%s)", msg)
+ self.log.debug("...settled after %.3f ms / %s loops (%s)",
+ time.time() - start, i, msg)
self.logState()
return
self.scheds.execute(
@@ -4665,6 +4694,10 @@ class ZuulTestCase(BaseTestCase):
completed.
"""
+ if not self.history:
+ self.log.debug("Build history: no builds ran")
+ return
+
self.log.debug("Build history:")
for build in self.history:
self.log.debug(build)