-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathtest_utils.go
59 lines (54 loc) · 2.03 KB
/
test_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package kv
import (
"strings"
"github.com/cockroachdb/cockroach/pkg/kv/kvbase"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
)
// OnlyFollowerReads looks through all the RPCs and asserts that every single
// one resulted in a follower read. Returns false if no RPCs are found.
func OnlyFollowerReads(rec tracing.Recording) bool {
foundFollowerRead := false
for _, sp := range rec {
if sp.Operation == "/cockroach.roachpb.Internal/Batch" &&
sp.Tags["span.kind"] == "server" {
if tracing.LogsContainMsg(sp, kvbase.FollowerReadServingMsg) {
foundFollowerRead = true
} else {
return false
}
}
}
return foundFollowerRead
}
// IsExpectedRelocateError maintains an allowlist of errors related to
// atomic-replication-changes we want to ignore / retry on for tests.
// See:
// https://github.com/cockroachdb/cockroach/issues/33732
// https://github.com/cockroachdb/cockroach/issues/33708
// https://github.cm/cockroachdb/cockroach/issues/34012
// https://github.com/cockroachdb/cockroach/issues/33683#issuecomment-454889149
// for more failure modes not caught here.
func IsExpectedRelocateError(err error) bool {
allowlist := []string{
"descriptor changed",
"unable to remove replica .* which is not present",
"unable to add replica .* which is already present",
"received invalid ChangeReplicasTrigger .* to remove self",
"failed to apply snapshot: raft group deleted",
"snapshot failed:",
"breaker open",
"unable to select removal target", // https://github.com/cockroachdb/cockroach/issues/49513
}
pattern := "(" + strings.Join(allowlist, "|") + ")"
return testutils.IsError(err, pattern)
}