-
Notifications
You must be signed in to change notification settings - Fork 859
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
Query Failure #6947
Open
bergundy
wants to merge
1
commit into
temporalio:main
Choose a base branch
from
bergundy:query-failure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+134
−5
Open
Query Failure #6947
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -28,19 +28,30 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"maps" | ||
"slices" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
commandpb "go.temporal.io/api/command/v1" | ||
"go.temporal.io/api/common/v1" | ||
enumspb "go.temporal.io/api/enums/v1" | ||
"go.temporal.io/api/failure/v1" | ||
querypb "go.temporal.io/api/query/v1" | ||
"go.temporal.io/api/serviceerror" | ||
taskqueuepb "go.temporal.io/api/taskqueue/v1" | ||
"go.temporal.io/api/workflowservice/v1" | ||
"go.temporal.io/sdk/client" | ||
sdkclient "go.temporal.io/sdk/client" | ||
"go.temporal.io/sdk/worker" | ||
"go.temporal.io/sdk/workflow" | ||
"go.temporal.io/server/common/log/tag" | ||
"go.temporal.io/server/common/testing/testvars" | ||
"go.temporal.io/server/common/util" | ||
"go.temporal.io/server/service/history/consts" | ||
"go.temporal.io/server/tests/testcore" | ||
) | ||
|
@@ -357,3 +368,121 @@ func (s *QueryWorkflowSuite) TestQueryWorkflow_ClosedWithoutWorkflowTaskStarted( | |
s.Error(err) | ||
s.ErrorContains(err, consts.ErrWorkflowClosedBeforeWorkflowTaskStarted.Error()) | ||
} | ||
|
||
func (s *QueryWorkflowSuite) TestQueryWorkflow_FailurePropagated() { | ||
ctx := testcore.NewContext() | ||
taskQueue := testcore.RandomizeStr(s.T().Name()) | ||
|
||
workflowRun, err := s.SdkClient().ExecuteWorkflow(ctx, client.StartWorkflowOptions{TaskQueue: taskQueue}, "workflow") | ||
s.NoError(err) | ||
|
||
// Create a channel for errors generated in background goroutines. | ||
errChan := make(chan error, 1) | ||
|
||
// Query the workflow in the background to have the query delivered with the first workflow task in the Queries map. | ||
go func() { | ||
_, err = s.FrontendClient().QueryWorkflow(ctx, &workflowservice.QueryWorkflowRequest{ | ||
Namespace: s.Namespace(), | ||
Execution: &common.WorkflowExecution{ | ||
WorkflowId: workflowRun.GetID(), | ||
}, | ||
Query: &querypb.WorkflowQuery{ | ||
QueryType: "dont-care", | ||
}, | ||
}) | ||
errChan <- err | ||
}() | ||
|
||
// Hope that 3 seconds will be enough for history to record the query and attach it to the pending workflow task. | ||
// There's really no other way to ensure that the query is included in the task unfortunately. | ||
util.InterruptibleSleep(ctx, 3*time.Second) | ||
|
||
task, err := s.FrontendClient().PollWorkflowTaskQueue(ctx, &workflowservice.PollWorkflowTaskQueueRequest{ | ||
Namespace: s.Namespace(), | ||
TaskQueue: &taskqueuepb.TaskQueue{Name: taskQueue}, | ||
Identity: s.T().Name(), | ||
}) | ||
|
||
s.Len(task.Queries, 1) | ||
qKey := slices.Collect(maps.Keys(task.Queries))[0] | ||
|
||
_, err = s.FrontendClient().RespondWorkflowTaskCompleted(ctx, &workflowservice.RespondWorkflowTaskCompletedRequest{ | ||
TaskToken: task.TaskToken, | ||
Identity: s.T().Name(), | ||
QueryResults: map[string]*querypb.WorkflowQueryResult{ | ||
qKey: { | ||
ResultType: enumspb.QUERY_RESULT_TYPE_FAILED, | ||
ErrorMessage: "my error message", | ||
Failure: &failure.Failure{ | ||
Message: "my failure error message", | ||
}, | ||
}, | ||
}, | ||
Commands: []*commandpb.Command{ | ||
{ | ||
CommandType: enumspb.COMMAND_TYPE_COMPLETE_WORKFLOW_EXECUTION, | ||
Attributes: &commandpb.Command_CompleteWorkflowExecutionCommandAttributes{}, | ||
}, | ||
}, | ||
}) | ||
s.NoError(err) | ||
|
||
select { | ||
case err = <-errChan: | ||
case <-ctx.Done(): | ||
// Abort and fail the test. | ||
s.NoError(ctx.Err()) | ||
} | ||
|
||
var query1FailedErr *serviceerror.QueryFailed | ||
s.ErrorAs(err, &query1FailedErr) | ||
s.Equal("my error message", query1FailedErr.Message) | ||
s.Equal("my failure error message", query1FailedErr.Failure.Message) | ||
|
||
go func() { | ||
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. q: why not just a single test, with both "QueryWorkflow" and "PollWorkflowTaskQueue/RespondQueryTaskCompleted" in a separate goroutines? What are you testing by testing like that? |
||
task, err := s.FrontendClient().PollWorkflowTaskQueue(ctx, &workflowservice.PollWorkflowTaskQueueRequest{ | ||
Namespace: s.Namespace(), | ||
TaskQueue: &taskqueuepb.TaskQueue{Name: taskQueue}, | ||
Identity: s.T().Name(), | ||
}) | ||
if err != nil { | ||
errChan <- err | ||
return | ||
} | ||
|
||
_, err = s.FrontendClient().RespondQueryTaskCompleted(ctx, &workflowservice.RespondQueryTaskCompletedRequest{ | ||
Namespace: s.Namespace(), | ||
TaskToken: task.TaskToken, | ||
CompletedType: enumspb.QUERY_RESULT_TYPE_FAILED, | ||
ErrorMessage: "my error message", | ||
Failure: &failure.Failure{ | ||
Message: "my failure error message", | ||
}, | ||
}) | ||
|
||
errChan <- err | ||
}() | ||
|
||
_, err = s.FrontendClient().QueryWorkflow(ctx, &workflowservice.QueryWorkflowRequest{ | ||
Namespace: s.Namespace(), | ||
Execution: &common.WorkflowExecution{ | ||
WorkflowId: workflowRun.GetID(), | ||
}, | ||
Query: &querypb.WorkflowQuery{ | ||
QueryType: "dont-care", | ||
}, | ||
}) | ||
|
||
var query2FailedErr *serviceerror.QueryFailed | ||
s.ErrorAs(err, &query2FailedErr) | ||
s.Equal("my error message", query2FailedErr.Message) | ||
s.Equal("my failure error message", query2FailedErr.Failure.Message) | ||
|
||
select { | ||
case err = <-errChan: | ||
s.NoError(err) | ||
case <-ctx.Done(): | ||
// Abort and fail the test. | ||
s.NoError(ctx.Err()) | ||
} | ||
} |
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.
Could you add a small comment explaining the purpose of the second half of the test? I don't quite see the difference to the first half.