Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Add test code for branch nodes #258

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/compiler/test/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ func TestBranches(t *testing.T) {

t.Run(path, func(t *testing.T) {
// If you want to debug a single use-case. Uncomment this line.
//if !strings.HasSuffix(path, "success_1.json") {
// t.SkipNow()
//}
if !strings.HasSuffix(path, "success_7.json") {
t.SkipNow()
}

raw, err := ioutil.ReadFile(path)
assert.NoError(t, err)
Expand Down
214 changes: 214 additions & 0 deletions pkg/compiler/test/testdata/branch/success_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"workflow": {
"id": {
"resourceType": "WORKFLOW",
"project": "project",
"domain": "domain",
"name": "name",
"version": "version"
},
"metadata": {},
"interface": {
"inputs": {
"variables": {
"my_input": {
"type": {
"simple": "FLOAT"
},
"description": "my_input"
}
}
},
"outputs": {
"variables": {
"o0": {
"type": {
"simple": "FLOAT"
},
"description": "o0"
}
}
}
},
"nodes": [
{
"id": "node-0",
"metadata": {},
"inputs": [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would normally expect not to need to reference ".var-1" and ".var-2"

{
"var": ".var-1",
"binding": {
"promise": {
"var": "my_input",
"nodeId": "start-node"
}
}
},
{
"var": ".var-2",
"binding": {
"promise": {
"var": "my_input",
"nodeId": "start-node"
}
}
},
{
"var": "n",
"binding": {
"promise": {
"var": "my_input",
"nodeId": "start-node"
}
}
}
],
"branchNode": {
"ifElse": {
"case": {
"condition": {
"comparison": {
"operator": "EQ",
"leftValue": {
"var": ".var-1"
},
"rightValue": {
"var": ".var-1"
}
}
},
"thenNode": {
"id": "thenNode-1",
"metadata": {},
"inputs": [
{
"var": ".var-1",
"binding": {
"promise": {
"var": "my_input",
"nodeId": "start-node"
}
}
}
],
"branchNode": {
"ifElse": {
"case": {
"condition": {
"comparison": {
"operator": "EQ",
"leftValue": {
"var": ".var-2"
},
"rightValue": {
"var": ".var-2"
}
}
},
"thenNode": {
"id": "thenNode-2",
"metadata": {},
"inputs": [
{
"var": "n",
"binding": {
"promise": {
"var": "my_input",
"nodeId": "start-node"
}
}
}
],
"taskNode": {
"referenceId": {
"resourceType": "TASK",
"project": "project",
"domain": "domain",
"name": "name",
"version": "version"
}
}
}
},
"error": {
"message": "",
"failedNodeId": ""
}
}
}
}
},
"error": {
"message": "",
"failedNodeId": ""
}
}
}
}
],
"outputs": [
{
"var": "o0",
"binding": {
"promise": {
"nodeId": "node-0",
"var": "o0"
}
}
}
],
"metadataDefaults": {}
},
"tasks": [
{
"id": {
"resourceType": "TASK",
"project": "project",
"domain": "domain",
"name": "name",
"version": "version"
},
"type": "python-task",
"metadata": {},
"interface": {
"inputs": {
"variables": {
"n": {
"type": {
"simple": "FLOAT"
},
"description": "n"
},
".var-1": {
"type": {
"simple": "FLOAT"
},
"description": ".var-1"
},
".var-2": {
"type": {
"simple": "FLOAT"
},
"description": ".var-2"
}
}
},
"outputs": {
"variables": {
"o0": {
"type": {
"simple": "FLOAT"
},
"description": "o0"
}
}
}
},
"container": {
"image": "image:name",
"args": ["command"],
"resources": {}
}
}
]
}
21 changes: 13 additions & 8 deletions pkg/compiler/validators/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,36 @@ func validateBranchInterface(w c.WorkflowBuilder, node c.NodeBuilder, errs error
if iface, ok = ValidateUnderlyingInterface(w, n, errs.NewScope()); ok {
// Clear out the Inputs. We do not care if the inputs of each of the underlying nodes
// match. We will pull the inputs needed for the underlying branch node at runtime.
iface = &flyte.TypedInterface{
Inputs: &flyte.VariableMap{Variables: map[string]*flyte.Variable{}},
Outputs: iface.Outputs,
}
// iface = &flyte.TypedInterface{
// Inputs: &flyte.VariableMap{Variables: map[string]*flyte.Variable{}},
// Outputs: iface.Outputs,
// }

outputs, outputsSet = buildVariablesIndex(iface.Outputs)
finalOutputParameterNames = finalOutputParameterNames.Union(outputsSet)
}
} else {
if iface2, ok2 := ValidateUnderlyingInterface(w, n, errs.NewScope()); ok2 {
iface2 = &flyte.TypedInterface{
Inputs: &flyte.VariableMap{Variables: map[string]*flyte.Variable{}},
Outputs: iface2.Outputs,
}
//iface2 = &flyte.TypedInterface{
// Inputs: &flyte.VariableMap{Variables: map[string]*flyte.Variable{}},
// Outputs: iface2.Outputs,
//}

validateIfaceMatch(n.GetId(), iface2, errs.NewScope())
}
}
}

if !errs.HasErrors() && iface != nil {
print(finalOutputParameterNames)
print(finalInputParameterNames)
/*
iface = &flyte.TypedInterface{
Inputs: filterVariables(iface.Inputs, finalInputParameterNames),
Outputs: filterVariables(iface.Outputs, finalOutputParameterNames),
}
*/
iface = iface
} else {
iface = nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/compiler/validators/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func ValidateNode(w c.WorkflowBuilder, n c.NodeBuilder, validateConditionTypes b
if n.GetBranchNode() != nil {
if nodes, edges, ok := ValidateBranchNode(w, n, validateConditionTypes, errs.NewScope()); ok {
renamedNodes := make(map[c.NodeID]c.NodeID, len(nodes))
for _, subNode := range nodes {
oldID := subNode.GetId()
subNode.SetID(branchNodeIDFormatter(n.GetId(), subNode.GetId()))
w.AddNode(subNode, errs)
renamedNodes[oldID] = subNode.GetId()
}
//for _, subNode := range nodes {
// oldID := subNode.GetId()
// subNode.SetID(branchNodeIDFormatter(n.GetId(), subNode.GetId()))
// w.AddNode(subNode, errs)
// renamedNodes[oldID] = subNode.GetId()
//}

for _, edge := range edges {
if newID, found := renamedNodes[edge.from]; found {
Expand Down