Files
temporal/tests/workflow_api_batch_delete_test.go
Sean Kane a1b0e621c1 Implement terminate/cancel/delete batch operation for standalone activities (#10803)
## What changed?
- terminate, cancel, delete standalone activity batch operations
- Add OperationType to ListBatchOperations
- Show query/executions and operation type on DescribeBatchOperation

## Why?
Terminate, cancel, delete are available batch operations for workflows,
providing them for standalone activities brings SAA up to parity.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [X] covered by existing tests
- [X] added new unit test(s)
- [X] added new functional test(s)

## Potential risks
Changes to batch operations introduces the risk of non-backwards
compatible code. This code has been manually (human-read) audited for
backwards compatability.

---------

Co-authored-by: ks-temporal <281732484+ks-temporal@users.noreply.github.com>
2026-07-20 10:56:10 -06:00

91 lines
3.1 KiB
Go

package tests
import (
"errors"
"fmt"
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
batchpb "go.temporal.io/api/batch/v1"
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
sdkclient "go.temporal.io/sdk/client"
"go.temporal.io/sdk/workflow"
"go.temporal.io/server/common/testing/parallelsuite"
"go.temporal.io/server/tests/testcore"
)
type WorkflowAPIBatchDeleteClientTestSuite struct {
parallelsuite.Suite[*WorkflowAPIBatchDeleteClientTestSuite]
}
func TestWorkflowAPIBatchDeleteClientTestSuite(t *testing.T) {
parallelsuite.Run(t, &WorkflowAPIBatchDeleteClientTestSuite{})
}
func (s *WorkflowAPIBatchDeleteClientTestSuite) TestWorkflowBatchDelete_Success() {
for _, selector := range workflowBatchTargetSelectors() {
s.Run(selector.name, func(s *WorkflowAPIBatchDeleteClientTestSuite) {
env := newWorkflowBatchEnv(s.T())
t := s.T()
ctx := s.Context()
workflowType := testcore.RandomizeStr(t.Name())
env.SdkWorker().RegisterWorkflowWithOptions(blockingWorkflow, workflow.RegisterOptions{Name: workflowType})
// Start three workflows of the same (per-test, unique) type. Batch
// delete works on running or closed workflows, so no need to close
// them first.
executions := make([]*commonpb.WorkflowExecution, 0, 3)
for i := range 3 {
run, err := env.SdkClient().ExecuteWorkflow(ctx, sdkclient.StartWorkflowOptions{
ID: testcore.RandomizeStr(fmt.Sprintf("%s-%d", t.Name(), i)),
TaskQueue: env.WorkerTaskQueue(),
}, workflowType)
s.NoError(err)
executions = append(executions, &commonpb.WorkflowExecution{
WorkflowId: run.GetID(),
RunId: run.GetRunID(),
})
}
// Delete all three workflows with a single batch operation.
jobID := uuid.NewString()
req := &workflowservice.StartBatchOperationRequest{
Namespace: env.Namespace().String(),
Operation: &workflowservice.StartBatchOperationRequest_DeletionOperation{
DeletionOperation: &batchpb.BatchOperationDeletion{
Identity: "batch-deleter",
},
},
JobId: jobID,
Reason: "test",
}
expectedQuery, expectedExecutions := selector.apply(t, env, ctx, workflowType, executions, req)
_, err := env.SdkClient().WorkflowService().StartBatchOperation(ctx, req)
s.NoError(err)
// Describe/List should report the correct operation type, query, and executions for the batch.
assertWorkflowBatchOperationType(ctx, t, env, jobID, enumspb.BATCH_OPERATION_TYPE_DELETE_WORKFLOW, expectedQuery, expectedExecutions)
// All three workflows must be deleted (no longer describable).
for _, e := range executions {
//nolint:forbidigo // for tests with waits
require.Eventually(t, func() bool {
_, err := env.FrontendClient().DescribeWorkflowExecution(ctx, &workflowservice.DescribeWorkflowExecutionRequest{
Namespace: env.Namespace().String(),
Execution: e,
})
var notFoundErr *serviceerror.NotFound
return errors.As(err, &notFoundErr)
}, 5*time.Second, 100*time.Millisecond)
}
})
}
}