From 4bc2fed5504571e5b2c28b719d56269f6607ef3b Mon Sep 17 00:00:00 2001 From: Kamila Borowska Date: Thu, 28 Dec 2023 00:14:28 +0100 Subject: [PATCH] Fix DAG cycle detection (#3049) Previously a graph like this. a <- b ^ ^ | | c <- d Was incorrectly recognized as having a cycle. Fixes #3048. --- pipeline/frontend/yaml/compiler/dag.go | 2 ++ pipeline/frontend/yaml/compiler/dag_test.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pipeline/frontend/yaml/compiler/dag.go b/pipeline/frontend/yaml/compiler/dag.go index 9351006001b..1ce6a9f7386 100644 --- a/pipeline/frontend/yaml/compiler/dag.go +++ b/pipeline/frontend/yaml/compiler/dag.go @@ -102,6 +102,8 @@ func dfsVisit(steps map[string]*dagCompilerStep, name string, visited map[string } } + delete(visited, name) + return nil } diff --git a/pipeline/frontend/yaml/compiler/dag_test.go b/pipeline/frontend/yaml/compiler/dag_test.go index 1bde0cfc757..e5a9d975d1c 100644 --- a/pipeline/frontend/yaml/compiler/dag_test.go +++ b/pipeline/frontend/yaml/compiler/dag_test.go @@ -51,6 +51,26 @@ func TestConvertDAGToStages(t *testing.T) { _, err = convertDAGToStages(steps, "") assert.NoError(t, err) + steps = map[string]*dagCompilerStep{ + "a": { + step: &backend_types.Step{}, + }, + "b": { + step: &backend_types.Step{}, + dependsOn: []string{"a"}, + }, + "c": { + step: &backend_types.Step{}, + dependsOn: []string{"a"}, + }, + "d": { + step: &backend_types.Step{}, + dependsOn: []string{"b", "c"}, + }, + } + _, err = convertDAGToStages(steps, "") + assert.NoError(t, err) + steps = map[string]*dagCompilerStep{ "step1": { step: &backend_types.Step{},