Files
Alex ShtinandGitHub fcc4a41a11 Delete Namespace: read cache refresh interval from DC (#7215)
## What changed?
<!-- Describe what has changed in this PR -->
Delete Namespace: read cache refresh interval from dynamic config
instead of hardcoded const.

## Why?
<!-- Tell your future self why have you made these changes -->
`cacheRefreshInterval` used to be a const, and it was kinda ok to
duplicate it in delete namespace WF code. But now it is coming from
dynamic config, and WF should read it from there too.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Modified existing unit tests.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No risks.

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
No.

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
2025-02-03 11:41:15 -08:00

117 lines
4.3 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package reclaimresources
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/testsuite"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/persistence/visibility/manager"
"go.temporal.io/server/common/searchattribute"
"go.uber.org/mock/gomock"
)
func Test_EnsureNoExecutionsAdvVisibilityActivity_NoExecutions(t *testing.T) {
ctrl := gomock.NewController(t)
visibilityManager := manager.NewMockVisibilityManager(ctrl)
visibilityManager.EXPECT().CountWorkflowExecutions(gomock.Any(), &manager.CountWorkflowExecutionsRequest{
NamespaceID: "namespace-id",
Namespace: "namespace",
Query: searchattribute.QueryWithAnyNamespaceDivision(""),
}).Return(&manager.CountWorkflowExecutionsResponse{
Count: 0,
}, nil)
a := &Activities{
visibilityManager: visibilityManager,
logger: log.NewTestLogger(),
}
err := a.EnsureNoExecutionsAdvVisibilityActivity(context.Background(), "namespace-id", "namespace", 0)
require.NoError(t, err)
}
func Test_EnsureNoExecutionsAdvVisibilityActivity_ExecutionsExist(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestActivityEnvironment()
ctrl := gomock.NewController(t)
visibilityManager := manager.NewMockVisibilityManager(ctrl)
visibilityManager.EXPECT().CountWorkflowExecutions(gomock.Any(), &manager.CountWorkflowExecutionsRequest{
NamespaceID: "namespace-id",
Namespace: "namespace",
Query: searchattribute.QueryWithAnyNamespaceDivision(""),
}).Return(&manager.CountWorkflowExecutionsResponse{
Count: 1,
}, nil)
a := &Activities{
visibilityManager: visibilityManager,
logger: log.NewTestLogger(),
}
env.RegisterActivity(a.EnsureNoExecutionsAdvVisibilityActivity)
_, err := env.ExecuteActivity(a.EnsureNoExecutionsAdvVisibilityActivity, namespace.ID("namespace-id"), namespace.Name("namespace"), 0)
require.Error(t, err)
var appErr *temporal.ApplicationError
require.ErrorAs(t, err, &appErr)
require.Equal(t, "ExecutionsStillExist", appErr.Type())
}
func Test_EnsureNoExecutionsAdvVisibilityActivity_NotDeletedExecutionsExist(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestActivityEnvironment()
ctrl := gomock.NewController(t)
visibilityManager := manager.NewMockVisibilityManager(ctrl)
visibilityManager.EXPECT().CountWorkflowExecutions(gomock.Any(), &manager.CountWorkflowExecutionsRequest{
NamespaceID: "namespace-id",
Namespace: "namespace",
Query: searchattribute.QueryWithAnyNamespaceDivision(""),
}).Return(&manager.CountWorkflowExecutionsResponse{
Count: 10,
}, nil)
a := &Activities{
visibilityManager: visibilityManager,
logger: log.NewTestLogger(),
}
env.RegisterActivity(a.EnsureNoExecutionsAdvVisibilityActivity)
_, err := env.ExecuteActivity(a.EnsureNoExecutionsAdvVisibilityActivity, namespace.ID("namespace-id"), namespace.Name("namespace"), 10)
require.Error(t, err)
var appErr *temporal.ApplicationError
require.ErrorAs(t, err, &appErr)
require.Equal(t, "NotDeletedExecutionsStillExist", appErr.Type())
}