mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
parent
189721da16
commit
bf3ce16823
2
core/stores/cache/cache_test.go
vendored
2
core/stores/cache/cache_test.go
vendored
@ -23,6 +23,7 @@ type mockedNode struct {
|
||||
|
||||
func (mc *mockedNode) Del(keys ...string) error {
|
||||
var be errorx.BatchError
|
||||
|
||||
for _, key := range keys {
|
||||
if _, ok := mc.vals[key]; !ok {
|
||||
be.Add(mc.errNotFound)
|
||||
@ -30,6 +31,7 @@ func (mc *mockedNode) Del(keys ...string) error {
|
||||
delete(mc.vals, key)
|
||||
}
|
||||
}
|
||||
|
||||
return be.Err()
|
||||
}
|
||||
|
||||
|
15
core/stores/cache/cachenode.go
vendored
15
core/stores/cache/cachenode.go
vendored
@ -65,9 +65,18 @@ func (c cacheNode) Del(keys ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := c.rds.Del(keys...); err != nil {
|
||||
logx.Errorf("failed to clear cache with keys: %q, error: %v", formatKeys(keys), err)
|
||||
c.asyncRetryDelCache(keys...)
|
||||
if len(keys) > 1 && c.rds.Type == redis.ClusterType {
|
||||
for _, key := range keys {
|
||||
if _, err := c.rds.Del(key); err != nil {
|
||||
logx.Errorf("failed to clear cache with key: %q, error: %v", key, err)
|
||||
c.asyncRetryDelCache(key)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _, err := c.rds.Del(keys...); err != nil {
|
||||
logx.Errorf("failed to clear cache with keys: %q, error: %v", formatKeys(keys), err)
|
||||
c.asyncRetryDelCache(keys...)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
18
core/stores/cache/cachenode_test.go
vendored
18
core/stores/cache/cachenode_test.go
vendored
@ -29,6 +29,7 @@ func init() {
|
||||
func TestCacheNode_DelCache(t *testing.T) {
|
||||
store, clean, err := redistest.CreateRedis()
|
||||
assert.Nil(t, err)
|
||||
store.Type = redis.ClusterType
|
||||
defer clean()
|
||||
|
||||
cn := cacheNode{
|
||||
@ -49,6 +50,23 @@ func TestCacheNode_DelCache(t *testing.T) {
|
||||
assert.Nil(t, cn.Del("first", "second"))
|
||||
}
|
||||
|
||||
func TestCacheNode_DelCacheWithErrors(t *testing.T) {
|
||||
store, clean, err := redistest.CreateRedis()
|
||||
assert.Nil(t, err)
|
||||
store.Type = redis.ClusterType
|
||||
clean()
|
||||
|
||||
cn := cacheNode{
|
||||
rds: store,
|
||||
r: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
lock: new(sync.Mutex),
|
||||
unstableExpiry: mathx.NewUnstable(expiryDeviation),
|
||||
stat: NewStat("any"),
|
||||
errNotFound: errTestNotFound,
|
||||
}
|
||||
assert.Nil(t, cn.Del("third", "fourth"))
|
||||
}
|
||||
|
||||
func TestCacheNode_InvalidCache(t *testing.T) {
|
||||
s, err := miniredis.Run()
|
||||
assert.Nil(t, err)
|
||||
|
2
tools/goctl/util/env/env_test.go
vendored
2
tools/goctl/util/env/env_test.go
vendored
@ -70,7 +70,7 @@ func TestCanExec(t *testing.T) {
|
||||
assert.Equal(t, canExec, CanExec())
|
||||
}
|
||||
|
||||
func execCommand(cmd string, arg ...string) (stdout string, stderr string, err error) {
|
||||
func execCommand(cmd string, arg ...string) (stdout, stderr string, err error) {
|
||||
output := bytes.NewBuffer(nil)
|
||||
errOutput := bytes.NewBuffer(nil)
|
||||
c := exec.Command(cmd, arg...)
|
||||
|
Loading…
Reference in New Issue
Block a user