Skip to content
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

Test duplicate rejected updates #1569

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,35 @@ func (ts *IntegrationTestSuite) TestUpdateRejected() {
ts.NoError(run.Get(ctx, nil))
}

func (ts *IntegrationTestSuite) TestUpdateRejectedDuplicated() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
options := ts.startWorkflowOptions("test-update-rejected-duplicated")
run, err := ts.client.ExecuteWorkflow(ctx, options, ts.workflows.WorkflowWithRejectableUpdate)
ts.NoError(err)
// Send an update we expect to be rejected before the first workflow task
handle, err := ts.client.UpdateWorkflow(ctx, client.UpdateWorkflowOptions{
WorkflowID: run.GetID(),
RunID: run.GetRunID(),
UpdateName: "update",
WaitForStage: client.WorkflowUpdateStageCompleted,
Args: []interface{}{true},
})
ts.NoError(err)
ts.Error(handle.Get(ctx, nil))
// Same update ID should be allowed to be reused after the first attempt is rejected
handle, err = ts.client.UpdateWorkflow(ctx, client.UpdateWorkflowOptions{
WorkflowID: run.GetID(),
RunID: run.GetRunID(),
UpdateName: "update",
WaitForStage: client.WorkflowUpdateStageCompleted,
Args: []interface{}{false},
})
ts.NoError(err)
ts.NoError(handle.Get(ctx, nil))
ts.client.CancelWorkflow(ctx, run.GetID(), run.GetRunID())
}

func (ts *IntegrationTestSuite) TestUpdateSettingHandlerInGoroutine() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
19 changes: 19 additions & 0 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,24 @@ func (w *Workflows) UpdateRejectedWithOtherGoRoutine(ctx workflow.Context) error
return nil
}

func (w *Workflows) WorkflowWithRejectableUpdate(ctx workflow.Context) error {
workflow.SetUpdateHandlerWithOptions(ctx, "update",
func(ctx workflow.Context, _ bool) error {
return nil
}, workflow.UpdateHandlerOptions{
Validator: func(ctx workflow.Context, reject bool) error {
if reject {
return errors.New("test update rejected")
}
return nil
},
})
workflow.Await(ctx, func() bool {
return false
})
return nil
}

func (w *Workflows) UpdateOrdering(ctx workflow.Context) (int, error) {
updatesRan := 0
updateHandle := func(ctx workflow.Context) error {
Expand Down Expand Up @@ -3135,6 +3153,7 @@ func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.QueryTestWorkflow)
worker.RegisterWorkflow(w.UpdateWithMutex)
worker.RegisterWorkflow(w.UpdateWithSemaphore)
worker.RegisterWorkflow(w.WorkflowWithRejectableUpdate)

worker.RegisterWorkflow(w.child)
worker.RegisterWorkflow(w.childWithRetryPolicy)
Expand Down
Loading