serverlessworkflow/sdk-go

nil pointer on Events timeouts

spolti opened this issue · 8 comments

What happened:
While trying to parse a workflow file the event timeouts (all types) was getting a nil pointer.

What you expected to happen:
The parsed timeout values.

How to reproduce it:
Create a workflow with events timeouts and try to parse it using the FromFile func.
e.g.:

  - name: ParallelExec
    type: parallel
    completionType: allOf
    branches:
      - name: ShortDelayBranch
        actions:
          - subFlowRef: shortdelayworkflowid
        actionExecTimeout: "PT5H"
        branchExecTimeout: "PT6M"
      - name: LongDelayBranch
        actions:
          - subFlowRef: longdelayworkflowid
    timeouts:
      branchExecTimeout: "PT6M"
      stateExecTimeout:
        total: PT1S
        single: PT2S

And when trying to assert them, a nil would happen:

assert.Equal(t, "PT5H", w.States[2].(*model.ParallelState).Branches[0].Timeouts.ActionExecTimeout)
assert.Equal(t, "PT6M", w.States[2].(*model.ParallelState).Branches[0].Timeouts.BranchExecTimeout)

Anything else we need to know?:

Environment:

  • Specification version used:
  • Go version:

I can't reproduce this issue. This is how did i do:

add below content to continue-as-example.yaml files 36-41 line:
image

add below code to testcase:
image

and the unittest works as expected. can you add a commit just fail this unittest?

Indeed, it actually happens on the ParrallelState, let me update it.

also with EventBasedSwitchState, DataBasedSwitchState

There is a small issue also with the default forEach mode, when not set it should default to parallel, which is not happening.

    parser_test.go:189: 
        	Error Trace:	parser_test.go:189
        	            				parser_test.go:503
        	Error:      	Not equal: 
        	            	expected: "parallel"
        	            	actual  : ""
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,2 @@
        	            	-(model.ForEachModeType) (len=8) "parallel"
        	            	+(model.ForEachModeType) ""
        	            	 
        	Test:       	TestFromFile/./testdata/workflows/greetings-v08-spec.sw.yaml

aha,i think there is a misunderstand of specification. According to the specification https://github.com/serverlessworkflow/specification/blob/0.8.x/specification.md#Parallel-State-Branch, Branch doesn't have actionExecTimeout & branchExecTimeout properties (they are under timeouts properties):

image

wdyt?

let's fix this then :)

aha,i think there is a misunderstand of specification. According to the specification https://github.com/serverlessworkflow/specification/blob/0.8.x/specification.md#Parallel-State-Branch, Branch doesn't have actionExecTimeout & branchExecTimeout properties (they are under timeouts properties):

image

wdyt?

That's correct, fixed the yaml here: #104

The test is asserting the correct location:
assert.Equal(t, "PT5H", w.States[2].(*model.ParallelState).Branches[0].Timeouts.ActionExecTimeout)

fixed by #104