Skip to content

Commit 2baa60e

Browse files
authoredJul 29, 2024··
Test duplicate rejected updates (#1569)
1 parent 6bb8f99 commit 2baa60e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
 

‎test/integration_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,35 @@ func (ts *IntegrationTestSuite) TestUpdateRejected() {
34713471
ts.NoError(run.Get(ctx, nil))
34723472
}
34733473

3474+
func (ts *IntegrationTestSuite) TestUpdateRejectedDuplicated() {
3475+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
3476+
defer cancel()
3477+
options := ts.startWorkflowOptions("test-update-rejected-duplicated")
3478+
run, err := ts.client.ExecuteWorkflow(ctx, options, ts.workflows.WorkflowWithRejectableUpdate)
3479+
ts.NoError(err)
3480+
// Send an update we expect to be rejected before the first workflow task
3481+
handle, err := ts.client.UpdateWorkflow(ctx, client.UpdateWorkflowOptions{
3482+
WorkflowID: run.GetID(),
3483+
RunID: run.GetRunID(),
3484+
UpdateName: "update",
3485+
WaitForStage: client.WorkflowUpdateStageCompleted,
3486+
Args: []interface{}{true},
3487+
})
3488+
ts.NoError(err)
3489+
ts.Error(handle.Get(ctx, nil))
3490+
// Same update ID should be allowed to be reused after the first attempt is rejected
3491+
handle, err = ts.client.UpdateWorkflow(ctx, client.UpdateWorkflowOptions{
3492+
WorkflowID: run.GetID(),
3493+
RunID: run.GetRunID(),
3494+
UpdateName: "update",
3495+
WaitForStage: client.WorkflowUpdateStageCompleted,
3496+
Args: []interface{}{false},
3497+
})
3498+
ts.NoError(err)
3499+
ts.NoError(handle.Get(ctx, nil))
3500+
ts.client.CancelWorkflow(ctx, run.GetID(), run.GetRunID())
3501+
}
3502+
34743503
func (ts *IntegrationTestSuite) TestUpdateSettingHandlerInGoroutine() {
34753504
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
34763505
defer cancel()

‎test/workflow_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,24 @@ func (w *Workflows) UpdateRejectedWithOtherGoRoutine(ctx workflow.Context) error
26412641
return nil
26422642
}
26432643

2644+
func (w *Workflows) WorkflowWithRejectableUpdate(ctx workflow.Context) error {
2645+
workflow.SetUpdateHandlerWithOptions(ctx, "update",
2646+
func(ctx workflow.Context, _ bool) error {
2647+
return nil
2648+
}, workflow.UpdateHandlerOptions{
2649+
Validator: func(ctx workflow.Context, reject bool) error {
2650+
if reject {
2651+
return errors.New("test update rejected")
2652+
}
2653+
return nil
2654+
},
2655+
})
2656+
workflow.Await(ctx, func() bool {
2657+
return false
2658+
})
2659+
return nil
2660+
}
2661+
26442662
func (w *Workflows) UpdateOrdering(ctx workflow.Context) (int, error) {
26452663
updatesRan := 0
26462664
updateHandle := func(ctx workflow.Context) error {
@@ -3135,6 +3153,7 @@ func (w *Workflows) register(worker worker.Worker) {
31353153
worker.RegisterWorkflow(w.QueryTestWorkflow)
31363154
worker.RegisterWorkflow(w.UpdateWithMutex)
31373155
worker.RegisterWorkflow(w.UpdateWithSemaphore)
3156+
worker.RegisterWorkflow(w.WorkflowWithRejectableUpdate)
31383157

31393158
worker.RegisterWorkflow(w.child)
31403159
worker.RegisterWorkflow(w.childWithRetryPolicy)

0 commit comments

Comments
 (0)
Please sign in to comment.