Merge "Don't consider type of dependencies to process"

This commit is contained in:
Zuul 2024-04-15 18:52:11 +00:00 committed by Gerrit Code Review
commit 01e9472306
2 changed files with 30 additions and 4 deletions

View File

@ -620,6 +620,33 @@ class TestGraph(BaseTestCase):
self.assertEqual(set(graph.getParentJobsRecursively(child)),
set(parents) - set([parents[3]]))
def test_soft_dependency_mixed_cycle(self):
# This is a regression test to make sure we are not processing
# jobs twice, when mixing soft/hard dependencies to a job.
graph = model.JobGraph({})
parent = FakeFrozenJob("parent")
graph.addJob(parent)
intermediate = FakeFrozenJob("intermediate")
intermediate.dependencies = frozenset([
# Hard dependency to parent
model.JobDependency(parent.name)
])
graph.addJob(intermediate)
child = FakeFrozenJob("child")
child.dependencies = frozenset([
# Soft dependency to parent
model.JobDependency(parent.name, soft=True),
# Dependency to intermediate, which has a hard dependency
# to parent.
model.JobDependency(intermediate.name),
])
graph.addJob(child)
# We don't expect this to raise an exception
graph.freezeDependencies()
class TestTenant(BaseTestCase):
def test_add_project(self):

View File

@ -3695,10 +3695,10 @@ class JobGraph(object):
def getParentJobsRecursively(self, job, skip_soft=False):
all_dependency_uuids = set()
uuids_to_iterate = set([(job.uuid, False)])
uuids_to_iterate = set([job.uuid])
ancestor_uuids = set()
while len(uuids_to_iterate) > 0:
(current_uuid, current_data) = uuids_to_iterate.pop()
current_uuid = uuids_to_iterate.pop()
if current_uuid in ancestor_uuids:
current_job = self.getJobFromUuid(current_uuid)
raise Exception("Dependency cycle detected in job %s" %
@ -3716,8 +3716,7 @@ class JobGraph(object):
all_dependency_uuids.add(current_uuid)
new_dependency_uuids = (set(current_dependency_uuids.keys()) -
all_dependency_uuids)
for u in new_dependency_uuids:
uuids_to_iterate.add((u, current_dependency_uuids[u]['soft']))
uuids_to_iterate.update(new_dependency_uuids)
return [self.getJobFromUuid(u) for u in all_dependency_uuids]
def getProjectMetadata(self, name):