Skip to content

Commit

Permalink
Added seperate suite for the workflowID test
Browse files Browse the repository at this point in the history
Adding a seperate suite enables us to se the ratelimits only for this
specific test, and not for all the integration tests. Similar to the
async_wf_test
  • Loading branch information
jakobht committed Apr 5, 2024
1 parent 7b9bd65 commit 87211d6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
3 changes: 0 additions & 3 deletions host/dynamicconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ var (
dynamicconfig.EnableConsistentQueryByDomain: true,
dynamicconfig.MinRetentionDays: 0,
dynamicconfig.WorkflowDeletionJitterRange: 1,
dynamicconfig.WorkflowIDCacheExternalEnabled: true,
dynamicconfig.WorkflowIDExternalRPS: 5,
dynamicconfig.WorkflowIDExternalRateLimitEnabled: true,
}
)

Expand Down
5 changes: 5 additions & 0 deletions host/test_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ type (
*require.Assertions
*IntegrationBase
}

WorkflowIDRateLimitIntegrationSuite struct {
*require.Assertions
*IntegrationBase
}
)
11 changes: 11 additions & 0 deletions host/testdata/integration_wfidratelimit_cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enablearchival: true
clusterno: 2
messagingclientconfig:
usemock: true
historyconfig:
numhistoryshards: 4
numhistoryhosts: 1
workerconfig:
enablearchiver: true
enablereplicator: true
enableindexer: false
76 changes: 75 additions & 1 deletion host/workflowidratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,86 @@
package host

import (
"flag"
"testing"

"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/uber/cadence/common/clock"
"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/persistence"
pt "github.com/uber/cadence/common/persistence/persistence-tests"

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/types"
)

func (s *IntegrationSuite) TestWorkflowIDSpecificRateLimits() {
func TestWorkflowIDRateLimitIntegrationSuite(t *testing.T) {
flag.Parse()

clusterConfig, err := GetTestClusterConfig("integration_wfidratelimit_cluster.yaml")
if err != nil {
panic(err)
}

clusterConfig.TimeSource = clock.NewMockedTimeSource()
clusterConfig.HistoryDynamicConfigOverrides = map[dynamicconfig.Key]interface{}{
dynamicconfig.WorkflowIDCacheExternalEnabled: true,
dynamicconfig.WorkflowIDExternalRPS: 5,
dynamicconfig.WorkflowIDExternalRateLimitEnabled: true,
}

testCluster := NewPersistenceTestCluster(t, clusterConfig)

s := new(WorkflowIDRateLimitIntegrationSuite)
params := IntegrationBaseParams{
DefaultTestCluster: testCluster,
VisibilityTestCluster: testCluster,
TestClusterConfig: clusterConfig,
}
s.IntegrationBase = NewIntegrationBase(params)
suite.Run(t, s)
}

func (s *WorkflowIDRateLimitIntegrationSuite) SetupSuite() {
s.setupLogger()

s.Logger.Info("Running integration test against test cluster")
clusterMetadata := NewClusterMetadata(s.T(), s.testClusterConfig)
dc := persistence.DynamicConfiguration{
EnableCassandraAllConsistencyLevelDelete: dynamicconfig.GetBoolPropertyFn(true),
PersistenceSampleLoggingRate: dynamicconfig.GetIntPropertyFn(100),
EnableShardIDMetrics: dynamicconfig.GetBoolPropertyFn(true),
}
params := pt.TestBaseParams{
DefaultTestCluster: s.defaultTestCluster,
VisibilityTestCluster: s.visibilityTestCluster,
ClusterMetadata: clusterMetadata,
DynamicConfiguration: dc,
}
cluster, err := NewCluster(s.T(), s.testClusterConfig, s.Logger, params)
s.Require().NoError(err)
s.testCluster = cluster
s.engine = s.testCluster.GetFrontendClient()
s.adminClient = s.testCluster.GetAdminClient()

s.domainName = s.randomizeStr("integration-test-domain")
s.Require().NoError(s.registerDomain(s.domainName, 1, types.ArchivalStatusDisabled, "", types.ArchivalStatusDisabled, ""))

s.domainCacheRefresh()
}

func (s *WorkflowIDRateLimitIntegrationSuite) SetupTest() {
s.Assertions = require.New(s.T())
}

func (s *WorkflowIDRateLimitIntegrationSuite) TearDownSuite() {
s.tearDownSuite()
}

func (s *WorkflowIDRateLimitIntegrationSuite) TestWorkflowIDSpecificRateLimits() {
const (
testWorkflowID = "integration-workflow-specific-rate-limit-test"
testWorkflowType = "integration-workflow-specific-rate-limit-test-type"
Expand All @@ -57,12 +129,14 @@ func (s *IntegrationSuite) TestWorkflowIDSpecificRateLimits() {

// The ratelimit is 5 per second, so we should be able to start 5 workflows without any error
for i := 0; i < 5; i++ {
s.Require().NotNil(s.engine)
_, err := s.engine.StartWorkflowExecution(ctx, request)
assert.NoError(s.T(), err)
}

// Now we should get a rate limit error
for i := 0; i < 5; i++ {
s.Require().NotNil(s.engine)
_, err := s.engine.StartWorkflowExecution(ctx, request)
var busyErr *types.ServiceBusyError
assert.ErrorAs(s.T(), err, &busyErr)
Expand Down

0 comments on commit 87211d6

Please sign in to comment.