-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dedup duplicate update IDs for test environment #1695
base: master
Are you sure you want to change the base?
Changes from 5 commits
7881da0
2526b8b
d70caf8
47057fe
5639859
d03b73a
fd52f49
16b9ce3
223677f
c3d37eb
809c82e
41c27d9
d49647c
330189d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -491,6 +491,63 @@ func TestWorkflowUpdateOrderAcceptReject(t *testing.T) { | |
require.Equal(t, "unknown update bad update. KnownUpdates=[update]", updateRejectionErr.Error()) | ||
} | ||
|
||
func TestWorkflowDuplicateIDDedup(t *testing.T) { | ||
var suite WorkflowTestSuite | ||
// Test dev server rejects UpdateWorkflow with same ID | ||
env := suite.NewTestWorkflowEnvironment() | ||
env.RegisterDelayedCallback(func() { | ||
env.UpdateWorkflow("update", "id", &updateCallback{ | ||
reject: func(err error) { | ||
require.Fail(t, fmt.Sprintf("update should not be rejected, err: %v", err)) | ||
}, | ||
accept: func() { | ||
}, | ||
complete: func(result interface{}, err error) { | ||
intResult, ok := result.(int) | ||
if !ok { | ||
require.Fail(t, "result should be int") | ||
} else { | ||
require.Equal(t, 0, intResult) | ||
} | ||
}, | ||
env: env, | ||
yuandrew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, 0) | ||
}, 0) | ||
|
||
env.RegisterDelayedCallback(func() { | ||
env.UpdateWorkflow("update", "id", &updateCallback{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if this update is sent before the first update completes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, added a mutex to the map to ensure the 2nd update must wait for the 1st update to complete |
||
reject: func(err error) { | ||
require.Fail(t, fmt.Sprintf("update should not be rejected, err: %v", err)) | ||
}, | ||
accept: func() { | ||
}, | ||
complete: func(result interface{}, err error) { | ||
intResult, ok := result.(int) | ||
if !ok { | ||
require.Fail(t, "result should be int") | ||
} else { | ||
// if dedup, this be okay, even if we pass in 1 as arg, since it's deduping, | ||
// the result should match the first update's result, 0 | ||
require.Equal(t, 0, intResult) | ||
} | ||
}, | ||
env: env, | ||
}, 1) | ||
|
||
}, 1*time.Millisecond) | ||
|
||
env.ExecuteWorkflow(func(ctx Context) error { | ||
err := SetUpdateHandler(ctx, "update", func(ctx Context, i int) (int, error) { | ||
return i, nil | ||
}, UpdateHandlerOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
return Sleep(ctx, time.Hour) | ||
}) | ||
require.NoError(t, env.GetWorkflowError()) | ||
} | ||
|
||
func TestAllHandlersFinished(t *testing.T) { | ||
var suite WorkflowTestSuite | ||
env := suite.NewTestWorkflowEnvironment() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm so this class is not for users, this whole file is for testing since it is post-fixed with
*_test.go
. The logic can't be in the updateCallback as we take an impl. from user. The logic needs to be in(env *testWorkflowEnvironmentImpl) updateWorkflow
. We could potentially add a wrapper around the user interface. Does that make sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
user
in this context referring to the user of the test suite?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And would it be accurate to rephrase this as "we need to implement this within the test suite, not the individual test logic.
updateCallback
is a test specific implementation"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What interface are you referring to here?
updateWorkflow
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
yeah, exactly
UpdateCallbacks