Skip to content

Commit

Permalink
OnAccept, OnReject, OnComplete, tested with samples-go
Browse files Browse the repository at this point in the history
  • Loading branch information
yuandrew committed Nov 22, 2024
1 parent 494d4a7 commit 23d82bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions internal/workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ type (
// Tests are welcome to implement their own version of this interface if they need to test more complex
// update logic. This is a simple implementation to make testing basic Workflow Updates easier.
TestUpdateCallback struct {
accept func()
reject func(error)
complete func(interface{}, error)
OnAccept func()
OnReject func(error)
OnComplete func(interface{}, error)
}
)

Expand Down Expand Up @@ -778,15 +778,15 @@ func (c *MockCallWrapper) NotBefore(calls ...*MockCallWrapper) *MockCallWrapper
}

func (uc *TestUpdateCallback) Accept() {
uc.accept()
uc.OnAccept()
}

func (uc *TestUpdateCallback) Reject(err error) {
uc.reject(err)
uc.OnReject(err)
}

func (uc *TestUpdateCallback) Complete(success interface{}, err error) {
uc.complete(success, err)
uc.OnComplete(success, err)
}

// ExecuteWorkflow executes a workflow, wait until workflow complete. It will fail the test if workflow is blocked and
Expand Down Expand Up @@ -1103,11 +1103,11 @@ func (e *TestWorkflowEnvironment) UpdateWorkflowByID(workflowID, updateName, upd

func (e *TestWorkflowEnvironment) UpdateWorkflowNoRejection(updateName string, updateID string, t mock.TestingT, args ...interface{}) {
uc := &TestUpdateCallback{
reject: func(err error) {
OnReject: func(err error) {
require.Fail(t, "update should not be rejected")
},
accept: func() {},
complete: func(interface{}, error) {},
OnAccept: func() {},
OnComplete: func(interface{}, error) {},
}
e.UpdateWorkflow(updateName, updateID, uc, args)
}
Expand Down
24 changes: 12 additions & 12 deletions internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ func TestWorkflowIDUpdateWorkflowByID(t *testing.T) {
env := suite.NewTestWorkflowEnvironment()
env.RegisterDelayedCallback(func() {
err := env.UpdateWorkflowByID("my-workflow-id", "update", "id", &TestUpdateCallback{
reject: func(err error) {
OnReject: func(err error) {
require.Fail(t, "update should not be rejected")
},
accept: func() {},
complete: func(interface{}, error) {},
OnAccept: func() {},
OnComplete: func(interface{}, error) {},
}, "input")
require.NoError(t, err)
}, time.Second)
Expand Down Expand Up @@ -312,12 +312,12 @@ func TestChildWorkflowUpdate(t *testing.T) {
})
env.RegisterDelayedCallback(func() {
err := env.UpdateWorkflowByID("child-workflow", "child-handler", "1", &TestUpdateCallback{
accept: func() {
OnAccept: func() {
},
reject: func(err error) {
OnReject: func(err error) {
require.Fail(t, "update failed", err)
},
complete: func(result interface{}, err error) {
OnComplete: func(result interface{}, err error) {
if err != nil {
require.Fail(t, "update failed", err)
}
Expand Down Expand Up @@ -402,13 +402,13 @@ func TestWorkflowNotRegisteredRejected(t *testing.T) {
var updateRejectionErr error
env.RegisterDelayedCallback(func() {
env.UpdateWorkflow("update", "id", &TestUpdateCallback{
reject: func(err error) {
OnReject: func(err error) {
updateRejectionErr = err
},
accept: func() {
OnAccept: func() {
require.Fail(t, "update should not be accepted")
},
complete: func(interface{}, error) {},
OnComplete: func(interface{}, error) {},
})
}, 0)

Expand All @@ -433,13 +433,13 @@ func TestWorkflowUpdateOrderAcceptReject(t *testing.T) {
var updateRejectionErr error
env.RegisterDelayedCallback(func() {
env.UpdateWorkflow("bad update", "2", &TestUpdateCallback{
reject: func(err error) {
OnReject: func(err error) {
updateRejectionErr = err
},
accept: func() {
OnAccept: func() {
require.Fail(t, "update should not be accepted")
},
complete: func(interface{}, error) {},
OnComplete: func(interface{}, error) {},
})
}, 0)

Expand Down

0 comments on commit 23d82bd

Please sign in to comment.