-
Notifications
You must be signed in to change notification settings - Fork 805
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d7d68d
Add unit tests for methods in constants.go
timl3136 ff12fb0
Merge branch 'uber:master' into test-coverage
timl3136 64db0a7
lint
timl3136 cb366bd
add copyright
timl3136 9c7b767
Merge branch 'master' into test-coverage
timl3136 4dee723
Merge branch 'master' into test-coverage
timl3136 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
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()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.