diff --git a/client/v3/op.go b/client/v3/op.go index bd0f1f2f2..e8c0c1e08 100644 --- a/client/v3/op.go +++ b/client/v3/op.go @@ -77,6 +77,9 @@ type Op struct { cmps []Cmp thenOps []Op elseOps []Op + + isOptsWithFromKey bool + isOptsWithPrefix bool } // accessors / mutators @@ -216,6 +219,10 @@ func (op Op) isWrite() bool { return op.t != tRange } +func NewOp() *Op { + return &Op{key: []byte("")} +} + // OpGet returns "get" operation based on given key and operation options. func OpGet(key string, opts ...OpOption) Op { // WithPrefix and WithFromKey are not supported together @@ -387,6 +394,7 @@ func WithPrefix() OpOption { return } op.end = getPrefix(op.key) + op.isOptsWithPrefix = true } } @@ -406,6 +414,7 @@ func WithFromKey() OpOption { op.key = []byte{0} } op.end = []byte("\x00") + op.isOptsWithFromKey = true } } @@ -554,7 +563,21 @@ func toLeaseTimeToLiveRequest(id LeaseID, opts ...LeaseOption) *pb.LeaseTimeToLi } // IsOptsWithPrefix returns true if WithPrefix option is called in the given opts. -func IsOptsWithPrefix(opts []OpOption) bool { return isOpFuncCalled("WithPrefix", opts) } +func IsOptsWithPrefix(opts []OpOption) bool { + ret := NewOp() + for _, opt := range opts { + opt(ret) + } + + return ret.isOptsWithPrefix +} // IsOptsWithFromKey returns true if WithFromKey option is called in the given opts. -func IsOptsWithFromKey(opts []OpOption) bool { return isOpFuncCalled("WithFromKey", opts) } +func IsOptsWithFromKey(opts []OpOption) bool { + ret := NewOp() + for _, opt := range opts { + opt(ret) + } + + return ret.isOptsWithFromKey +} diff --git a/client/v3/utils.go b/client/v3/utils.go index b998c41b9..850275877 100644 --- a/client/v3/utils.go +++ b/client/v3/utils.go @@ -16,9 +16,6 @@ package clientv3 import ( "math/rand" - "reflect" - "runtime" - "strings" "time" ) @@ -32,18 +29,3 @@ func jitterUp(duration time.Duration, jitter float64) time.Duration { multiplier := jitter * (rand.Float64()*2 - 1) return time.Duration(float64(duration) * (1 + multiplier)) } - -// Check if the provided function is being called in the op options. -func isOpFuncCalled(op string, opts []OpOption) bool { - for _, opt := range opts { - v := reflect.ValueOf(opt) - if v.Kind() == reflect.Func { - if opFunc := runtime.FuncForPC(v.Pointer()); opFunc != nil { - if strings.Contains(opFunc.Name(), op) { - return true - } - } - } - } - return false -} diff --git a/tests/integration/testing_test.go b/tests/integration/testing_test.go index f9afb8ded..a225063b1 100644 --- a/tests/integration/testing_test.go +++ b/tests/integration/testing_test.go @@ -15,14 +15,14 @@ package integration_test import ( - "testing" - "time" - "go.etcd.io/etcd/tests/v3/integration" + "testing" ) func TestBeforeTestWithoutLeakDetection(t *testing.T) { integration.BeforeTest(t, integration.WithoutGoLeakDetection(), integration.WithoutSkipInShort()) // Intentional leak that should get ignored - go time.Sleep(2 * time.Second) + go func() { + + }() }