Skip to content

Commit

Permalink
Error for unused Update operation (#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanos authored Oct 3, 2024
1 parent ea60ad5 commit 4e8380c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ type (
// workflow completion callback. Only settable by the SDK - e.g. [temporalnexus.workflowRunOperation].
callbacks []*commonpb.Callback
// links. Only settable by the SDK - e.g. [temporalnexus.workflowRunOperation].
links []*commonpb.Link
links []*commonpb.Link
}

// WithStartWorkflowOperation is a type of operation that can be executed as part of a workflow start.
Expand Down Expand Up @@ -1082,6 +1082,9 @@ func (op *UpdateWithStartWorkflowOperation) Get(ctx context.Context) (WorkflowUp
case <-op.doneCh:
return op.handle, op.err
case <-ctx.Done():
if !op.executed.Load() {
return nil, fmt.Errorf("%w: %w", ctx.Err(), fmt.Errorf("operation was not executed"))
}
return nil, ctx.Err()
}
}
Expand Down
29 changes: 29 additions & 0 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,35 @@ func (s *workflowRunSuite) TestExecuteWorkflowWithUpdate_Retry() {
s.NoError(err)
}

func (s *workflowRunSuite) TestExecuteWorkflowWithUpdate_OperationNotExecuted() {
s.workflowServiceClient.EXPECT().StartWorkflowExecution(gomock.Any(), gomock.Any(), gomock.Any()).
Return(&workflowservice.StartWorkflowExecutionResponse{
RunId: runID,
}, nil)

updOp := NewUpdateWithStartWorkflowOperation(
UpdateWorkflowOptions{
UpdateName: "update",
WaitForStage: WorkflowUpdateStageCompleted,
})

ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()

_, err := s.workflowClient.ExecuteWorkflow(
ctxWithTimeout,
StartWorkflowOptions{
ID: workflowID,
TaskQueue: taskqueue,
// WithStartOperation is not specified!
}, workflowType,
)
require.NoError(s.T(), err)

_, err = updOp.Get(ctxWithTimeout)
require.EqualError(s.T(), err, "context deadline exceeded: operation was not executed")
}

func (s *workflowRunSuite) TestExecuteWorkflowWithUpdate_Abort() {
tests := []struct {
name string
Expand Down

0 comments on commit 4e8380c

Please sign in to comment.