Files
tasks/service/worker/migration/handover_workflow_test.go
Yu XiaandGitHub 9a7041a052 Adding minimum timeout require in system workflow (#8231)
## What changed?
Adding minimum timeout require in system workflow

## Why?
The system workflow needs to have sufficient time to execute the defer
logic.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-08-26 06:40:08 +00:00

78 lines
2.2 KiB
Go

package migration
import (
"errors"
"testing"
"time"
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/testsuite"
)
func TestHandoverWorkflow(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
var a *activities
namespaceID := uuid.New()
env.OnActivity(a.GetMetadata, mock.Anything, metadataRequest{Namespace: "test-ns"}).Return(&metadataResponse{ShardCount: 4, NamespaceID: namespaceID}, nil)
env.OnActivity(a.GetMaxReplicationTaskIDs, mock.Anything).Return(
&replicationStatus{map[int32]int64{
1: 100,
2: 100,
3: 100,
4: 100,
},
},
nil,
)
env.OnActivity(a.WaitReplication, mock.Anything, mock.Anything).Return(nil)
env.OnActivity(a.UpdateNamespaceState, mock.Anything, mock.Anything).Return(nil)
env.OnActivity(a.WaitHandover, mock.Anything, mock.Anything).Return(nil)
env.OnActivity(a.UpdateActiveCluster, mock.Anything, mock.Anything).Return(nil)
env.ExecuteWorkflow(NamespaceHandoverWorkflow, NamespaceHandoverParams{
Namespace: "test-ns",
RemoteCluster: "test-remote",
AllowedLaggingSeconds: 10,
HandoverTimeoutSeconds: 10,
})
require.True(t, env.IsWorkflowCompleted())
require.NoError(t, env.GetWorkflowError())
env.AssertExpectations(t)
}
func TestHandoverWorkflow_SetTimeout(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestWorkflowEnvironment()
// Set workflow execution timeout to 5 minutes
env.SetWorkflowRunTimeout(5 * time.Minute)
env.ExecuteWorkflow(NamespaceHandoverWorkflowV2, NamespaceHandoverParams{
Namespace: "test-ns",
RemoteCluster: "test-remote",
AllowedLaggingSeconds: 10,
HandoverTimeoutSeconds: 10,
})
require.True(t, env.IsWorkflowCompleted())
// Verify that the workflow failed with the expected error
workflowErr := env.GetWorkflowError()
require.Error(t, workflowErr)
var applicationErr *temporal.ApplicationError
require.True(t, errors.As(workflowErr, &applicationErr))
assert.Equal(t, "InvalidTimeout", applicationErr.Type())
assert.True(t, applicationErr.NonRetryable())
}