Fix early processing of merge-pending items on reconfig
On a reconfiguration, when we re-enqueue an item, we could end
up creating a job graph for an item before the merge for that
item has returned. Make sure we use the same methods that the
main processing loop uses so that we maintain the state machine
around waiting for merges and dynamic layouts.
Change-Id: I2b99620cfe1f7666ee3e6297ce041b3f7a02e051
diff --git a/tests/base.py b/tests/base.py
index 5841c08..dacb1ef 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -1570,7 +1570,7 @@
parameters = json.loads(job.arguments.decode('utf8'))
if not regex or re.match(regex, parameters.get('job')):
match = True
- if job.name == b'merger:merge':
+ if job.name.startswith(b'merger:'):
if not regex:
match = True
if match:
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index 65a37ff..906c336 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -4715,6 +4715,28 @@
build = self.getJobFromHistory('py27')
self.assertEqual(build.parameters['zuul']['jobtags'], [])
+ def test_pending_merge_in_reconfig(self):
+ # Test that if we are waiting for an outstanding merge on
+ # reconfiguration that we continue to do so.
+ self.gearman_server.hold_merge_jobs_in_queue = True
+ A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
+ A.setMerged()
+ self.fake_gerrit.addEvent(A.getRefUpdatedEvent())
+ self.waitUntilSettled()
+ # Reconfigure while we still have an outstanding merge job
+ self.sched.reconfigureTenant(self.sched.abide.tenants['tenant-one'],
+ None)
+ self.waitUntilSettled()
+ # Verify the merge job is still running and that the item is
+ # in the pipeline
+ self.assertEqual(len(self.sched.merger.jobs), 1)
+ tenant = self.sched.abide.tenants.get('tenant-one')
+ pipeline = tenant.layout.pipelines['post']
+ self.assertEqual(len(pipeline.getAllItems()), 1)
+ self.gearman_server.hold_merge_jobs_in_queue = False
+ self.gearman_server.release()
+ self.waitUntilSettled()
+
class TestExecutor(ZuulTestCase):
tenant_config_file = 'config/single-tenant/main.yaml'