-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow no state or not start state (#59)
- Loading branch information
1 parent
35fed84
commit d0397b3
Showing
25 changed files
with
213 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package integ | ||
|
||
import ( | ||
"context" | ||
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNoStartStateWorkflow(t *testing.T) { | ||
wfId := "TestNoStartStateWorkflow" + strconv.Itoa(int(time.Now().Unix())) | ||
wf := noStartStateWorkflow{} | ||
|
||
runId, err := client.StartWorkflow(context.Background(), wf, wfId, 10, 1, nil) | ||
assert.Nil(t, err) | ||
assert.NotEmpty(t, runId) | ||
|
||
var rpcOutput int | ||
err = client.InvokeRPC(context.Background(), wfId, "", wf.TestRPC, 1, &rpcOutput) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 2, rpcOutput) | ||
|
||
time.Sleep(time.Second * 2) | ||
info, err := client.DescribeWorkflow(context.Background(), wfId, "") | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwfidl.COMPLETED, info.Status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package integ | ||
|
||
import ( | ||
"github.com/indeedeng/iwf-golang-sdk/iwf" | ||
) | ||
|
||
type noStartStateWorkflow struct { | ||
iwf.WorkflowDefaults | ||
} | ||
|
||
func (b noStartStateWorkflow) GetCommunicationSchema() []iwf.CommunicationMethodDef { | ||
return []iwf.CommunicationMethodDef{ | ||
iwf.RPCMethodDef(b.TestRPC, nil), | ||
} | ||
} | ||
|
||
func (b noStartStateWorkflow) GetWorkflowStates() []iwf.StateDef { | ||
return []iwf.StateDef{ | ||
iwf.NonStartingStateDef(&noStartStateWorkflowState1{}), | ||
} | ||
} | ||
|
||
func (b noStartStateWorkflow) TestRPC(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (interface{}, error) { | ||
var i int | ||
input.Get(&i) | ||
i++ | ||
communication.TriggerStateMovements(iwf.NewStateMovement(noStartStateWorkflowState1{}, nil)) | ||
return i, nil | ||
} | ||
|
||
type noStartStateWorkflowState1 struct { | ||
iwf.WorkflowStateDefaults | ||
iwf.NoWaitUntil | ||
} | ||
|
||
func (b noStartStateWorkflowState1) Execute(ctx iwf.WorkflowContext, input iwf.Object, commandResults iwf.CommandResults, persistence iwf.Persistence, communication iwf.Communication) (*iwf.StateDecision, error) { | ||
return iwf.GracefulCompletingWorkflow, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package integ | ||
|
||
import ( | ||
"context" | ||
"github.com/indeedeng/iwf-golang-sdk/gen/iwfidl" | ||
"github.com/indeedeng/iwf-golang-sdk/iwf" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNoStateWorkflow(t *testing.T) { | ||
wfId := "TestNoStateWorkflow" + strconv.Itoa(int(time.Now().Unix())) | ||
wf := noStateWorkflow{} | ||
|
||
runId, err := client.StartWorkflow(context.Background(), wf, wfId, 10, 1, nil) | ||
assert.Nil(t, err) | ||
assert.NotEmpty(t, runId) | ||
|
||
time.Sleep(time.Second) | ||
info, err := client.DescribeWorkflow(context.Background(), wfId, "") | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwfidl.RUNNING, info.Status) | ||
|
||
err = client.InvokeRPC(context.Background(), wfId, "", wf.TestErrorRPC, 1, nil) | ||
assert.NotNil(t, err) | ||
assert.True(t, iwf.IsRPCError(err)) | ||
rpcErr, _ := err.(*iwf.ApiError) | ||
assert.Equal(t, "worker API error, status:501, errorType:test-error-type", rpcErr.Response.GetDetail()) | ||
|
||
err = client.StopWorkflow(context.Background(), wfId, "", &iwf.WorkflowStopOptions{ | ||
StopType: iwfidl.FAIL, | ||
Reason: "test", | ||
}) | ||
assert.Nil(t, err) | ||
time.Sleep(time.Second * 2) | ||
info, err = client.DescribeWorkflow(context.Background(), wfId, "") | ||
assert.Nil(t, err) | ||
assert.Equal(t, iwfidl.FAILED, info.Status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package integ | ||
|
||
import ( | ||
"fmt" | ||
"github.com/indeedeng/iwf-golang-sdk/iwf" | ||
) | ||
|
||
type noStateWorkflow struct { | ||
iwf.WorkflowDefaults | ||
} | ||
|
||
func (b noStateWorkflow) GetCommunicationSchema() []iwf.CommunicationMethodDef { | ||
return []iwf.CommunicationMethodDef{ | ||
iwf.RPCMethodDef(b.TestErrorRPC, nil), | ||
} | ||
} | ||
|
||
func (b noStateWorkflow) TestErrorRPC(ctx iwf.WorkflowContext, input iwf.Object, persistence iwf.Persistence, communication iwf.Communication) (interface{}, error) { | ||
return nil, fmt.Errorf("test error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.