Browse Source

Merge "dequeue abandoned changes"

changes/21/103321/1
Jenkins 7 years ago
committed by Gerrit Code Review
parent
commit
ae6b9ee599
  1. 21
      tests/base.py
  2. 31
      tests/test_scheduler.py
  3. 6
      zuul/scheduler.py

21
tests/base.py

@ -210,6 +210,21 @@ class FakeChange(object):
"owner": {"name": "User Name"},
"url": "https://hostname/3"},
"restorer": {"name": "User Name"},
"patchSet": self.patchsets[-1],
"reason": ""}
return event
def getChangeAbandonedEvent(self):
event = {"type": "change-abandoned",
"change": {"project": self.project,
"branch": self.branch,
"id": "I5459869c07352a31bfb1e7a8cac379cabfcb25af",
"number": str(self.number),
"subject": self.subject,
"owner": {"name": "User Name"},
"url": "https://hostname/3"},
"abandoner": {"name": "User Name"},
"patchSet": self.patchsets[-1],
"reason": ""}
return event
@ -920,7 +935,8 @@ class ZuulTestCase(testtools.TestCase):
def assertFinalState(self):
# Make sure that the change cache is cleared
self.assertEqual(len(self.gerrit._change_cache.keys()), 0)
self.assertEqual(len(self.gerrit._change_cache.keys()), 0,
"Change cache should have been cleared")
# Make sure that git.Repo objects have been garbage collected.
repos = []
gc.collect()
@ -1181,7 +1197,8 @@ class ZuulTestCase(testtools.TestCase):
if len(queue.queue) != 0:
print 'pipeline %s queue %s contents %s' % (
pipeline.name, queue.name, queue.queue)
self.assertEqual(len(queue.queue), 0)
self.assertEqual(len(queue.queue), 0,
"Pipelines queues should be empty")
def assertReportedStat(self, key, value=None, kind=None):
start = time.time()

31
tests/test_scheduler.py

@ -39,6 +39,7 @@ logging.basicConfig(level=logging.DEBUG,
class TestScheduler(ZuulTestCase):
def test_jobs_launched(self):
"Test that jobs are launched and a change is merged"
@ -1406,6 +1407,36 @@ class TestScheduler(ZuulTestCase):
self.assertEqual(D.reported, 2)
self.assertEqual(len(self.history), 9) # 3 each for A, B, D.
def test_abandoned_change_dequeues(self):
"Test that an abandoned change is dequeued"
self.worker.hold_jobs_in_build = True
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertEqual(len(self.builds), 1, "One job being built (on hold)")
self.assertEqual(self.builds[0].name, 'project-merge')
self.fake_gerrit.addEvent(A.getChangeAbandonedEvent())
self.waitUntilSettled()
# For debugging purposes...
#for pipeline in self.sched.layout.pipelines.values():
# for queue in pipeline.queues:
# self.log.info("pipepline %s queue %s contents %s" % (
# pipeline.name, queue.name, queue.queue))
self.worker.release('.*-merge')
self.waitUntilSettled()
self.assertEqual(len(self.builds), 0, "No job running")
self.assertEmptyQueues()
self.assertEqual(len(self.history), 1, "Only one build in history")
self.assertEqual(self.history[0].result, 'ABORTED',
'Build should have been aborted')
self.assertEqual(A.reported, 0, "Abandoned change should not report")
def test_zuul_url_return(self):
"Test if ZUUL_URL is returning when zuul_url is set in zuul.conf"
self.assertTrue(self.sched.config.has_option('merger', 'zuul_url'))

6
zuul/scheduler.py

@ -781,6 +781,8 @@ class Scheduler(threading.Thread):
self.triggers.get(event.trigger_name))
if event.type == 'patchset-created':
pipeline.manager.removeOldVersionsOfChange(change)
elif event.type == 'change-abandoned':
pipeline.manager.removeAbandonedChange(change)
if pipeline.manager.eventMatches(event, change):
self.log.info("Adding %s, %s to %s" %
(project, change, pipeline))
@ -1062,6 +1064,10 @@ class BasePipelineManager(object):
(change, old_change, old_change))
self.removeChange(old_change)
def removeAbandonedChange(self, change):
self.log.debug("Change %s abandoned, removing." % change)
self.removeChange(change)
def reEnqueueItem(self, item):
change_queue = self.pipeline.getQueue(item.change.project)
if change_queue:

Loading…
Cancel
Save