Merge "Fix merging reconfiguration events"

This commit is contained in:
Zuul 2021-12-14 22:14:39 +00:00 committed by Gerrit Code Review
commit 38fb68ef50
3 changed files with 26 additions and 30 deletions

View File

@ -3631,35 +3631,28 @@ class TestScheduler(ZuulTestCase):
def test_reconfigure_merge(self):
"""Test that two reconfigure events are merged"""
# Wrap the recofiguration handler so we can count how many
# times it runs.
with mock.patch.object(
zuul.scheduler.Scheduler, '_doTenantReconfigureEvent',
wraps=self.scheds.first.sched._doTenantReconfigureEvent
) as mymock:
with self.scheds.first.sched.run_handler_lock:
self.create_branch('org/project', 'stable/diablo')
self.fake_gerrit.addEvent(
self.fake_gerrit.getFakeBranchCreatedEvent(
'org/project', 'stable/diablo'))
self.create_branch('org/project', 'stable/essex')
self.fake_gerrit.addEvent(
self.fake_gerrit.getFakeBranchCreatedEvent(
'org/project', 'stable/essex'))
for _ in iterate_timeout(60, 'jobs started'):
if len(self.scheds.first.sched.trigger_events[
'tenant-one']) == 2:
break
tenant = self.scheds.first.sched.abide.tenants['tenant-one']
(trusted, project) = tenant.getProject('org/project')
management_queue = self.scheds.first.sched.management_events[
'tenant-one']
with self.scheds.first.sched.run_handler_lock:
mgmt_queue_size = len(management_queue)
self.assertEqual(mgmt_queue_size, 0)
self.scheds.first.sched.reconfigureTenant(tenant, project, None)
mgmt_queue_size = len(management_queue)
self.assertEqual(mgmt_queue_size, 1)
self.scheds.first.sched.reconfigureTenant(tenant, project, None)
mgmt_queue_size = len(management_queue)
self.assertEqual(mgmt_queue_size, 2)
# The second event should be combined with the first so we should
# only see the merged entry when consuming from the queue.
mgmt_events = list(management_queue)
self.assertEqual(len(mgmt_events), 1)
self.assertEqual(len(mgmt_events[0].merged_events), 1)
self.waitUntilSettled()
mgmt_queue_size = len(management_queue)
self.assertEqual(mgmt_queue_size, 0)
self.waitUntilSettled()
mymock.assert_called_once()
def test_live_reconfiguration(self):
"Test that live reconfiguration works"

View File

@ -5548,7 +5548,7 @@ class TenantReconfigureEvent(ManagementEvent):
if self.tenant_name != other.tenant_name:
raise Exception("Can not merge events from different tenants")
self.project_branches |= other.project_branches
for connection_name, ltime in other.branch_cache_ltimes:
for connection_name, ltime in other.branch_cache_ltimes.items():
self.branch_cache_ltimes[connection_name] = max(
self.branch_cache_ltimes.get(connection_name, ltime), ltime)
self.zuul_event_ltime = max(self.zuul_event_ltime,

View File

@ -560,8 +560,11 @@ class ManagementEventQueue(ZooKeeperEventQueue):
if event.zuul_event_ltime is None:
event.zuul_event_ltime = zstat.creation_transaction_id
with suppress(ValueError):
try:
other_event = event_list[event_list.index(event)]
except ValueError:
other_event = None
if other_event:
if isinstance(other_event, model.TenantReconfigureEvent):
other_event.merge(event)
continue