fix IsOptsWithFromKey
fix IsOptsWithFromKey fix IsOptsWithFromKey fix IsOptsWithFromKey fix IsOptsWithFromKey fix IsOptsWithFromKey
This commit is contained in:
@ -77,6 +77,9 @@ type Op struct {
|
|||||||
cmps []Cmp
|
cmps []Cmp
|
||||||
thenOps []Op
|
thenOps []Op
|
||||||
elseOps []Op
|
elseOps []Op
|
||||||
|
|
||||||
|
isOptsWithFromKey bool
|
||||||
|
isOptsWithPrefix bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// accessors / mutators
|
// accessors / mutators
|
||||||
@ -216,6 +219,10 @@ func (op Op) isWrite() bool {
|
|||||||
return op.t != tRange
|
return op.t != tRange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewOp() *Op {
|
||||||
|
return &Op{key: []byte("")}
|
||||||
|
}
|
||||||
|
|
||||||
// OpGet returns "get" operation based on given key and operation options.
|
// OpGet returns "get" operation based on given key and operation options.
|
||||||
func OpGet(key string, opts ...OpOption) Op {
|
func OpGet(key string, opts ...OpOption) Op {
|
||||||
// WithPrefix and WithFromKey are not supported together
|
// WithPrefix and WithFromKey are not supported together
|
||||||
@ -387,6 +394,7 @@ func WithPrefix() OpOption {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
op.end = getPrefix(op.key)
|
op.end = getPrefix(op.key)
|
||||||
|
op.isOptsWithPrefix = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +414,7 @@ func WithFromKey() OpOption {
|
|||||||
op.key = []byte{0}
|
op.key = []byte{0}
|
||||||
}
|
}
|
||||||
op.end = []byte("\x00")
|
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.
|
// 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.
|
// 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
|
||||||
|
}
|
||||||
|
@ -16,9 +16,6 @@ package clientv3
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,18 +29,3 @@ func jitterUp(duration time.Duration, jitter float64) time.Duration {
|
|||||||
multiplier := jitter * (rand.Float64()*2 - 1)
|
multiplier := jitter * (rand.Float64()*2 - 1)
|
||||||
return time.Duration(float64(duration) * (1 + multiplier))
|
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
|
|
||||||
}
|
|
||||||
|
@ -15,14 +15,14 @@
|
|||||||
package integration_test
|
package integration_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.etcd.io/etcd/tests/v3/integration"
|
"go.etcd.io/etcd/tests/v3/integration"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBeforeTestWithoutLeakDetection(t *testing.T) {
|
func TestBeforeTestWithoutLeakDetection(t *testing.T) {
|
||||||
integration.BeforeTest(t, integration.WithoutGoLeakDetection(), integration.WithoutSkipInShort())
|
integration.BeforeTest(t, integration.WithoutGoLeakDetection(), integration.WithoutSkipInShort())
|
||||||
// Intentional leak that should get ignored
|
// Intentional leak that should get ignored
|
||||||
go time.Sleep(2 * time.Second)
|
go func() {
|
||||||
|
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user