Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage for constants.go #5685

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
319 changes: 319 additions & 0 deletions common/dynamicconfig/constants_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
// 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 (
"testing"
"time"

"github.com/stretchr/testify/suite"

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

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": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you planning to cover the rest of the keys in follow up PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really as variable definition is not included in code coverage and including all keys will be essentially parsed structs in constants.go.

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())
}
}