Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yuandrew committed Oct 29, 2024
1 parent 47057fe commit 5639859
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
5 changes: 1 addition & 4 deletions internal/internal_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ type (
// Complete is called for an update with the result of executing the
// update function. If the provided error is non-nil then the overall
// outcome is understood to be a failure.
Complete(success interface{}, err error) // not sure i should change the API here
// TODO: add an ID identity?
// no, it doesn't make sense to add it here

Complete(success interface{}, err error)
}

// UpdateScheduler allows an update state machine to spawn coroutines and
Expand Down
4 changes: 1 addition & 3 deletions internal/internal_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1406,9 +1406,7 @@ type updateCallback struct {
accept func()
reject func(error)
complete func(interface{}, error)
// TODO: How do I capture env from this struct?
// it won't work to require env to be passed in
env *TestWorkflowEnvironment
env *TestWorkflowEnvironment
}

func (uc *updateCallback) Accept() {
Expand Down
4 changes: 1 addition & 3 deletions internal/internal_workflow_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,6 @@ func (env *testWorkflowEnvironmentImpl) RegisterUpdateHandler(
handler func(name string, id string, input *commonpb.Payloads, header *commonpb.Header, resp UpdateCallbacks),
) {
env.updateHandler = handler

}

func (env *testWorkflowEnvironmentImpl) RegisterQueryHandler(
Expand Down Expand Up @@ -2725,20 +2724,19 @@ func (env *testWorkflowEnvironmentImpl) updateWorkflow(name string, id string, u
if err != nil {
panic(err)
}
// Some way to capture state of the update
if env.updateMap == nil {
env.updateMap = make(map[string]interface{})
}

// check for duplicate update ID
if _, ok := env.updateMap[id]; ok {
// return cached result
env.postCallback(func() {
uc.Accept()
uc.Complete(env.updateMap[id], nil)
}, false)
} else {
env.currentUpdateId = id
// return cached state
env.postCallback(func() {
// Do not send any headers on test invocations
env.updateHandler(name, id, data, nil, uc)
Expand Down
5 changes: 1 addition & 4 deletions internal/workflow_testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"errors"
"fmt"
"log/slog"
"runtime/debug"
"strings"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -502,7 +501,6 @@ func TestWorkflowDuplicateIDDedup(t *testing.T) {
require.Fail(t, fmt.Sprintf("update should not be rejected, err: %v", err))
},
accept: func() {
debug.PrintStack()
},
complete: func(result interface{}, err error) {
intResult, ok := result.(int)
Expand All @@ -519,7 +517,7 @@ func TestWorkflowDuplicateIDDedup(t *testing.T) {
env.RegisterDelayedCallback(func() {
env.UpdateWorkflow("update", "id", &updateCallback{
reject: func(err error) {
require.Fail(t, "update should not be rejected")
require.Fail(t, fmt.Sprintf("update should not be rejected, err: %v", err))
},
accept: func() {
},
Expand Down Expand Up @@ -548,7 +546,6 @@ func TestWorkflowDuplicateIDDedup(t *testing.T) {
return Sleep(ctx, time.Hour)
})
require.NoError(t, env.GetWorkflowError())
require.True(t, false)
}

func TestAllHandlersFinished(t *testing.T) {
Expand Down

0 comments on commit 5639859

Please sign in to comment.