state: speed up TestStateStore_ServicesByNodeMeta

Make watchLimit a var so that we can patch it in tests and reduce the time spent creating state.
This commit is contained in:
Daniel Nephin 2020-07-22 16:38:39 -04:00
parent 0402dd7ac5
commit 9ed61fd160
2 changed files with 20 additions and 5 deletions

View File

@ -1709,8 +1709,10 @@ func TestStateStore_ServicesByNodeMeta(t *testing.T) {
})
t.Run("Uses watchLimit to limit the number of watches", func(t *testing.T) {
patchWatchLimit(t, 10)
var idx uint64 = 6
for i := 0; i < 2*watchLimit; i++ {
for i := 0; i < watchLimit+2; i++ {
node := fmt.Sprintf("many%d", i)
testRegisterNodeWithMeta(t, s, idx, node, map[string]string{"common": "1"})
idx++
@ -1731,6 +1733,16 @@ func TestStateStore_ServicesByNodeMeta(t *testing.T) {
})
}
// patchWatchLimit package variable. Not safe for concurrent use. Do not use
// with t.Parallel.
func patchWatchLimit(t *testing.T, limit int) {
oldLimit := watchLimit
watchLimit = limit
t.Cleanup(func() {
watchLimit = oldLimit
})
}
func TestStateStore_ServiceNodes(t *testing.T) {
s := testStateStore(t)
@ -1847,7 +1859,8 @@ func TestStateStore_ServiceNodes(t *testing.T) {
// Overwhelm the node tracking.
idx = 19
for i := 0; i < 2*watchLimit; i++ {
patchWatchLimit(t, 10)
for i := 0; i < watchLimit+2; i++ {
node := fmt.Sprintf("many%d", i)
if err := s.EnsureNode(idx, &structs.Node{Node: node, Address: "127.0.0.1"}); err != nil {
t.Fatalf("err: %v", err)
@ -2616,7 +2629,8 @@ func TestStateStore_ServiceChecksByNodeMeta(t *testing.T) {
}
// Overwhelm the node tracking.
for i := 0; i < 2*watchLimit; i++ {
patchWatchLimit(t, 10)
for i := 0; i < watchLimit+2; i++ {
node := fmt.Sprintf("many%d", idx)
testRegisterNodeWithMeta(t, s, idx, node, map[string]string{"common": "1"})
idx++
@ -2796,7 +2810,8 @@ func TestStateStore_ChecksInStateByNodeMeta(t *testing.T) {
}
// Overwhelm the node tracking.
for i := 0; i < 2*watchLimit; i++ {
patchWatchLimit(t, 10)
for i := 0; i < watchLimit+2; i++ {
node := fmt.Sprintf("many%d", idx)
testRegisterNodeWithMeta(t, s, idx, node, map[string]string{"common": "1"})
idx++

View File

@ -82,7 +82,7 @@ var (
ErrMissingIntentionID = errors.New("Missing Intention ID")
)
const (
var (
// watchLimit is used as a soft limit to cap how many watches we allow
// for a given blocking query. If this is exceeded, then we will use a
// higher-level watch that's less fine-grained. Choosing the perfect