|
|
@ -16,11 +16,11 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/alicebob/miniredis"
|
|
|
|
"github.com/alicebob/miniredis"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/tal-tech/go-zero/core/lang"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
|
|
"github.com/tal-tech/go-zero/core/stat"
|
|
|
|
"github.com/tal-tech/go-zero/core/stat"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/cache"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/cache"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/redis"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/redis"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/redistest"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/sqlx"
|
|
|
|
"github.com/tal-tech/go-zero/core/stores/sqlx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -31,16 +31,15 @@ func init() {
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConn_GetCache(t *testing.T) {
|
|
|
|
func TestCachedConn_GetCache(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
var value string
|
|
|
|
var value string
|
|
|
|
err = c.GetCache("any", &value)
|
|
|
|
err = c.GetCache("any", &value)
|
|
|
|
assert.Equal(t, ErrNotFound, err)
|
|
|
|
assert.Equal(t, ErrNotFound, err)
|
|
|
|
s.Set("any", `"value"`)
|
|
|
|
r.Set("any", `"value"`)
|
|
|
|
err = c.GetCache("any", &value)
|
|
|
|
err = c.GetCache("any", &value)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "value", value)
|
|
|
|
assert.Equal(t, "value", value)
|
|
|
@ -48,11 +47,10 @@ func TestCachedConn_GetCache(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestStat(t *testing.T) {
|
|
|
|
func TestStat(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
@ -72,15 +70,14 @@ func TestStat(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConn_QueryRowIndex_NoCache(t *testing.T) {
|
|
|
|
func TestCachedConn_QueryRowIndex_NoCache(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewConn(dummySqlConn{}, cache.CacheConf{
|
|
|
|
c := NewConn(dummySqlConn{}, cache.CacheConf{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RedisConf: redis.RedisConf{
|
|
|
|
RedisConf: redis.RedisConf{
|
|
|
|
Host: s.Addr(),
|
|
|
|
Host: r.Addr,
|
|
|
|
Type: redis.NodeType,
|
|
|
|
Type: redis.NodeType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Weight: 100,
|
|
|
|
Weight: 100,
|
|
|
@ -122,11 +119,10 @@ func TestCachedConn_QueryRowIndex_NoCache(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConn_QueryRowIndex_HasCache(t *testing.T) {
|
|
|
|
func TestCachedConn_QueryRowIndex_HasCache(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
|
|
|
|
|
|
|
@ -210,16 +206,13 @@ func TestCachedConn_QueryRowIndex_HasCache_IntPrimary(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s.FlushAll()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
|
|
|
|
|
|
|
@ -256,11 +249,10 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) {
|
|
|
|
for k, v := range caches {
|
|
|
|
for k, v := range caches {
|
|
|
|
t.Run(k+"/"+v, func(t *testing.T) {
|
|
|
|
t.Run(k+"/"+v, func(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
cache.WithNotFoundExpiry(time.Second))
|
|
|
|
|
|
|
|
|
|
|
@ -312,11 +304,10 @@ func TestStatCacheFails(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestStatDbFails(t *testing.T) {
|
|
|
|
func TestStatDbFails(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
@ -334,11 +325,10 @@ func TestStatDbFails(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestStatFromMemory(t *testing.T) {
|
|
|
|
func TestStatFromMemory(t *testing.T) {
|
|
|
|
resetStats()
|
|
|
|
resetStats()
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10))
|
|
|
|
|
|
|
|
|
|
|
|
var all sync.WaitGroup
|
|
|
|
var all sync.WaitGroup
|
|
|
@ -393,7 +383,7 @@ func TestStatFromMemory(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnQueryRow(t *testing.T) {
|
|
|
|
func TestCachedConnQueryRow(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
@ -404,7 +394,6 @@ func TestCachedConnQueryRow(t *testing.T) {
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
var user string
|
|
|
|
var user string
|
|
|
|
var ran bool
|
|
|
|
var ran bool
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
|
ran = true
|
|
|
|
ran = true
|
|
|
@ -412,7 +401,7 @@ func TestCachedConnQueryRow(t *testing.T) {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
actualValue, err := s.Get(key)
|
|
|
|
actualValue, err := r.Get(key)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
var actual string
|
|
|
|
var actual string
|
|
|
|
assert.Nil(t, json.Unmarshal([]byte(actualValue), &actual))
|
|
|
|
assert.Nil(t, json.Unmarshal([]byte(actualValue), &actual))
|
|
|
@ -422,7 +411,7 @@ func TestCachedConnQueryRow(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnQueryRowFromCache(t *testing.T) {
|
|
|
|
func TestCachedConnQueryRowFromCache(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
@ -433,7 +422,6 @@ func TestCachedConnQueryRowFromCache(t *testing.T) {
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
var user string
|
|
|
|
var user string
|
|
|
|
var ran bool
|
|
|
|
var ran bool
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
assert.Nil(t, c.SetCache(key, value))
|
|
|
|
assert.Nil(t, c.SetCache(key, value))
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
@ -442,7 +430,7 @@ func TestCachedConnQueryRowFromCache(t *testing.T) {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
actualValue, err := s.Get(key)
|
|
|
|
actualValue, err := r.Get(key)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
var actual string
|
|
|
|
var actual string
|
|
|
|
assert.Nil(t, json.Unmarshal([]byte(actualValue), &actual))
|
|
|
|
assert.Nil(t, json.Unmarshal([]byte(actualValue), &actual))
|
|
|
@ -452,7 +440,7 @@ func TestCachedConnQueryRowFromCache(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestQueryRowNotFound(t *testing.T) {
|
|
|
|
func TestQueryRowNotFound(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
@ -460,7 +448,6 @@ func TestQueryRowNotFound(t *testing.T) {
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
var user string
|
|
|
|
var user string
|
|
|
|
var ran int
|
|
|
|
var ran int
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
|
err = c.QueryRow(&user, key, func(conn sqlx.SqlConn, v interface{}) error {
|
|
|
@ -473,12 +460,11 @@ func TestQueryRowNotFound(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnExec(t *testing.T) {
|
|
|
|
func TestCachedConnExec(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
_, err = c.ExecNoCache("delete from user_table where id='kevin'")
|
|
|
|
_, err = c.ExecNoCache("delete from user_table where id='kevin'")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
@ -486,24 +472,23 @@ func TestCachedConnExec(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnExecDropCache(t *testing.T) {
|
|
|
|
func TestCachedConnExecDropCache(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, err := miniredis.Run()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer r.Close()
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
key = "user"
|
|
|
|
key = "user"
|
|
|
|
value = "any"
|
|
|
|
value = "any"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
c := NewNodeConn(&conn, redis.NewRedis(r.Addr(), redis.NodeType), cache.WithExpiry(time.Second*30))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*30))
|
|
|
|
|
|
|
|
assert.Nil(t, c.SetCache(key, value))
|
|
|
|
assert.Nil(t, c.SetCache(key, value))
|
|
|
|
_, err = c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) {
|
|
|
|
_, err = c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) {
|
|
|
|
return conn.Exec("delete from user_table where id='kevin'")
|
|
|
|
return conn.Exec("delete from user_table where id='kevin'")
|
|
|
|
}, key)
|
|
|
|
}, key)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.True(t, conn.execValue)
|
|
|
|
assert.True(t, conn.execValue)
|
|
|
|
_, err = s.Get(key)
|
|
|
|
_, err = r.Get(key)
|
|
|
|
assert.Exactly(t, miniredis.ErrKeyNotFound, err)
|
|
|
|
assert.Exactly(t, miniredis.ErrKeyNotFound, err)
|
|
|
|
_, err = c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) {
|
|
|
|
_, err = c.Exec(func(conn sqlx.SqlConn) (result sql.Result, e error) {
|
|
|
|
return nil, errors.New("foo")
|
|
|
|
return nil, errors.New("foo")
|
|
|
@ -524,12 +509,11 @@ func TestCachedConnExecDropCacheFailed(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnQueryRows(t *testing.T) {
|
|
|
|
func TestCachedConnQueryRows(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
var users []string
|
|
|
|
var users []string
|
|
|
|
err = c.QueryRowsNoCache(&users, "select user from user_table where id='kevin'")
|
|
|
|
err = c.QueryRowsNoCache(&users, "select user from user_table where id='kevin'")
|
|
|
@ -538,12 +522,11 @@ func TestCachedConnQueryRows(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestCachedConnTransact(t *testing.T) {
|
|
|
|
func TestCachedConnTransact(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
|
var conn trackedConn
|
|
|
|
var conn trackedConn
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
c := NewNodeConn(&conn, r, cache.WithExpiry(time.Second*10))
|
|
|
|
err = c.Transact(func(session sqlx.Session) error {
|
|
|
|
err = c.Transact(func(session sqlx.Session) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -553,7 +536,7 @@ func TestCachedConnTransact(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestQueryRowNoCache(t *testing.T) {
|
|
|
|
func TestQueryRowNoCache(t *testing.T) {
|
|
|
|
s, clean, err := createMiniRedis()
|
|
|
|
r, clean, err := redistest.CreateRedis()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer clean()
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
|
|
|
@ -563,7 +546,6 @@ func TestQueryRowNoCache(t *testing.T) {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
var user string
|
|
|
|
var user string
|
|
|
|
var ran bool
|
|
|
|
var ran bool
|
|
|
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
|
|
|
|
|
|
|
conn := dummySqlConn{queryRow: func(v interface{}, q string, args ...interface{}) error {
|
|
|
|
conn := dummySqlConn{queryRow: func(v interface{}, q string, args ...interface{}) error {
|
|
|
|
user = value
|
|
|
|
user = value
|
|
|
|
ran = true
|
|
|
|
ran = true
|
|
|
@ -639,22 +621,3 @@ func (c *trackedConn) Transact(fn func(session sqlx.Session) error) error {
|
|
|
|
c.transactValue = true
|
|
|
|
c.transactValue = true
|
|
|
|
return c.dummySqlConn.Transact(fn)
|
|
|
|
return c.dummySqlConn.Transact(fn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createMiniRedis() (r *miniredis.Miniredis, clean func(), err error) {
|
|
|
|
|
|
|
|
r, err = miniredis.Run()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return r, func() {
|
|
|
|
|
|
|
|
ch := make(chan lang.PlaceholderType)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
r.Close()
|
|
|
|
|
|
|
|
close(ch)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
|
|
|
case <-ch:
|
|
|
|
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|