From 0d7d68dc2913496fae9ea916bddfa64d94782e52 Mon Sep 17 00:00:00 2001 From: Tim Li Date: Wed, 21 Feb 2024 16:37:54 -0800 Subject: [PATCH 1/3] Add unit tests for methods in constants.go --- common/dynamicconfig/constants_test.go | 295 +++++++++++++++++++++++++ 1 file changed, 295 insertions(+) create mode 100644 common/dynamicconfig/constants_test.go diff --git a/common/dynamicconfig/constants_test.go b/common/dynamicconfig/constants_test.go new file mode 100644 index 00000000000..e1a52d0e84c --- /dev/null +++ b/common/dynamicconfig/constants_test.go @@ -0,0 +1,295 @@ +package dynamicconfig + +import ( + "github.com/stretchr/testify/suite" + "github.com/uber/cadence/common" + "testing" + "time" +) + +type constantSuite struct { + suite.Suite +} + +func TestConstantSuite(t *testing.T) { + suite.Run(t, new(constantSuite)) +} + +func (s *constantSuite) TestListAllProductionKeys() { + //check if we given enough capacity + s.GreaterOrEqual(len(IntKeys)+len(BoolKeys)+len(FloatKeys)+len(StringKeys)+len(DurationKeys)+len(MapKeys), len(ListAllProductionKeys())) + +} + +func (s *constantSuite) TestIntKey() { + testIntKeys := map[string]struct { + key IntKey + expectedString string + expectedDefaultValue int + expectedDescription string + expectedFilters []Filter + }{ + "TestGetIntPropertyKey": { + key: TestGetIntPropertyKey, + expectedString: "testGetIntPropertyKey", + expectedDescription: "", + expectedDefaultValue: 0, + expectedFilters: nil, + }, + "TransactionSizeLimit": { + key: TransactionSizeLimit, + expectedString: "system.transactionSizeLimit", + expectedDescription: "TransactionSizeLimit is the largest allowed transaction size to persistence", + expectedDefaultValue: 14680064, + }, + "BlobSizeLimitWarn": { + key: BlobSizeLimitWarn, + expectedString: "limit.blobSize.warn", + expectedDescription: "BlobSizeLimitWarn is the per event blob size limit for warning", + expectedDefaultValue: 256 * 1024, + expectedFilters: []Filter{DomainName}, + }, + } + + for _, value := range testIntKeys { + s.Equal(value.expectedString, value.key.String()) + s.Equal(value.expectedDefaultValue, value.key.DefaultValue()) + s.Equal(value.expectedDescription, value.key.Description()) + s.Equal(value.expectedFilters, value.key.Filters()) + s.Equal(value.expectedDefaultValue, value.key.DefaultInt()) + } +} + +func (s *constantSuite) TestBoolKey() { + testBoolKeys := map[string]struct { + key BoolKey + expectedString string + expectedDefaultValue bool + expectedDescription string + expectedFilters []Filter + }{ + "TestGetBoolPropertyKey": { + key: TestGetBoolPropertyKey, + expectedString: "testGetBoolPropertyKey", + expectedDescription: "", + expectedDefaultValue: false, + expectedFilters: nil, + }, + "EnableReadVisibilityFromES": { + key: EnableReadVisibilityFromES, + expectedString: "system.enableReadVisibilityFromES", + expectedDescription: "EnableReadVisibilityFromES is key for enable read from elastic search or db visibility, usually using with AdvancedVisibilityWritingMode for seamless migration from db visibility to advanced visibility", + expectedDefaultValue: true, + expectedFilters: []Filter{DomainName}, + }, + "FrontendEmitSignalNameMetricsTag": { + key: FrontendEmitSignalNameMetricsTag, + expectedString: "frontend.emitSignalNameMetricsTag", + expectedDescription: "FrontendEmitSignalNameMetricsTag enables emitting signal name tag in metrics in frontend client", + expectedDefaultValue: false, + expectedFilters: []Filter{DomainName}, + }, + } + + for _, value := range testBoolKeys { + s.Equal(value.expectedString, value.key.String()) + s.Equal(value.expectedDefaultValue, value.key.DefaultValue()) + s.Equal(value.expectedDescription, value.key.Description()) + s.Equal(value.expectedFilters, value.key.Filters()) + s.Equal(value.expectedDefaultValue, value.key.DefaultBool()) + } +} + +func (s *constantSuite) TestFloatKey() { + testFloatKeys := map[string]struct { + key FloatKey + KeyName string + Filters []Filter + Description string + DefaultValue float64 + }{ + "TestGetFloat64PropertyKey": { + key: TestGetFloat64PropertyKey, + KeyName: "testGetFloat64PropertyKey", + Description: "", + DefaultValue: 0, + }, + "DomainFailoverRefreshTimerJitterCoefficient": { + key: DomainFailoverRefreshTimerJitterCoefficient, + KeyName: "frontend.domainFailoverRefreshTimerJitterCoefficient", + Description: "DomainFailoverRefreshTimerJitterCoefficient is the jitter for domain failover refresh timer jitter", + DefaultValue: 0.1, + }, + "ReplicationTaskProcessorStartWaitJitterCoefficient": { + key: ReplicationTaskProcessorStartWaitJitterCoefficient, + KeyName: "history.ReplicationTaskProcessorStartWaitJitterCoefficient", + Filters: []Filter{ShardID}, + Description: "ReplicationTaskProcessorStartWaitJitterCoefficient is the jitter for batch start wait timer", + DefaultValue: 0.9, + }, + } + + for _, value := range testFloatKeys { + s.Equal(value.KeyName, value.key.String()) + s.Equal(value.DefaultValue, value.key.DefaultValue()) + s.Equal(value.Description, value.key.Description()) + s.Equal(value.Filters, value.key.Filters()) + s.Equal(value.DefaultValue, value.key.DefaultFloat()) + } +} + +func (s *constantSuite) TestStringKey() { + testStringKeys := map[string]struct { + Key StringKey + KeyName string + Filters []Filter + Description string + DefaultValue string + }{ + "TestGetStringPropertyKey": { + Key: TestGetStringPropertyKey, + KeyName: "testGetStringPropertyKey", + Description: "", + DefaultValue: "", + }, + "HistoryArchivalStatus": { + Key: HistoryArchivalStatus, + KeyName: "system.historyArchivalStatus", + Description: "HistoryArchivalStatus is key for the status of history archival to override the value from static config.", + DefaultValue: "enabled", + }, + "DefaultEventEncoding": { + Key: DefaultEventEncoding, + KeyName: "history.defaultEventEncoding", + Filters: []Filter{DomainName}, + Description: "DefaultEventEncoding is the encoding type for history events", + DefaultValue: string(common.EncodingTypeThriftRW), + }, + } + + for _, value := range testStringKeys { + s.Equal(value.KeyName, value.Key.String()) + s.Equal(value.DefaultValue, value.Key.DefaultValue()) + s.Equal(value.Description, value.Key.Description()) + s.Equal(value.Filters, value.Key.Filters()) + s.Equal(value.DefaultValue, value.Key.DefaultString()) + } +} + +func (s *constantSuite) TestDurationKey() { + testDurationKeys := map[string]struct { + Key DurationKey + KeyName string + Filters []Filter + Description string + DefaultValue time.Duration + }{ + "TestGetDurationPropertyKey": { + Key: TestGetDurationPropertyKey, + KeyName: "testGetDurationPropertyKey", + Description: "", + DefaultValue: 0, + }, + "FrontendFailoverCoolDown": { + Key: FrontendFailoverCoolDown, + KeyName: "frontend.failoverCoolDown", + Filters: []Filter{DomainName}, + Description: "FrontendFailoverCoolDown is duration between two domain failvoers", + DefaultValue: time.Minute, + }, + "MatchingIdleTasklistCheckInterval": { + Key: MatchingIdleTasklistCheckInterval, + KeyName: "matching.idleTasklistCheckInterval", + Filters: []Filter{DomainName, TaskListName, TaskType}, + Description: "MatchingIdleTasklistCheckInterval is the IdleTasklistCheckInterval", + DefaultValue: time.Minute * 5, + }, + } + + for _, value := range testDurationKeys { + s.Equal(value.KeyName, value.Key.String()) + s.Equal(value.DefaultValue, value.Key.DefaultValue()) + s.Equal(value.Description, value.Key.Description()) + s.Equal(value.Filters, value.Key.Filters()) + s.Equal(value.DefaultValue, value.Key.DefaultDuration()) + } +} + +func (s *constantSuite) TestMapKey() { + testMapKeys := map[string]struct { + Key MapKey + KeyName string + Filters []Filter + Description string + DefaultValue map[string]interface{} + }{ + "TestGetMapPropertyKey": { + Key: TestGetMapPropertyKey, + KeyName: "testGetMapPropertyKey", + Description: "", + DefaultValue: nil, + }, + "TaskSchedulerRoundRobinWeights": { + Key: TaskSchedulerRoundRobinWeights, + KeyName: "history.taskSchedulerRoundRobinWeight", + Description: "TaskSchedulerRoundRobinWeights is the priority weight for weighted round robin task scheduler", + DefaultValue: common.ConvertIntMapToDynamicConfigMapProperty(map[int]int{ + common.GetTaskPriority(common.HighPriorityClass, common.DefaultPrioritySubclass): 500, + common.GetTaskPriority(common.DefaultPriorityClass, common.DefaultPrioritySubclass): 20, + common.GetTaskPriority(common.LowPriorityClass, common.DefaultPrioritySubclass): 5, + }), + }, + "QueueProcessorStuckTaskSplitThreshold": { + Key: QueueProcessorStuckTaskSplitThreshold, + KeyName: "history.queueProcessorStuckTaskSplitThreshold", + Description: "QueueProcessorStuckTaskSplitThreshold is the threshold for the number of attempts of a task", + DefaultValue: common.ConvertIntMapToDynamicConfigMapProperty(map[int]int{0: 100, 1: 10000}), + }, + } + + for _, value := range testMapKeys { + s.Equal(value.KeyName, value.Key.String()) + s.Equal(value.DefaultValue, value.Key.DefaultValue()) + s.Equal(value.Description, value.Key.Description()) + s.Equal(value.Filters, value.Key.Filters()) + s.Equal(value.DefaultValue, value.Key.DefaultMap()) + } +} + +func (s *constantSuite) TestListKey() { + testListKeys := map[string]struct { + Key ListKey + KeyName string + Filters []Filter + Description string + DefaultValue []interface{} + }{ + "DefaultIsolationGroupConfigStoreManagerGlobalMapping": { + Key: DefaultIsolationGroupConfigStoreManagerGlobalMapping, + KeyName: "system.defaultIsolationGroupConfigStoreManagerGlobalMapping", + Description: "A configuration store for global isolation groups - used in isolation-group config only, not normal dynamic config." + + "Not intended for use in normal dynamic config", + }, + "HeaderForwardingRules": { + Key: HeaderForwardingRules, + KeyName: "admin.HeaderForwardingRules", + Description: "Only loaded at startup. " + + "A list of rpc.HeaderRule values that define which headers to include or exclude for all requests, applied in order. " + + "Regexes and header names are used as-is, you are strongly encouraged to use `(?i)` to make your regex case-insensitive.", + DefaultValue: []interface{}{ + map[string]interface{}{ + "Add": true, + "Match": "", + }, + }, + }, + } + + for _, value := range testListKeys { + s.Equal(value.KeyName, value.Key.String()) + s.Equal(value.DefaultValue, value.Key.DefaultValue()) + s.Equal(value.Description, value.Key.Description()) + s.Equal(value.Filters, value.Key.Filters()) + s.Equal(value.DefaultValue, value.Key.DefaultList()) + } +} From 64db0a7d9b2e9e27f2dfdc4323862385ac6f60cc Mon Sep 17 00:00:00 2001 From: Tim Li Date: Thu, 22 Feb 2024 09:43:16 -0800 Subject: [PATCH 2/3] lint --- common/dynamicconfig/constants_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/dynamicconfig/constants_test.go b/common/dynamicconfig/constants_test.go index e1a52d0e84c..c66ee422edf 100644 --- a/common/dynamicconfig/constants_test.go +++ b/common/dynamicconfig/constants_test.go @@ -1,10 +1,12 @@ package dynamicconfig import ( - "github.com/stretchr/testify/suite" - "github.com/uber/cadence/common" "testing" "time" + + "github.com/stretchr/testify/suite" + + "github.com/uber/cadence/common" ) type constantSuite struct { From cb366bd732a89cba7040419925668fa3499cf115 Mon Sep 17 00:00:00 2001 From: Tim Li Date: Thu, 22 Feb 2024 09:55:51 -0800 Subject: [PATCH 3/3] add copyright --- common/dynamicconfig/constants_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/dynamicconfig/constants_test.go b/common/dynamicconfig/constants_test.go index c66ee422edf..a4cf469d840 100644 --- a/common/dynamicconfig/constants_test.go +++ b/common/dynamicconfig/constants_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 dynamicconfig import (