-
Notifications
You must be signed in to change notification settings - Fork 876
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
functional tests testing queries + nexus tasks with versioning-3 #7015
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
093ab55
Added functional tests testing queries for versioning-3
Shivs11 876b7f6
tests to verify routing of nexus tasks using versioning-3;
Shivs11 deec714
goimports
Shivs11 1024efa
added waiting until poller completion
Shivs11 02c9f46
lint fixes
Shivs11 ff38738
query redirects to latest deployment
Shivs11 37b1672
Addressed comments by making separate helpers
Shivs11 61742a4
removing non-required comments
Shivs11 24a50cd
Merge branch 'main' into shivam/query-versioning3-func-tests
Shivs11 0750ef0
lint errors
Shivs11 9e37261
better code
Shivs11 b854081
removed stale comments
Shivs11 1725f90
addressed all comments
Shivs11 6b96b98
restoring old code
Shivs11 6bd2fdc
Fixed errors
Shivs11 966a075
Setting query result on a nil error
Shivs11 dba609d
updating tests
Shivs11 9bf96e3
quieting the lint
Shivs11 114a87d
removing time.Sleep from tests
Shivs11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,21 @@ type ( | |
tv *testvars.TestVars | ||
timeout time.Duration | ||
} | ||
optionFunc func(*options) | ||
optionFunc func(*options) | ||
TaskCompletedRequest struct { | ||
WorkflowTaskCompletedRequest *workflowservice.RespondWorkflowTaskCompletedRequest | ||
QueryTaskCompletedRequest *workflowservice.RespondQueryTaskCompletedRequest | ||
} | ||
TaskCompletedResponse struct { | ||
WorkflowTaskCompletedResponse *workflowservice.RespondWorkflowTaskCompletedResponse | ||
QueryTaskCompletedResponse *workflowservice.RespondQueryTaskCompletedResponse | ||
} | ||
) | ||
|
||
var ( | ||
// DrainWorkflowTask returns an empty RespondWorkflowTaskCompletedRequest | ||
DrainWorkflowTask = func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error) { | ||
return &workflowservice.RespondWorkflowTaskCompletedRequest{}, nil | ||
DrainWorkflowTask = func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error) { | ||
return &TaskCompletedRequest{WorkflowTaskCompletedRequest: &workflowservice.RespondWorkflowTaskCompletedRequest{}}, nil | ||
} | ||
// CompleteActivityTask returns a RespondActivityTaskCompletedRequest with an auto-generated `Result` from `tv.Any().Payloads()`. | ||
CompleteActivityTask = func(tv *testvars.TestVars) func(task *workflowservice.PollActivityTaskQueueResponse) (*workflowservice.RespondActivityTaskCompletedRequest, error) { | ||
|
@@ -111,9 +119,9 @@ func (p *TaskPoller) PollWorkflowTask( | |
// If no task is available, it returns NoTaskAvailable. | ||
func (p *TaskPoller) PollAndHandleWorkflowTask( | ||
tv *testvars.TestVars, | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error), | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error), | ||
opts ...optionFunc, | ||
) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) { | ||
) (*TaskCompletedResponse, error) { | ||
return p. | ||
PollWorkflowTask(&workflowservice.PollWorkflowTaskQueueRequest{}). | ||
HandleTask(tv, handler, opts...) | ||
|
@@ -125,9 +133,9 @@ func (p *TaskPoller) PollAndHandleWorkflowTask( | |
// If no task is available, it returns NoTaskAvailable. | ||
func (p *workflowTaskPoller) HandleTask( | ||
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. Most of the time we do not work with queries, it seems a little to much to impose the nested TaskCompletedResponse on all usages. Why not keep all these methods untouched and add a
|
||
tv *testvars.TestVars, | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error), | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error), | ||
opts ...optionFunc, | ||
) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) { | ||
) (*TaskCompletedResponse, error) { | ||
p.t.Helper() | ||
options := newOptions(tv, opts) | ||
ctx, cancel := newContext(options) | ||
|
@@ -141,9 +149,9 @@ func (p *workflowTaskPoller) HandleTask( | |
func (p *TaskPoller) HandleWorkflowTask( | ||
tv *testvars.TestVars, | ||
task *workflowservice.PollWorkflowTaskQueueResponse, | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error), | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error), | ||
opts ...optionFunc, | ||
) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) { | ||
) (*TaskCompletedResponse, error) { | ||
p.t.Helper() | ||
options := newOptions(tv, opts) | ||
ctx, cancel := newContext(options) | ||
|
@@ -239,9 +247,6 @@ func (p *workflowTaskPoller) pollTask( | |
} | ||
|
||
events = history.Events | ||
if len(events) == 0 { | ||
Shivs11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil, errors.New("history events are empty") | ||
} | ||
|
||
nextPageToken := resp.NextPageToken | ||
for nextPageToken != nil { | ||
|
@@ -265,8 +270,8 @@ func (p *workflowTaskPoller) pollTask( | |
func (p *workflowTaskPoller) pollAndHandleTask( | ||
ctx context.Context, | ||
opts *options, | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error), | ||
) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) { | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error), | ||
) (*TaskCompletedResponse, error) { | ||
p.t.Helper() | ||
task, err := p.pollTask(ctx, opts) | ||
if err != nil { | ||
|
@@ -279,19 +284,52 @@ func (p *workflowTaskPoller) handleTask( | |
ctx context.Context, | ||
opts *options, | ||
task *workflowservice.PollWorkflowTaskQueueResponse, | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error), | ||
) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) { | ||
handler func(task *workflowservice.PollWorkflowTaskQueueResponse) (*TaskCompletedRequest, error), | ||
) (*TaskCompletedResponse, error) { | ||
p.t.Helper() | ||
reply, err := handler(task) | ||
if err != nil { | ||
return nil, p.respondTaskFailed(ctx, opts, task.TaskToken, err) | ||
} | ||
|
||
resp, err := p.respondTaskCompleted(ctx, opts, task, reply) | ||
if reply.QueryTaskCompletedRequest != nil { | ||
resp, err := p.respondQueryTaskCompleted(ctx, task, reply.QueryTaskCompletedRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &TaskCompletedResponse{QueryTaskCompletedResponse: resp}, nil | ||
} | ||
|
||
resp, err := p.respondTaskCompleted(ctx, opts, task, reply.WorkflowTaskCompletedRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &TaskCompletedResponse{WorkflowTaskCompletedResponse: resp}, nil | ||
} | ||
|
||
func (p *workflowTaskPoller) respondQueryTaskCompleted( | ||
ctx context.Context, | ||
task *workflowservice.PollWorkflowTaskQueueResponse, | ||
reply *workflowservice.RespondQueryTaskCompletedRequest, | ||
) (*workflowservice.RespondQueryTaskCompletedResponse, error) { | ||
p.t.Helper() | ||
if task == nil { | ||
return nil, errors.New("missing PollWorkflowTaskQueue") | ||
Shivs11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if reply == nil { | ||
stephanos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil, errors.New("missing RespondQueryTaskCompleted return") | ||
Shivs11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if reply.Namespace == "" { | ||
reply.Namespace = p.namespace | ||
} | ||
if reply.TaskToken == nil { | ||
reply.TaskToken = task.TaskToken | ||
} | ||
Shivs11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resp, err := p.client.RespondQueryTaskCompleted(ctx, reply) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to respond with respondQueryTaskCompleted: %w", err) | ||
} | ||
return resp, 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm, I'm not sure this is the right direction. I understand that the current API doesn't work for these Queries, but 95% of the time, the task poller will probably only deal with WFTs. Right now, without thinking longer about it, I see three other directions:
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.
(1) would be the easiest and clearest; let me know if that's a feasible option. I haven't worked with this Query API before.
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.
tagging you @ShahabT here as well since you had the exact concern - The main point seems to be to remove the need for
TaskCompletedResponse/Request
structures.In my earlier stab at this, I did not have any of these structures and had made one exported function inside
(*workflowTaskPoller).handleTask
and had changed the return type toany
(all the places that required it). Not, that in this attempt I also intended on usingVersioning3Suite.pollWftAndHandle
since it served as a nice helper function for all my needs. My train of thought was:nil
" or having these two structures were effectively conveying the same purpose: The response can be one of two types - Query or Workflowany
would make it a bit confusing)Hence, I took the more tedious approach and went ahead with this option - I can certainly revert back if you both feel strongly of not keeping this the way it is but would be curious to hear your thoughts
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.
Your reasoning is totally reasonable; but I strongly believe it's not the right path because it's too verbose for the majority of use cases. That was already a concern before, and is exacerbated here.
To pick up Shahab's suggestion; is this feasible in your opinion? If so, it would be my preferred approach.
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.
Will be attempting to have type assertions in place along with a separate
HandleQueryTask
method ⏳